.( loading editor ) update .( done ) .( ETh - for text editor help ) var handletxt var handlebuf Dstralloc const editfile var shiftx var shifty var curlocx var curlocy Dstr \listF\TXT_ET" tmphelpfile : disppage ( -- ) handletxt @ dynp shifty @ 50 * + 0 1 at! 1270 type ; : fclose ( close opened file ) handletxt @ dup if dynde handletxt off else drop then ; : ETnewpage fclose 27100 dynal dup handletxt ! dynp FF swap 27100 cfill ; var tmp1 : fopen ( strhand -- ) fclose dup editfile Dstr2Dstr fsDloadnew dup push dynp ( addrinp R: handinp ) 27100 dynal dup handletxt ! dynp ( addrinp addrout R: handinp ) FF over 27100 cfill tmp1 off i dyns do ( addrinp addrout ) over c@ ( addrinp addrout c ) dup FE = if drop 50 tmp1 @ - + tmp1 off else dup FD = if drop tmp1 @ tab ( addrinp addrout numspaces ) tmp1 @ over + tmp1 ! + 0 else over c! 1+ 0 tmp1 @ 1+ tmp1 ! then drop then swap 1+ swap loop 2drop pop dynde ; rh tmp1 : dispchar ( x y -- ) 2dup swap shiftx @ - swap shifty @ - 1+ at! 50 * + handletxt @ dynp + c@ emit ; : dispcur curlocx @ curlocy @ dispchar ; : displine ( line ) 0 over shifty @ - 1+ at! 50 * handletxt @ dynp + shiftx @ + 50 type ; : dispstatbar colneg 0 0 at! 50 do space loop 0 0 at! ." col:" curlocx @ . 7 0 at! ." line:" curlocy @ . 11 0 at! ." ascii:" curlocy @ 50 * curlocx @ + handletxt @ dynp + c@ . 1B 0 at! ." file:" editfile Dstr. 49 0 at! ." F1-help" colnorm ; : charins ( char x y ) 50 * handletxt @ dynp + ( char x addr ) over push + dup dup 1+ 4F pop - cmove ( char addr ) c! ; : charcut ( x y -- char ) over push 50 * handletxt @ dynp + + dup c@ swap ( char addr ) dup dup 1+ swap ( char addr addr+1 addr ) 4F pop - dup push cmove ( char addr ) pop + FF swap c! ; : lineins ( line ) 50 * dup push handletxt @ dynp + ( addr ) dup dup 50 + handletxt @ dyns 50 - pop - cmove ( addr ) FF swap 50 cfill ; : linecut ( line ) 50 * dup push handletxt @ dynp + ( addr ) dup 50 + swap handletxt @ dyns 50 - pop - cmove ; : screenaim 0 curlocy @ 1E - 794 bound shifty ! disppage ; var tmp1 : length ( line -- length ) 50 * 4F + handletxt @ dynp + ( addr ) 51 do i tmp1 ! dup c@ FF - if pop drop 0 push then 1- loop drop tmp1 @ ; rh tmp1 var tmp2 var tmp3 : fsavechar ( char ) tmp2 @ swap over c! 1+ tmp2 ! ; : fsave ( -- ) 27200 dynal dup dynp tmp2 ! 0 7CF do i length if drop pop 1+ 0 push then loop 0 swap for ( desthand ) tmp3 off i 50 * handletxt @ dynp + 0 i length for ( desthand srcaddr ) dup c@ i tab 8 = if tmp3 @ if FD fsavechar tmp3 off then then dup FF = if drop tmp3 @ 1+ tmp3 ! else tmp3 @ do FF fsavechar loop tmp3 off fsavechar then 1+ loop drop FE fsavechar loop tmp2 @ over dynp - over dynresize dup editfile fsDsave dynde ; rh tmp2 rh tmp3 str TXT_default" tmpdefault : ET handletxt @ if disppage until colneg dispcur dispstatbar KBD_FW@ colnorm dispcur dup 415 = if ( DEL ) curlocx @ curlocy @ charcut drop curlocy @ displine then dup FC = if ( BACKSPACE ) curlocx @ if curlocx @ 1- curlocy @ charcut drop curlocy @ displine drop 413 else curlocy @ if curlocy @ 1- dup length dup curlocx ! ( y-1 strlen ) swap 50 * handletxt @ dynp + ( strlen y1addr ) 2dup + swap 50 + ( strlen dest src ) swap rot 50 swap - cmove curlocy @ linecut drop 410 disppage then then then dup FD = if ( TAB ) curlocx @ tab dup do FF curlocx @ curlocy @ charins loop curlocx @ + curlocx ! curlocy @ displine then dup FE = if ( ENTER ) curlocy @ 7CF < if curlocy @ 1+ lineins curlocx @ 0 50 curlocx @ - do over curlocy @ charcut over curlocy @ 1+ charins 1+ loop 2drop curlocx off drop 412 disppage then then dup 418 = if curlocy @ 3A - curlocy ! then ( PG-UP ) dup 419 = if curlocy @ 3A + curlocy ! then ( PG-DOWN ) dup 416 = if curlocx off then ( HOME ) dup 417 = if curlocy @ length curlocx ! then ( END ) dup 401 = if tmphelpfile fsdisp disppage then ( F1 ) dup 402 = if fsave then ( F2 ) dup 403 = if fclose drop 1B then ( F3 ) dup 400 = if done 0 0 at! screen cls drop -1 then ( ESC ) 0 over F0 bound? if -1 else 0 then ( NORMAL KEY ) over FF = if drop -1 then if curlocx @ curlocy @ charins curlocy @ displine 411 then dup 411 = if curlocx @ 1+ curlocx ! then ( RIGHT ) dup 413 = if curlocx @ 1- curlocx ! then ( LEFT ) dup 412 = if curlocy @ 1+ curlocy ! then ( DOWN ) dup 410 = if curlocy @ 1- curlocy ! then ( UP ) drop 0 curlocx @ 4F bound curlocx ! 0 curlocy @ 7CF bound curlocy ! curlocy @ shifty @ - 3B > if screenaim then curlocy @ shifty @ - 3B - 0 = if 0 0 8 screen scrollf shifty @ 1+ shifty ! curlocy @ displine then curlocy @ shifty @ - -1 < if screenaim then curlocy @ shifty @ - 1+ 0 = if 0 0 -8 screen scrollf shifty @ 1- shifty ! curlocy @ displine then loop else tmpdefault editfile str2Dstr ETnewpage ET then ; : ETl fopen curlocx off curlocy off shiftx off shifty off ET ; : ETs editfile Dstr2Dstr fsave ." saved " ; : ETh tmphelpfile fs. ; rh handletxt rh handlebuf rh editfile rh shiftx rh shifty rh curlocx rh curlocy rh tmphelpfile rh disppage rh fclose rh fopen rh dispchar rh dispcur rh displine rh dispstatbar rh charins rh charcut rh lineins rh linecut rh screenaim rh length rh fsavechar rh fsave rh ETnewpage rh tmpdefault