| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600 |
- MOV CX,#$0004 ;4 times
- erpblnk2 CALL ekbdstat ;get KBD stat
- JNZ erpbw2 ;:key pressed
- MOV BX,#$0064 ;wait 100 ms
- PUSH CX ;save cnt
- CALL delaybx ;Delay
- POP CX ;restore cnt
- LOOP erpblnk2 ;:another
- JMP erpblnk ;'blink again
- erpbw2 CALL keyget ;get char
- CALL etstint ;test interrupt
- CALL upcase ;UpCase
- CMP AL,#$59 ;Y ?
- JZ erpdoit ;:yes, do it
- CMP AL,#$19 ;^Y ?
- JNZ erpbk
- erpdoit MOV.B txchg,#$FF ;set flags: text changed
- MOV.B txcomp,#$00 ;code invalid
- MOV.B CL,srrepl1 ;length of replacement
- MOV CH,#$00
- POP BX ;restore pos
- PUSH BX
- PUSH CX ;save
- MOV AL,srword1 ;length of word found
- SUB.B AL,CL ;- length of replacement
- MOV.B CL,AL ;-> CL
- LAHF ;save flags
- PUSH AX
- JNB erp2 ;do sign extension
- DEC.B CH
- erp2 TEST.B sropt,#$10 ;backwards ?
- JNZ erpbw ;:yes
- MOV BX,srpos ;beg of that word
- erpbw POP AX ;flag
- SAHF
- PUSH BX
- JZ erpsame ;: no difference
- CALL echgsize ;change len
- erpsame POP DX ;restore
- POP CX
- MOV.B AL,CH ;length = 0 ?
- OR.B AL,CL
- JZ erpnil
- MOV BX,#srrepl2 ;move in replacement word
- CALL movebk
- erpnil CALL ekbdstat ;get KBD stat
- JZ erpok ;:nothing
- CALL eredall ;redisplay all
- JMP.b erpchg ;'
- erpok PUSH DX ;save pos
- CALL erstlin ;restore line
- CALL eredall ;flag: redisplay
- POP DX ;restore pos
- erpchg TEST.B sropt,#$10 ;backwards ?
- JNZ erpbk ;:yes
- POP BX ;remove
- XCHG DX,BX ;set to end of word
- RET ;'
- erpbk POP BX ;restore beg of word
- erpret RET ;"
- ekw CMP.B bkhide,#$FF ;^KW:Write block to disk
- JZ erpret ;block hidden: ret
- CALL eflush ;rewrite line
- CALL erstlin ;restore line
- MOV AX,bkbeg ;block begin > block end ?
- CMP AX,bkend
- JNB erpret ;yes: ret
- CALL etstblk ;test block
- CALL erstlin ;restore line
- ekwlp CALL eclrstat ;clr status line
- CALL ewrits ;write string
- B "Write block to file",$00
- CALL ekwfile ;get filename
- JZ erpret ;nothing entered: ret
- CALL kpasext ;default extension .PAS
- MOV AX,#$3D00 ;open file
- MOV DX,#scrpn ;name ptr
- PUSH DS ;DS -> ES
- POP ES
- CALL dos
- MOV BX,AX ;file handle
- JB ekwnew
- MOV AH,#$3E ;close file
- CALL dos
- CALL eclrs2 ;clr status line
- CALL ewrits
- B "Overwrite old ",$00
- MOV SI,#scrpn ;write filename
- CALL printpn
- CALL yorn ;Y or N ?
- JZ ekwlp ;no: get new filename
- ekwnew MOV AH,#$3C ;create file
- MOV DX,#scrpn ;name ptr
- XOR CX,CX ;no attribute
- PUSH DS ;DS -> ES
- POP ES
- CALL dos
- JNB ekwopen ;:ok
- CALL eclrs2 ;clr status line
- CALL ewriterr ;write message
- B "Unable to create ",$00
- MOV SI,#scrpn ;write filename
- CALL printpn
- CALL waitesc ;wait for ESC
- JMP ekwlp ;'get new filename
- ekwopen PUSH AX ;save file handle
- CALL eclrs2 ;clr status line
- POP BX ;restore
- MOV DX,bkbeg ;block begin
- MOV SI,bkend ;block end
- MOV.B AL,[SI] ;get char at block end
- PUSH AX ;save it
- PUSH SI ;save its addr
- MOV.B [SI],#$1A ;store a ^Z there
- MOV CX,SI ;count = block end - block beg
- SUB CX,DX
- CMP BX,#$04 ;write to device ?
- JBE ekwdev ;:yes
- INC CX ;file: write ^Z, too
- ekwdev MOV AH,#$40 ;write byte block
- CALL dos
- JB ekwfull ;:error
- SUB CX,AX ;length = expected ?
- JZ ekwdone ;:yes
- DEC CX ;1 byte difference ?
- JNZ ekwfull ;no: error
- ekwdone CALL ekwclose ;close file
- JNB ekwok ;:ok
- CALL ewriterr ;write message
- B "Error closing file",$00
- CALL waitesc ;wait for ESC
- ekwok POP SI ;restore char at block end
- POP AX
- MOV.B [SI],AL
- RET ;'
- ekwfull CALL ekwclose ;close file
- MOV AH,#$41 ;delete it
- MOV DX,#scrpn ;name ptr
- CALL dos
- CALL ewriterr ;write message
- B "Disk full",$00
- CALL waitesc ;wait for ESC
- JMP ekwok ;'restore block end
- ekwclose MOV AH,#$3E ;close file
- JMP dos ;"
- ekwfile MOV DX,#fnbuf ;get filename
- CALL edreadst ;read it
- MOV BX,#fnbuf2 ;first char
- CMP.B [BX],#$1A ;= ^Z ?
- ekrret RET ;"yes: nothing entered
- ekr CALL eclrstat ;^KR:Read block from disk
- CALL ewrits ;write string
- B "Read block from file",$00
- CALL ekwfile ;get file name
- JZ ekrret ;nothing entered: ret
- CALL kpasext ;default extension .PAS
- MOV AX,#$3D00 ;open file
- MOV DX,#scrpn ;name ptr
- PUSH DS ;DS -> ES
- POP ES
- CALL dos ;do it
- XCHG AX,BX ;file handle
- JNB ekrfound ;:ok
- CALL eclrs2 ;clr status line
- CALL ewriterr ;write message
- B "File ",$00
- MOV SI,#scrpn ;write filename
- CALL printpn
- CALL prints ;write string
- B " not found",$00
- CALL waitesc ;wait for ESC
- JMP ekr ;'get another filename
- ekrfound PUSH BX ;save file handle
- MOV.B bkhide,#$00 ;flag: block not hidden
- CALL etstblk ;test block
- MOV BX,txend ;text end
- MOV DX,txmemend ;text space end
- MOV CX,#$00FE ;+ some space free
- ADD BX,CX
- SUB BX,DX
- PUSH BX ;save free space
- MOV CX,BX
- MOV BX,nbkbeg ;new block beg
- STC
- CALL echgsize ;make space
- POP AX ;restore free space
- POP BX ;restore file handle
- MOV DX,nbkbeg ;new block beg
- MOV CX,DX ;-> offset
- SUB CX,AX
- MOV explen,CX ;save end free space
- MOV vfilbig,#ebigfil ;set error vec
- CALL kload2 ;load block
- INC BX ;end of block read
- MOV bkend,BX ;store as new block end
- XCHG DX,BX ;-> DX
- MOV BX,nbkbeg ;new block beg
- MOV bkbeg,BX ;-> block beg
- ekrremov MOV BX,explen ;end free space
- SUB BX,DX ;-block end
- MOV CX,BX ;-> count
- JMP.b ekvremov ;'remove unneeded space
- MOV DX,nbkbeg ;File too big:
- CALL ekrremov ;remove space made free
- JMP etsterr ;"error: out of space
- eblkmov CALL etstblk ;^KV:Move block - test block
- JNB ekvrest
- CALL ecopyblk ;copy it
- MOV BX,nbkbeg ;new block beg
- MOV DX,bkbeg ;-> block beg
- MOV bkbeg,BX
- ADD BX,CX ;+ count
- MOV bkend,BX ;-> block end
- ekvremov XCHG BX,DX ;old block beg -> BX
- CLC
- CALL echgsize ;remove old block
- MOV BX,bkbeg ;block begin
- CALL efsetpos ;set position
- JMP erewrall ;'rewrite all
- ekvrest JMP erstlin ;"restore line
- eblkcpy CALL etstblk ;^KC:Copy block - test block
- JNB ekvrest
- CALL ecopyblk ;do copy it
- MOV BX,nbkbeg ;new block beg
- MOV bkbeg,BX ;-> block beg
- ADD BX,CX ;+ count
- MOV bkend,BX ;-> block end
- CALL eseldisp ;selective redisplay
- CALL erstlin ;restore line
- JMP erewrall ;"rewrite all
- etstblk CMP.B bkhide,#$00 ;Test block
- JZ etb2 ;:block not hidden
- CLC
- RET ;'
- etb2 CALL esrcend ;search end of input line
- INC BX ;+1
- MOV DX,lnpos ;pos in input line
- PUSH DX ;save it
- CALL emin ;take smaller of them
- XCHG BX,DX ;-> BX
- CALL efl2 ;write back to memory
- POP BX ;restore pos in input line
- MOV DX,#line ;calc relative pos in input line
- SUB BX,DX
- MOV DX,edpos ;+pos of current line
- ADD BX,DX
- MOV nbkbeg,BX ;-> new block beg
- PUSH BX ;save
- MOV DX,bkbeg ;block beg+1
- INC DX
- CMP BX,DX ;destination inside block ?
- MOV DX,bkend ;block end
- JB etbbeg ;:no
- CMP BX,DX
- JNB etbbeg ;:no
- OR.B AL,AL ;dest is in old block...
- JMP.b etb3 ;'end it
- etbbeg MOV BX,bkbeg ;block beg
- SUB BX,DX ;-block end
- MOV nbk,BX ;-> - block len
- MOV CX,BX ;-> count
- etb3 POP BX ;restore destination
- RET ;"
- ecopyblk CALL echgsize ;Copy block: make space for it
- MOV CX,nbk ;get count
- NEG CX ;(is - block len)
- MOV DX,nbkbeg ;block destination
- MOV BX,bkbeg ;block source
- PUSH CX ;save count
- CALL movebk ;move it
- POP CX ;restore count
- RET ;"
- eblkdel CALL eflush ;^KY:Delete block - rewrite line
- CMP.B bkhide,#$00 ;block hidden ?
- JNZ ekyrest
- MOV BX,bkbeg ;block beg
- CALL esrcbeg ;search beg of line
- MOV edpos,BX ;-> current pos
- MOV BX,posfifo ;update pos FIFO
- MOV DX,bkbeg ;inside block ?
- INC DX
- CMP BX,DX
- JB ekynochg ;:no
- MOV DX,bkend
- CMP BX,DX
- JNB ekynochg ;:no
- MOV BX,edpos ;current pos
- MOV posfifo,BX ;-> FIFO
- ekynochg MOV BX,bkend ;block end-block beg
- MOV DX,bkbeg
- SUB BX,DX ;calc count
- JNB ekyblkok ;:ok
- ekyrest JMP erstlin ;'restore line
- ekyblkok MOV CX,BX ;-> count
- XCHG BX,DX ;swap addrs
- PUSH BX ;save them
- PUSH CX
- PUSHF
- CALL eseldisp ;do selective rewrite
- POPF
- POP CX ;restore
- POP BX
- CALL echgsize ;delete block
- MOV BX,edpos ;current pos
- MOV bkbeg,BX ;-> block beg
- MOV bkend,BX ;-> block end
- CALL erstlin ;restore line
- JMP.b erewrall ;"rewrite all
- NOP ;^KH:hide / unhide block
- ekh NOT.B bkhide ;toggle flag: block hidden
- JMP.b erewrall ;"rewrite all
- NOP ;Mark block end
- emarkend MOV BX,lnpos ;pos in line
- MOV bkendl,BX ;-> block end in buffer
- MOV BX,edpos ;line pos
- MOV bkend,BX ;-> block end
- TEST.B attflg,#$02 ;block marked in this line ?
- LAHF
- OR.B attflg,#$02 ;set that flag
- emrend2 CMP.B bkhide,#$FF ;block hidden ?
- MOV.B bkhide,#$00 ;make it visible
- JZ erewrall ;hidden: rewrite all
- SAHF
- JZ erewrall ;no block marked in line: all
- JMP.b erewrlin ;"rewrite line, only
- NOP ;Mark block beg
- emarkbeg MOV BX,lnpos ;get pos in line
- MOV bkbegl,BX ;-> block beg in line buffer
- MOV BX,edpos ;current pos
- MOV bkbeg,BX ;-> block beg
- TEST.B attflg,#$01 ;block beg in this line ?
- LAHF
- OR.B attflg,#$01 ;set flag
- JMP emrend2 ;"as above
- ejbkbeg CALL eflush ;^QB:to beginning of block
- MOV BX,bkbeg ;block beg
- JMP efsetpos ;"set new position
- ejbkend CALL eflush ;^QK:to end of block
- MOV BX,bkend ;block end
- JMP efsetpos ;"set new position
- erewrlin MOV BH,#$00 ;Rewrite line
- CALL eposrow ;pos cursor to beg of line
- MOV BX,#line ;pos of current line
- MOV.B attchg,#$FF ;critical line
- CALL edmalin ;display it
- MOV.B attchg,#$00 ;normal again
- RET ;"
- erewrall CALL erewrlin ;rewrite line
- JMP eredall ;"then rewrite all
- ejtxend CALL eflush ;^QC:to end of text
- MOV BX,txend ;text end
- JMP efsetpos ;"set new position
- ejlnbeg MOV BX,#line ;^QS:to beg of line
- MOV lnpos,BX ;buffer beg -> pos in line
- JMP erepos ;"reposition in line
- ejlnend CALL esrcend ;^QD:to end of line
- INC BX ;search end of line+1
- MOV DX,#lineend ;too much ?
- CMP BX,DX
- JB ele2 ;:no
- MOV BX,#lineend1 ;limit it
- ele2 MOV lnpos,BX ;set new pos in line
- JMP erepos ;"reposition in line
- etogovr MOV.B statobs,#$00 ;^V:insert mode on/off
- NOT.B overflg ;toggle flag
- RET ;"status line obsolete
- etogind MOV.B statobs,#$00 ;^QI:indent mode on/off
- NOT.B indntflg ;toggle flag
- ednrt RET ;"status line obsolete
- eposcur MOV.B BH,phcol ;put cursor to current pos
- eposrow MOV.B BL,phrow
- JMP esetcur ;"set cursor pos
- edn MOV BX,edpos ;^X:line down
- CALL elindn ;go down one line
- JB ednrt
- CALL eflush ;rewrite line
- MOV BX,edpos ;now really go down
- CALL elindn
- edn2 MOV edpos,BX ;store new pos
- MOV.B scrfl2,#$00 ;flag: short update
- MOV.B scrfl1,#$FF
- CALL eseldisp ;do selective redisplay
- MOV.B scrfl1,#$00 ;clear flag
- JMP erstlin ;"restore line
- eup MOV BX,edpos ;^E:line up
- CALL elinup ;go up one line
- JB ednrt
- PUSH BX ;save pos
- CALL eflush ;rewrite line
- POP BX ;now go there
- JMP edn2 ;"set it
- escrup MOV AX,disbeg ;^W:scroll up
- CMP AX,txbeg ;display beg = text beg ?
- JZ eptret ;yes: ret
- CALL eflush ;rewrite line
- XOR CX,CX ;count pos on screen
- MOV BX,edpos ;current pos
- esulp CMP BX,disbeg ;= display beg ?
- JZ esu2 ;yes: do it
- CALL elinup ;go up one line
- INC CX ;count it
- JMP esulp ;'
- esu2 XCHG BX,edpos ;current pos = top of screen
- CS:
- MOV AL,txwiny2 ;line count - 3
- SUB AL,#$03
- CMP.B CL,AL ;= count ?
- JNZ esu3 ;no: ok
- CALL elinup ;go up one line
- esu3 PUSH BX ;save current pos
- MOV BX,edpos ;display beg
- CALL elinup ;go up one line
- CALL edn2 ;display it
- POP BX ;restore current pos
- esu4 JMP edn2 ;"set new pos
- escrdn CALL eflush ;^Z:scroll down
- PUSH edpos ;save current pos
- MOV BX,disbeg ;start from display beg
- XOR CX,CX
- CS:
- MOV.B CL,txwiny2 ;line count-2 -> CX
- SUB.B CL,#$02
- esdlp CALL elindn ;go down one line
- LOOP esdlp ;do it again
- PUSHF
- CALL edn2 ;set new pos
- POPF
- POP BX ;restore old pos
- JB esu4 ;:set new pos
- CMP BX,disbeg ;>= display beg ?
- JNB esu4 ;:set new pos
- CALL elindn ;go down one line
- JMP esu4 ;'set new pos
- eptret RET ;"
- epagtop MOV BX,disbeg ;^QE:to page top
- CMP BX,edpos ;display beg = current line ?
- JZ eptret ;yes: done
- PUSH BX ;save this pos
- CALL eflush ;rewrite line
- POP BX ;display beg -> new pos
- JMP esu4 ;"set that pos
- epagbot CALL eflush ;^QX:to bottom of page
- MOV BX,disbeg ;display beg
- XOR CX,CX ;line count-3 -> CX
- CS:
- MOV.B CL,txwiny2
- SUB.B CL,#$03
- epblp CALL elindn ;go down one line
- LOOP epblp ;:again
- JMP esu4 ;"set new pos
- epagdn CALL eflush ;^C:page down - rewrite line
- CS:
- MOV AL,txwiny2 ;line count - 2
- SUB AL,#$02
- MOV.B CH,AL ;-> CL, CH
- MOV.B CL,AL
- MOV BX,disbeg ;display beg
- epdlp CALL elindn ;go down one line
- DEC.B CH
- JNZ epdlp ;:another one
- MOV disbeg,BX ;store new display beg
- MOV BX,edpos ;current pos
- epdl2 CALL elindn ;go down one line
- LOOP epdl2 ;:again
- epd2 MOV edpos,BX ;set new pos
- CALL eseldisp ;redisplay
- CALL eredall ;redisplay all
- JMP erstlin ;"restore line
- epagup CALL eflush ;^R:page up - rewrite line
- CS:
- MOV AL,txwiny2 ;line count - 2
- SUB AL,#$02
- MOV.B CH,AL ;-> CL, CH
- MOV.B CL,AL
- MOV BX,disbeg ;display beg
- epulp CALL elinup ;go up one line
- DEC.B CH
- JNZ epulp ;:another
- MOV disbeg,BX ;store new display beg
- MOV BX,edpos ;current pos
- epul2 CALL elinup ;go up one line
- LOOP epul2 ;:another
- JMP epd2 ;"set new pos, redisplay
- etxtbeg MOV BX,disbeg ;^QR:to beg of text
- MOV DX,txbeg ;text beg = display beg ?
- CMP BX,DX
- JZ etsb2 ;:yes
- CALL eredall ;no:redisplay all
- etsb2 CALL eflush ;rewrite line
- MOV BX,txbeg ;text beg
- MOV edpos,BX ;-> current pos
- MOV disbeg,BX ;-> display beg
- CALL eseldisp ;do selective redisplay
- CALL erstlin ;restore line
- MOV BX,#line ;go to beg of line
- MOV lnpos,BX ;pos in line
- JMP erepos ;"reposition in line
- ecr CMP.B overflg,#$00 ;CR:carriage return
- JNZ ecrins ;:insert mode
- CALL edn ;go down one line
- JMP ejlnbeg ;'go to beg of line
- ecrins MOV.B txchg,#$FF ;set flags: text changed
- MOV.B txcomp,#$00
- MOV BX,phrow ;current cursor pos
- INC.B BL
- CALL esetcur ;set cursor to beg of line
- CALL elinbrk ;insert line break
- MOV BX,edpos
- PUSH BX ;save current pos
- CALL erstlin ;restore line
- CALL eflush ;rewrite line
- POP BX ;restore current pos
- CALL elindn ;go down one line
- MOV edpos,BX ;-> current pos
- MOV BX,#line ;go to beg of line
- CALL eredisp ;redisplay
- CALL eposcur ;set new position
- CMP.B indntflg,#$00 ;indent ?
- JZ elftret ;:no
- CALL etabup ;up one line from curr pos
- JB elftret ;:no
- MOV SI,#esepspc ;separator: spaces only
- CALL etslp ;'go word right
- JNB elftret
- JMP etab ;"do tab
- eredisp MOV lnpos,BX ;store pos in buffer
- CALL erepos ;reposition in line
- CALL eseldisp ;selective redisplay
- JMP erstlin ;"restore line
- elinins CALL elinbrk ;^N:insert line - insert line break
- MOV.B BL,phrow ;row + 1
- INC.B BL
- XOR.B BH,BH ;col = 0
- CALL esetcur ;set cursor pos
- MOV BX,edpos ;current pos
- CALL elindn ;go down one line
- CALL edmalin ;display line
- JMP erstlin ;"restore line
- elinbrk CALL eflush ;Insert line break: rewrite line
- CALL xinsline ;InsLine
- CALL esrcend ;search end of line + 1
- INC BX
- MOV DX,lnpos ;pos in buffer
- CALL emin
- MOV DX,#line ;relative pos in line
- SUB BX,DX
- elb2 XCHG BX,DX ;-> DX
- MOV BX,edpos ;current pos
- ADD BX,DX ;+ relative pos
- PUSH BX ;save pos of line break
- STC ;insert two bytes
- MOV CX,#$FFFE
- CALL echgsize ;do it
- POP BX ;restore pos
- MOV [BX],#$0A0D ;store CR, LF there
- INC BX
- elftret RET ;"
- eleft MOV BX,lnpos ;^S, ^H:character left
- DEC BX ;pos in line - 1
- CMP BX,#line ;already at the beg ?
- JB elftret
- eleft2 MOV lnpos,BX ;set new pos
- JMP erepos ;"reposition in line
- eright MOV BX,lnpos ;^D:character right
- INC BX ;pos in line + 1
- CMP BX,#lineend0 ;= end of buffer ?
- JB eleft2 ;below: ok, set it
- RET ;"
- elstpos CALL eflush ;^QP:to last position
- MOV BX,qppos ;get pos from FIFO
- CALL esrcbeg ;search beg of line
- MOV edpos,BX ;-> current pos
- MOV BX,qppos1 ;get display beg from FIFO
- JMP eredisp ;"redisplay
- emrkwrd CALL ewrdrt ;^T:mark word - word right
- CALL ewrdlft ;word left
- MOV BX,lnpos ;pos in line buffer
- emwlp CALL etstsep ;char = separator ?
- JB emwend ;yes: word end found
- INC BX ;next char
- CMP BX,#lineend0 ;end of line ?
- JB emwlp ;:no, continue
- emwend MOV lnpos,BX ;-> current pos
- CALL emarkend ;mark block end
- CALL ewrdlft ;go left one word
- JMP emarkbeg ;"mark block beg
- ewlup MOV BX,edpos ;get current pos
- CALL elinup ;go up one line
- JB ewloldp
- PUSH BX ;save pos
- CALL eflush ;rewrite line
- POP BX
- MOV edpos,BX ;set new pos
- MOV.B scrfl2,#$00 ;set flag: short updating
- CALL eseldisp ;selective redisplay
- CALL erstlin ;restore line
- CALL esrcend ;search end of line
- JMP.b ewlle ;'store position
- ewrdlft MOV BX,lnpos ;^A:word left
- ewllp DEC BX ;pos in buffer-1:search char<>sep
- CMP BX,#line ;= line beg ?
- JB ewlup ;yes: go up one line
- CALL etstsep ;char = separator ?
- JB ewllp ;yes: continue searching
- ewll2 DEC BX ;go back: search separator
- CMP BX,#$046C ;= line beg ?
- JB ewlle ;yes: end it
- CALL etstsep ;char = separator ?
- JNB ewll2 ;:no
- ewlle INC BX ;go to left of word
- ewlpos MOV lnpos,BX ;store pos in line
- ewloldp MOV BX,lnpos ;get pos
- JMP erepos ;"reposition in line
- ewrdrt CALL esrcend ;^F:word right
- MOV AX,BX ;end of line -> AX
- MOV BX,lnpos ;pos in line
- SUB AX,BX ;calc count
- MOV AL,#$00
- JNB ewr1 ;:ok
- INC.B AL
- ewr1 MOV curpast,AL ;flag: cursor past end of line
- ewrlp DEC BX
- ewrl2 INC BX ;next char
- CMP BX,#lineend0 ;end of line ?
- JB ewrtst ;:no
- ewrl3 MOV BX,edpos ;current pos
- CALL elindn ;go down one line
- JB etabret
- CALL eflush ;rewrite line
- MOV BX,edpos ;current pos
- CALL elindn ;go down
- MOV edpos,BX ;new pos
- MOV.B scrfl2,#$00 ;short update
- CALL eseldisp ;redisplay
- CALL erstlin ;restore line
- MOV BX,#$046C ;go to beg of line
- MOV lnpos,BX
- CALL etstsep ;char = separator ?
- JB ewrlp ;:yes
- JMP erepos ;'set that pos
- ewrtst CALL etstsep ;char = separator ?
- JNB ewrl2 ;:no
- ewrlp2 INC BX ;next char
- CMP BX,#lineend0 ;end of line ?
- JB ewrtst2 ;:no
- CMP.B curpast,#$00 ;cursor past end of line ?
- JNZ ewrl3 ;:yes
- CALL esrcend ;search end of line + 1
- INC BX
- JMP ewlpos ;'set that pos
- ewrtst2 CALL etstsep ;char = separator ?
- JB ewrlp2 ;:yes
- JMP ewlpos ;"set that pos
- etabup MOV BX,edpos ;current pos
- CALL elinup ;go up one line
- etabret RET ;"
- etab CALL etabup ;^I:Tab - go up one line
- JB etabret
- MOV AL,phrow ;save phys row
- PUSH AX
- MOV BX,lnpos ;pos in line
- MOV lnupper,BX ;store pos of upper line
- MOV.B disflg,#$00 ;normal mode
- CALL eflush ;rewrite line
- MOV BX,edpos ;current pos
- PUSH BX ;save it
- CALL elinup ;go up one line
- MOV edpos,BX ;store pos
- CALL erstlin ;restore line
- PUSH sepptr ;save ptr
- MOV sepptr,#esepspc ;set sep ptr: spaces only
- CALL ewrdrt ;word right
- POP sepptr ;restore sep ptr
- POP edpos ;restore current pos
- POP AX
- MOV phrow,AL ;restore phys row
- CALL erstlin ;restore line
- MOV.B disflg,#$FF ;flag: short update
- CMP.B overflg,#$FF ;insert ?
- JZ etabins ;:yes
- JMP erewrlin ;'rewrite line
- etabins MOV BX,lnpos ;pos in line
- MOV DX,lnupper ;pos in upper line
- SBB BX,DX ;difference
- JBE etabret ;not found: ret
- XCHG BX,DX ;-> count
- etabinsl PUSH DX ;save count
- CALL einsch ;insert a char
- MOV.B [BX],#$20 ;space
- POP DX ;restore count
- DEC.B DL ;another ?
- JNZ etabinsl ;:yes
- JMP erewrlin ;"rewrite line
- edeleol MOV BX,lnpos ;^QY:delete to end of line
- PUSH BX ;save pos in line
- CALL etstbk ;test block markers in line
- POP BX ;restore pos
- PUSH BX
- MOV DX,#lineend1 ;end position
- edelp MOV.B [BX],#$20 ;fill up with spaces
- CMP BX,DX ;end reached ?
- JZ edeend ;:yes
- INC BX ;next char
- JMP edelp ;'
- edeend POP BX ;restore pos in line
- JMP eredlin ;"redisplay line
- edellin MOV BX,#line ;^Y:delete line
- MOV lnpos,BX ;to line beg
- CALL erepos ;reposition in line
- CALL edeleol ;delete to end of line
- CALL eflush ;rewrite line
- MOV BX,edpos ;current pos
- PUSH BX ;save it
- PUSH BX
- CALL elindn ;go down one line
- POP DX ;old pos
- JB edlend
- SUB BX,DX ;difference
- MOV CX,BX ;-> count
- POP BX ;restore current pos
- JNZ edb3 ;:erase the rest
- RET ;'
- edlend POP BX ;remove from stack
- JMP erstlin ;"restore line
- edlinbrk CALL efl2 ;del line break: rewrite to BX
- MOV BX,edpos ;current pos
- CALL elindn ;go down one line
- JNB edb2 ;:ok
- JMP erstlin ;'restore line
- edb2 DEC BX ;go back two bytes
- DEC BX
- MOV CX,#$0002 ;delete 2 bytes
- OR.B AL,AL ;clear carry
- edb3 CALL echgsize ;do it
- CALL xdelline ;DelLine
- CS:
- MOV AL,txwiny2 ;get line cnt - 1
- DEC.B AL
- CALL edsplin ;redisplay last line
- JMP erstlin ;"restore line
- edelwrd CALL esrcend ;^T:delete right word
- MOV DX,lnpos ;pos in buffer
- CMP BX,DX ;> end ?
- XCHG BX,DX
- JB edlinbrk ;:delete line break
- MOV.B AL,[BX] ;get char
- CMP AL,#$20 ;space ?
- JZ edelspc ;:delete spaces
- CALL etstsep ;separator ?
- JB edel2 ;:end it
- edwlp CALL edelch ;delete char
- CALL etstsep ;separator ?
- JB edrest ;:yes, end
- JMP edwlp ;"another char
- edwend MOV BX,edpos ;current pos
- CALL elinup ;up one line
- JB edwret
- CALL eup ;line up
- CALL ejlnend ;go to line end
- JMP edelwrd ;'delete word
- edwret RET ;'
- edelrt MOV BX,lnpos ;^G:delete right
- JMP.b edel2 ;'
- edellft MOV BX,lnpos ;DEL:delete left
- DEC BX ;go back one char
- CMP BX,#line ;beg of line ?
- JB edwend ;yes: go to line above
- MOV lnpos,BX ;store new pos
- edel2 CALL edelch ;delete char
- edrest CALL erepos ;reposition on line
- JMP eredlin ;"redisplay line
- edelspc CALL edelch ;Delete spaces
- MOV.B AL,[BX] ;get char
- CMP AL,#$20 ;space ?
- JZ edelspc ;:delete it
- JMP edrest ;"redisplay
- eredispl CALL eposcur ;Redisplay: set cursor pos
- CALL edisbdn ;go down from display beg
- edisp1 CALL ekbdstat ;get KBD stat
- JNZ edisp2
- CALL edsp2 ;redisplay
- JNB edisp1 ;:continue
- edisp2 JMP eposcur ;"set cursor pos
- edodispl CALL eposcur ;Redisplay: set cursor pos
- CALL edisbdn ;go down from display beg
- eddlp CALL edsp2 ;redisplay
- JNB eddlp ;:continue
- JMP eposcur ;"set cursor pos
- edisbdn MOV.B CL,dislin ;go down from display beg
- edisbdn2 XOR.B CH,CH ;count: first line to display
- MOV BX,disbeg ;display beg
- DEC CX ;count down
- JZ eddnil ;:end it
- eddn CALL elindn ;go down one line
- JB eddend
- LOOP eddn ;:another line
- eddnil RET ;'
- eddend MOV BX,txend ;go to text end
- RET ;"
- edodisp CALL elindn ;do redisplay: go down
- JNB edsp2 ;:ok
- MOV BX,txend ;go to text beg
- edsp2 MOV AL,dislin ;display from where ?
- CS:
- CMP.B AL,txwiny2 ;= line cnt ?
- JNB edspret
- INC.B dislin ;go down one more line
- CMP.B AL,phrow ;= phys row ?
- JZ edodisp ;yes: go down
- edsp3 MOV scrrow,AL ;current line
- CMP BX,txend ;text end reached ?
- JNB edsp4 ;:yes
- CALL edmalin ;display line
- CLC ;not yet end
- RET ;'
- edsp4 CALL esetnrm ;NormVideo
- CALL eclrlin ;clear line
- CLC ;not yet end
- RET ;'
- edspret STC ;end it
- RET ;"
- edsplin PUSH AX ;redisplay one line
- MOV.B CL,AL ;line number
- CALL edisbdn2 ;go down to this line
- POP AX ;restore
- JMP edsp3 ;"redisplay that line
- esrcbeg MOV AL,#$0A ;search beg of line: LF
- esblp DEC BX ;go back
- CMP BX,txbeg ;text beg ?
- JZ esbend ;yes: end it
- JB esb1 ;below: next char
- CMP.B AL,[BX] ;test char: LF ?
- JNZ esblp ;no: continue searching
- esb1 INC BX ;next char
- esbend RET ;"
- eskipcr CMP AL,#$0D ;Skip CR
- JNZ escret ;no: ret
- MOV.B AL,[BX] ;get char
- INC BX ;next char
- CMP BX,txend ;text end ?
- JB eskipcr ;no: continue
- escret RET ;"
- eclrlin CS: ;Clear line
- MOV.B CH,txwinx2 ;col count-1
- DEC.B CH
- JMP eclrln ;"clear line
- escrdma PUSH DS ;Prepare screen DMA
- POP ES ;DS -> ES
- MOV DI,#dmabuf ;ptr to DMA buffer
- CLD
- XOR.B AH,AH ;AL -> CX = pos in line
- MOV CX,AX
- MOV SI,AX ;AL*2 -> SI
- ADD SI,SI
- CS:
- MOV AL,txwinx2 ;column count * 2
- ADD AX,AX
- MOV BP,AX ;-> BP
- SUB BP,SI ;- horizontal offset
- MUL.B scrrow ;line length * current row
- ADD BP,AX ;+ row position
- RET ;"
- escrdma2 INC.B AL ;column + 1
- CALL escrdma ;prepare DMA
- DEC CX ;char cnt-1
- JMP.b edlcrit ;"do it
- edmalin CS: ;Display line
- MOV AL,txwinx2 ;column count
- CALL escrdma ;prepare screen DMA
- DEC CX ;count down
- MOV.B AH,horscr ;horizontal scroll
- OR.B AH,AH ;=0 ?
- JZ edlcrit
- edl1 CALL esetatt ;set attribute
- MOV.B AL,[BX] ;get char
- INC BX ;next char
- CMP BX,txend ;text end ?
- JNB edletx ;:yes
- CALL eskipcr ;skip CR
- CMP AL,#$0A ;LF ?
- JZ edletx ;:yes
- DEC.B AH ;another char ?
- JNZ edl1 ;:yes
- edlcrit CMP.B attchg,#$00 ;critical line
- JZ edlatt ;:no
- PUSH BX ;save pos
- CALL esrcend ;search end of line
- MOV AX,lnpos ;pos in line = end of line ?
- CMP AX,BX
- JBE edllim ;:ok
- MOV BX,AX ;limit it
- edllim INC BX
- MOV eolpos,BX ;pos: end of line
- POP BX ;restore pos
- CALL esetatt ;set attribute
- CMP BX,eolpos ;= pos EOL ?
- JNB edletx ;:yes
- edlatt CALL esetatt ;set attribute
- CMP BX,eolpos ;end of line ?
- JZ edletx ;yes: end
- MOV.B AL,[BX] ;get char
- INC BX ;next
- CMP BX,txend ;text end ?
- JA edletx ;yes: end
- CMP AL,#$0D ;CR ?
- JZ edllp ;yes: forget it
- CMP AL,#$20 ;control char ?
- JNB edlnrm ;:no, normal
- ADD AL,#$40 ;convert to normal
- PUSH AX ;save it
- CALL etogatt ;set attribute
- POP AX ;restore
- edlnrm MOV.B AH,attcur ;current attribute
- STOS ;store in buffer
- LOOP edlatt ;:another char
- edllp MOV.B AL,[BX] ;get char
- INC BX
- CMP BX,txend ;text end ?
- JA edletx ;:yes
- CMP AL,#$0A ;LF ?
- JNZ edllp ;:not yet
- edletx INC CX ;one more byte
- MOV AL,#$20 ;fill up with spaces
- MOV.B AH,attcur ;current attribute
- REPZ
- STOS
- CMP.B disflg,#$00 ;display it ?
- JZ edlret ;:no
- MOV CX,SI ;byte number / 2 -> words
- SHR CX,1
- MOV DI,BP ;destination ofs
- MOV ES,scrseg ;screen segment
- MOV SI,#dmabuf ;buffer addr
- CMP.B scrbad,#$FF
- JZ edlbad ;:yes
- REPZ ;just move it into screen memory
- MOVS
- edlret RET ;'
- edlbad MOV DX,#$03DA ;test port
- edlblp LODS ;get word
- MOV BP,AX ;save it
- edlbw1 IN AL,DX ;get status
- RCR.B AL,1
- JB edlbw1 ;:wait
- CLI ;no INT allowed
- edlbw2 IN AL,DX ;get status
- RCR.B AL,1
- JNB edlbw2 ;:wait
- XCHG AX,BP ;restore char
- STOS ;store it
- STI ;clear interrupt
- LOOP edlblp ;:another char
- edlbret RET ;"
- esetatt CMP.B bkhide,#$FF ;Set attribute
- JZ esetnrm ;:block hidden
- CMP.B attchg,#$FF ;block beg/end in this line ?
- JZ esetblk ;:no
- CMP BX,bkbeg ;block begin ?
- JB esetnrm ;:no, normal
- CMP BX,bkend ;block end ?
- JNB esetnrm ;above: normal
- JMP.b eset2 ;'in block !
- esetblk CMP BX,bkbegl ;= pos block beg in buffer ?
- JB esetnrm ;:no, normal
- CMP BX,bkendl ;> pos block end in buffer ?
- JNB esetnrm ;yes: normal
- eset2 CMP.B disflg,#$00 ;display it ?
- JZ edlbret ;:no
- JMP vidattr2 ;'Attribute #2
- esetnrm CMP.B disflg,#$00 ;display it ?
- JZ edlbret ;:no
- JMP knrmvid ;"NormVideo
- esetlow CMP.B disflg,#$00 ;display it ?
- JZ edlbret ;:no
- JMP klowvid ;"LowVideo
- etogatt CMP.B curatt,#$01 ;low set ?
- JZ esetnrm ;yes:NormVideo
- JMP esetlow ;"LowVideo
- eclrln CMP.B disflg,#$00 ;Clear line
- JZ edlbret
- PUSH AX ;save
- PUSH DX
- MOV.B AL,CH ;line number+1
- INC.B AL
- CALL escrdma ;prepare screen DMA
- DEC CX ;length-1
- CALL edletx ;erase to end of line
- POP DX ;restore
- POP AX
- RET ;"
- escrolup MOV BX,#$0001 ;Scroll up
- CALL esetcur ;set cursor pos: top line
- JMP xdelline ;"DelLine
- erstlin MOV BX,edpos ;^QL:restore line
- MOV DX,#$0000 ;clear block pos in buf:
- MOV bkbegl,DX ;block beg
- MOV bkendl,DX ;block end
- MOV CH,#$7F ;up to 127 chars
- MOV SI,#line ;dest: line buffer
- MOV.B attflg,#$00 ;flag: no block beg / end
- erllp MOV.B AL,[BX] ;get char
- CMP BX,bkbeg ;block beg ?
- JNZ erlnbeg ;:no
- MOV bkbegl,SI ;pos block beg in line
- OR.B attflg,#$01 ;block beg in this line
- erlnbeg CMP BX,bkend ;block end ?
- JNZ erlnend ;:no
- MOV bkendl,SI ;pos block end in line
- OR.B attflg,#$02 ;block end in this line
- erlnend CMP AL,#$0D ;CR ?
- JNZ erlnext ;no:next char
- MOV.B [SI],#$20 ;store a space
- INC SI ;next
- DEC.B CH ;count down
- JZ elonglin ;:line too long
- INC BX ;next char
- CMP BX,txend ;end of text ?
- JNB erllp ;:no, continue
- erlend CMP BX,bkend ;block active in this line ?
- JNB erlbeg ;:no
- PUSH BX ;save pos
- MOV BX,#$FFFF ;flag: block ends after
- MOV bkendl,BX ;this line
- POP BX
- erlbeg CMP BX,bkbeg ;block beg ?
- JNB erllen
- MOV BX,#$FFFF ;flag: block starts before this
- MOV bkbegl,BX ;line
- erllen MOV AL,#$7F ;test line length
- SUB.B AL,CH
- MOV oldlen,AL ;store old length
- erlpad MOV.B [SI],#$20 ;fill up with spaces
- INC SI
- DEC.B CH
- JNZ erlpad ;:again
- MOV BX,lnpos ;pos in buffer
- CALL erepos ;reposition in line
- CMP.B scrfl2,#$00 ;small move only ?
- MOV.B scrfl2,#$FF ;reset flag
- JZ erldisp ;:yes
- JMP erewrlin ;'redisplay line
- erldisp MOV AL,dislin ;redisplay from ...
- DEC.B AL
- CMP.B AL,phrow ;= phys row ?
- JNB eseret ;above: ret
- JMP erewrlin ;'rewrite line
- erlnext CMP AL,#$0A ;LF ?
- JZ erlend ;yes: end it
- MOV.B [SI],AL ;store char
- INC SI ;go to next
- DEC.B CH ;too much ?
- JNZ erletx ;:no
- JMP.b elonglin ;'error: long line
- erletx INC BX ;end of text ?
- CMP BX,txend
- JNB erlend ;yes: end it
- JMP erllp ;"continue
- elonglin CALL eclrstat ;Insert line break - line too long
- CALL ewriterr ;write message
- B "Line too long - CR inserted",$00
- CALL waitesc ;wait for ESC
- MOV BX,#$007D ;offset
- CALL elb2 ;insert line break
- CALL erstlin ;restore line
- JMP erewrall ;"rewrite all
- eclrstat CALL edodispl ;Clear status line
- eclrs2 MOV.B statobs,#$00 ;status line destroyes
- MOV BX,#$0000 ;set cursor pos
- CALL esetcur
- CALL knrmvid ;NormVideo
- CALL eclrlin ;clear line
- MOV BX,#$0000 ;set cursor pos
- CALL esetcur
- JMP klowvid ;"LowVideo
- esrcend MOV AL,#$20 ;Search end of input line
- MOV BX,#lineend1 ;end pos
- MOV DX,#line0 ;start pos
- eselp CMP.B AL,[BX] ;space ?
- JNZ eseret ;no: end found
- DEC BX ;search backwards
- CMP BX,DX ;beg reached ?
- JNZ eselp ;no:continue
- eseret RET ;"
- elimpos MOV DX,#lineend ;BX>end of line ?
- CMP BX,DX
- JNB eseret ;:ret
- MOV DX,CX
- JMP emin ;"min(BX,DX)->BX
- eflush CALL esrcend
- INC BX ;search end of line + 1
- efl2 MOV CX,BX ;end position
- MOV BX,bkbegl ;pos block beg in buf
- CALL elimpos ;limit to end position
- MOV bkbegl,BX
- MOV BX,bkendl ;pos block beg in buf
- CALL elimpos ;limit to end position
- MOV bkendl,BX
- MOV BX,CX ;restore end position
- INC BX ;+1
- MOV DX,#line ;- beg position
- SUB BX,DX
- PUSH BX ;-> length
- MOV AL,oldlen ;old length - new length
- SUB.B AL,BL
- MOV.B CL,AL ;-> count
- MOV CH,#$00
- JNB eflpos ;:ok
- MOV CH,#$FF ;negative
- eflpos MOV BX,edpos ;current pos
- JZ eflsame ;:no size change
- CALL echgsize ;expand / shrink text
- eflsame POP CX ;restore length
- MOV SI,edpos ;destination pos
- MOV BX,#line ;buffer pos
- MOV.B CH,CL ;count
- OR.B CH,CH ;test it
- JZ eflend ;0:nothing to do
- efllp MOV.B AL,[BX] ;get char
- CMP BX,bkbegl ;= block beg ?
- JNZ eflnbeg ;:no
- MOV bkbeg,SI ;set block beg
- eflnbeg CMP BX,bkendl ;= block end ?
- JNZ eflnend ;:no
- MOV bkend,SI ;set block end
- eflnend MOV.B [SI],AL ;store char
- INC BX ;next char
- INC SI
- DEC.B CH ;another ?
- JNZ efllp ;:yes
- DEC SI ;go back one char
- eflend MOV.B [SI],#$0D ;store CR at end
- RET ;"
- etstmem MOV BX,txmemend ;Test if memory full
- SUB BX,DX ;end text space - new text end
- JB etsterr ;:error
- MOV CX,#$00FE ;254 bytes left ?
- SUB BX,CX
- JNB etstret ;or more: ret
- ADD BX,CX ;restore
- PUSH BX
- CALL eclrs2 ;clear status line
- POP BX ;number free bytes
- MOV CH,#$00
- CALL ewriterr ;write message
- B "WARNING: ",$00
- CALL edcvt ;display number
- CALL ewriterr ;write message
- B " byte(s) left",$00
- CALL waitesc ;wait for ESC
- etstret RET ;'
- etsterr CALL eclrstat ;clear status line
- CALL ewriterr ;write message
- B "ERROR: Out of space",$00
- CALL waitesc ;wait for ESC
- JMP edmain ;"return to main loop
- etstint CMP AL,#$15 ;Test for interrupt
- JNZ etstret ;:not ^U - ret
- CALL eclrstat ;clear status line
- CALL ewriterr ;write message
- B "*** INTERRUPTED",$00
- CALL waitesc ;wait for ESC
- JMP edmain ;"go to main loop
- echgsize PUSH BX ;Shrink or expand text
- PUSH CX ;save pos,cnt
- JB edinsert ;:insert, negative count
- JMP edshrink ;'delete, positive count
- edinsert MOV DX,txend ;save text end
- PUSH DX
- PUSH DX
- XCHG DX,BX ;text end - pos
- SUB BX,DX
- MOV BP,BX ;-> BP
- POP BX ;text end
- PUSH BP ;save (text end - pos)
- SUB BX,CX ;text end - count
- JNB etsterr ;:error - out of space
- MOV DX,BX ;-> BX
- PUSH DX ;save new text end
- CALL etstmem ;test space free
- POP DX ;restore new text end
- POP CX ;restore count+1
- INC CX
- POP BX ;text end
- MOV txend,DX ;set new text end
- OR CX,CX ;test count
- JZ edins2 ;0:no move to do
- CALL movebkb ;move block backwards
- edins2 POP CX ;restore difference
- POP BX ;pos
- XCHG BX,DX
- MOV BX,bkbeg ;update pointers:
- CALL edupdate ;block beg
- MOV bkbeg,BX
- MOV BX,bkend
- CALL edupdate ;block end
- MOV bkend,BX
- MOV BX,disbeg
- CALL edupdate ;display beg
- MOV disbeg,BX
- MOV BX,edpos
- CALL edupdate ;pos current line
- MOV edpos,BX
- MOV BX,posfifo
- CALL edupdate ;position FIFO
- MOV posfifo,BX
- MOV BX,qppos
- CALL edupdate ;pos FIFO 2
- MOV qppos,BX
- MOV BX,srend
- CALL edupdate ;search limit end
- MOV srend,BX
- MOV BX,srbeg
- CALL edupdate ;search limit beg
- MOV srbeg,BX
- RET ;"
- edupdate CMP BX,DX ;update pointer: >pos of change ?
- JBE edupret ;below/equal: no change
- SUB BX,CX ;change it
- edupret RET ;"
- edshrink PUSH BX ;Shrink text: save pos
- ADD BX,CX ;+ count
- PUSH BX ;save
- MOV DX,txend ;text end+1
- INC DX
- XCHG DX,BX ;-pos-count
- SUB BX,DX
- MOV CX,BX ;-> move count
- POP BX ;restore source
- POP DX ;restore dest
- OR CX,CX ;test counter
- JZ edshnil ;:nothing to move
- CALL movebk ;move it - delete
- DEC DX ;end pos-1
- edshnil MOV txend,DX ;set new end pos
- JMP edins2 ;"update pointers
- etstbk PUSH BX ;Test block markers in line buffer
- MOV DX,bkbegl ;pos block beg in buffer
- CALL emin ;min(BX,DX)->BX
- TEST.B attflg,#$01 ;block beg in this line ?
- JZ etbnbeg ;:no
- MOV bkbegl,BX ;set it
- etbnbeg POP BX ;restore
- TEST.B attflg,#$02 ;block end in this line ?
- JZ etbnend ;:no
- MOV DX,bkendl ;update it
- CALL emin
- MOV bkendl,BX
- etbnend RET ;"
- erepos MOV DX,#line ;Reposition in current line
- CS: ;ptr line beg
- MOV AL,txwinx2 ;column count - 1 -> CL
- DEC.B AL
- MOV.B CL,AL
- SUB BX,DX ;relative pos -> BX
- MOV.B AL,BL
- SUB.B AL,horscr ;pos < hor scroll ?
- JB erephscr ;yes: underflow
- CMP.B AL,CL ;outside displayed window ?
- JB erepcol ;no: ok
- SUB.B AL,CL ;calc diff+1 (overflow)
- INC.B AL
- ADD.B AL,horscr ;add to horizontal scroll
- MOV horscr,AL
- CS:
- MOV AL,txwinx2 ;col cnt-2 -> phys col
- DEC.B AL
- DEC.B AL
- MOV phcol,AL
- JMP erewrall ;'redisplay all
- erepcol MOV phcol,AL ;store phys col
- erepret RET ;'
- erephscr ADD.B AL,horscr ;add to horizontal scroll
- MOV horscr,AL
- MOV.B phcol,#$00 ;phys col 0
- JMP erewrall ;"rewrite all
- eseldisp CMP.B disflg,#$00 ;Do selective rewrite
- JZ erepret
- MOV BX,disbeg ;display beg
- MOV AX,txbeg ;text beg
- CMP AX,BX ;the same ?
- JBE esd2 ;:yes
- MOV disbeg,AX ;store to display beg
- MOV BX,AX
- esd2 MOV CX,#$0001 ;line cnt
- MOV DX,edpos ;current pos
- CMP BX,DX ;= display beg ?
- JNZ esd3 ;:no
- JMP esd9 ;'yes: done
- esd3 JB esddn ;below: search down
- esd4 MOV DX,edpos ;current pos
- CMP BX,DX ;= ?
- JZ esd5
- CALL elinup ;go up one line
- INC CX ;count it
- JMP esd4 ;'
- esd5 MOV disbeg,BX ;store display beg
- MOV.B phrow,#$01 ;phys row
- MOV.B scrfl2,#$FF ;set flag
- XOR AX,AX
- CS:
- MOV AL,txwiny2 ;row cnt - 1
- SUB AX,#$0001
- CMP AX,CX ;= line ?
- JB esdredsp ;below: ok
- DEC CX ;go back one line
- MOV BX,#$0001 ;set cursor pos:
- CALL esetcur ;below status line
- DEC CX ;test it
- PUSHF
- INC CX ;restore
- esdinsl CALL xinsline ;InsLine
- LOOP esdinsl ;:again
- POPF ;one only ?
- JNZ esdredsp ;no: do redisplay
- RET ;'
- esdredsp JMP eredall ;'redisplay all
- esddn CMP BX,edpos ;>= current pos
- JNB esd6 ;:not yet
- CALL elindn ;go down one line
- INC CX ;count
- JMP esddn ;'
- esd6 OR.B CH,CH ;clear count
- JNZ esd10 ;:much
- CS:
- MOV AL,txwiny2 ;line count-1 -> DL
- DEC.B AL
- MOV.B DL,AL
- MOV.B AL,CL ;counter-line cnt+1 -> DH
- SUB.B AL,DL
- MOV.B DH,AL
- INC.B DH
- JB esd9 ;:ok
- DEC.B DH ;test it
- JNZ esd7
- CMP.B scrfl1,#$FF ;test flag
- JNZ esd7 ;:normal
- JMP.b esd11 ;'keep it short
- NOP
- esd7 INC.B DH
- SUB.B AL,DL
- JNB esd10
- MOV AL,dislin ;redisplay from
- SUB.B AL,DH
- JBE esd10
- MOV dislin,AL ;set it
- MOV BX,disbeg ;display beg
- MOV.B CH,DH
- PUSH DX
- esdscrl CALL elindn ;go down one line
- PUSH BX ;save pos
- CALL escrolup ;scroll up
- POP BX ;restore
- DEC.B CH ;count down
- JNZ esdscrl ;:another
- MOV disbeg,BX ;store display beg
- POP DX
- esd8 DEC.B DL
- MOV.B phrow,DL ;phys row
- RET ;'
- esd9 MOV.B phrow,CL
- RET ;'
- esd10 MOV BX,disbeg
- DEC CX
- CS: ;line cnt - 3 -> DL
- MOV AL,txwiny2
- SUB AL,#$03
- MOV.B DL,AL
- MOV.B AL,CL
- SUB.B AL,DL
- MOV.B CL,AL
- JNB esddn2
- DEC.B CH
- esddn2 CALL elindn ;go down one line
- LOOP esddn2 ;:again
- MOV disbeg,BX ;store display beg
- CALL eredall ;redisplay all
- MOV.B scrfl2,#$FF ;set flag: long update
- JMP eseldisp ;'do it again
- esd11 CALL esd8 ;set phys row
- MOV AL,dislin ;redisplay from
- CS:
- CMP.B AL,txwiny2 ;= line cnt ?
- JZ esd12 ;:yes
- DEC.B AL
- JZ esd12
- MOV dislin,AL ;set: redisplay from
- esd12 MOV BX,disbeg ;display beg
- CALL elindn ;go down one line
- MOV disbeg,BX ;-> new display beg
- CALL escrolup ;scroll up
- CS:
- MOV AL,txwiny2 ;line cnt - 1
- DEC.B AL
- JMP edsplin ;"redisplay one line
- etstsep MOV SI,sepptr ;Char = separator ?
- etslp CS: ;get ptr to table
- MOV.B AL,[SI] ;get char from table
- OR.B AL,AL ;table end ?
- JZ etsno ;:yes
- CMP.B AL,[BX] ;= text char ?
- JZ etsyes ;:yes
- INC SI ;try next char
- JMP etslp ;'
- etsyes STC ;found it !
- etsno MOV DX,SI ;DX=pos in table
- RET ;"
- LAHF ;redisplay current line
- PUSH AX ;save
- MOV AL,phrow ;phys row
- CMP.B AL,dislin ;>= redisplay from ?
- JNB erc2 ;:ok
- MOV dislin,AL ;redisplay current line, too !
- erc2 POP AX ;restore
- SAHF
- RET ;"
- eredall MOV.B dislin,#$01 ;set flag: redisplay all
- RET ;"
- eblkupdt XCHG BX,DX ;Update blocks
- TEST.B attflg,#$01 ;block beg in this line ?
- JZ ebunobk ;:no
- MOV BX,bkbegl ;pos block in buffer
- CMP BX,DX ;< BX ?
- JB ebunobk ;:ok
- ADD BX,CX ;add count
- MOV bkbegl,BX ;-> update
- ebunobk TEST.B attflg,#$02 ;block end in this line ?
- JZ ebunochg ;:no
- MOV BX,bkendl ;pos block end in buffer
- CMP BX,DX ;< BX ?
- JB ebunochg ;:ok
- ADD BX,CX ;add count
- MOV bkendl,BX ;-> update
- ebunochg XCHG BX,DX ;restore BX
- RET ;"
- edelch PUSH BX ;delete char: save pos
- MOV CX,#$FFFF ;1 char back
- CALL eblkupdt ;update blocks
- XCHG BX,DX ;pos -> DX
- MOV BX,#lineend1 ;buffer end
- SUB BX,DX ;calculate count
- JZ edelcnil ;:nothing to move
- MOV CX,BX ;count -> CX
- MOV BX,DX ;pos -> BX
- INC BX ;source: +1
- CALL movebk ;move it
- edelcnil MOV BX,#lineend1 ;store a space at the end
- MOV.B [BX],#$20
- POP BX ;restore pos
- RET ;"
- emin CMP BX,DX ;min(BX,DX) -> BX
- JB emin2 ;max(BX,DX) -> DX
- XCHG BX,DX
- emin2 RET ;"
- eredlin CALL eposcur ;redisplay line: set cursor pos
- CS:
- MOV AL,txwinx2 ;col cnt - 1
- DEC.B AL
- SUB.B AL,phcol ;- phys col
- MOV BX,lnpos ;pos in line buffer
- MOV.B attchg,#$FF ;attribute change in this line
- CALL escrdma2 ;redisplay this line
- MOV.B attchg,#$00 ;clear attribute flag
- RET ;"
- elindn MOV BP,CX ;go down one line
- MOV CX,txend ;text end
- MOV DI,BX ;current pos
- SUB CX,DI ;text end-pos -> count
- JBE eld2 ;:too much
- MOV AX,DS ;DS -> ES
- MOV ES,AX
- CLD ;search LF
- MOV AL,#$0A
- REPNZ
- SCAS.B
- JNZ eld2 ;:not found
- MOV CX,BP ;restore CX
- MOV BX,DI ;pos of line break
- RET ;'
- eld2 MOV CX,BP ;restore CX
- STC ;flag: not done
- RET ;"
- elinup MOV BP,BX ;go up one line
- MOV AL,#$0A ;search LF
- MOV DI,txbeg ;text beg = limit
- DEC BX ;go back one char
- elulp DEC BX ;go back
- CMP BX,DI ;= end ?
- JBE eluend ;:yes
- CMP.B [BX],AL ;LF ?
- JNZ elulp ;:no, try again
- INC BX ;go to beg of line
- eluend JB eluerr ;:not found
- RET ;'
- eluerr MOV BX,BP ;restore pos
- RET ;"
- einsch PUSH BX ;insert char in line
- MOV CX,#$0001 ;1 char
- CALL eblkupdt ;update blocks
- MOV DX,#lineend1 ;buffer end
- XCHG BX,DX ;calc count
- SUB BX,DX
- DEC BX
- MOV CX,BX
- MOV DX,#lineend0 ;buffer end
- MOV BX,DX
- DEC BX
- MOV.B AL,CL ;test length
- OR.B AL,CH ;did they translate this automatically
- JZ einscnil ;from Z80-code ??!!
- PUSH DX ;save pos
- CALL movebkb ;insert
- POP BX ;restore pos
- MOV.B [BX],#$20 ;store a space
- einscnil POP BX ;restore pos
- RET ;"
- ewritpos CALL esetcur ;Write string + pos cursor
- ewrits CALL klowvid ;LowVideo
- JMP prints ;"write string
- ewriterr CALL vidattr3 ;Attribute #3
- JMP prints ;"write string: error message
- ewritch CMP.B disflg,#$FF ;editing status
- JNZ ewritret ;:ret
- JMP conput ;"write it
- ekbdstat PUSH AX ;Get KBD stat
- PUSH BX
- PUSH CX
- PUSH DX
- DEC SP
- CALL [vkbdstat] ;do it
- POP DX
- POP CX
- POP BX
- POP AX
- ewritret RET ;"
- esetcur CMP.B disflg,#$00 ;set cursor pos
- JZ escrt
- MOV.B scrrow,BL ;line
- XCHG BX,DX
- CALL setcpos ;set it
- XCHG BX,DX ;restore
- escrt RET ;"
- ;first command table (installed with TINST)
- ecmd1 B $01,$0D,$02,$1B,$4B,$01,$FF,$02,$1B,$4D,$02,$1B,$73,$02
- B $1B,$74,$02,$1B,$48,$02,$1B,$50,$01,$FF,$01,$FF,$02,$1B
- B $49,$02,$1B,$51,$02,$1B,$47,$02,$1B,$4F,$02,$1B,$77,$02
- B $1B,$75,$02,$1B,$84,$02,$1B,$76,$01,$FF,$01,$FF,$01,$FF
- B $02,$1B,$52,$01,$FF,$01,$FF,$01,$FF,$01,$FF,$02,$1B,$53
- B $01,$08,$01,$FF,$02,$1B,$41,$02,$1B,$42,$01,$FF,$01,$FF
- B $01,$FF,$01,$FF,$01,$FF,$01,$FF,$01,$FF,$01,$FF,$01,$FF
- B $01,$FF,$01,$FF,$01,$FF,$01,$FF,$01,$FF,$01,$FF,$00,$00
- B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
- B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
- B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
- B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
- B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
- B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
- B $00,$00,$00,$00 ;"
- ;second command line (preinstalled)
- ecmd2 B $01,$0D,$01,$13,$01,$08,$01,$04,$01,$01,$01,$06,$01,$05
- B $01,$18,$01,$17,$01,$1A,$01,$12,$01,$03,$02,$11,$13,$02
- B $11,$04,$02,$11,$05,$02,$11,$18,$02,$11,$12,$02,$11,$03
- B $02,$11,$02,$02,$11,$0B,$02,$11,$10,$01,$16,$01,$0E,$01
- B $19,$02,$11,$19,$01,$14,$01,$07,$01,$7F,$01,$FF,$02,$0B
- B $02,$02,$0B,$0B,$02,$0B,$14,$02,$0B,$08,$02,$0B,$03,$02
- B $0B,$16,$02,$0B,$19,$02,$0B,$12,$02,$0B,$17,$02,$0B,$04
- B $01,$09,$02,$11,$09,$02,$11,$0C,$02,$11,$06,$02,$11,$01
- B $01,$0C,$01,$10,$00 ;"
- eseptab B "<>,[].*+-/$:=(){}^#\'"
- esepspc B " ",$00 ;"
- ;Jump table for editor commands
- ;Labels ending with 2 have the MSB set. On these commands
- ;the text is marked as changed. The commands are in the order
- ;given in the chapter "Editing Command Installation" of the
- ;Turbo manual.
- ejmptab W ecr,eleft,eleft,eright,ewrdlft,ewrdrt,eup,edn,escrup,escrdn
- W epagup,epagdn,ejlnbeg,ejlnend,epagtop,epagbot,etxtbeg
- W ejtxend,ejbkbeg,ejbkend,elstpos,etogovr,elinins2,edellin2
- W edeleol2,edelwrd2,edelrt2,edellft2,edellft2,emarkbeg,emarkend
- W emrkwrd,ekh,eblkcpy2,eblkmov2,eblkdel2,eblkrd2,ekw,ekd
- W etab2,etogind,erstlin2,efind,ereplace,erepeat,eprefix2 ;"
- ;*** Compiler ***
- turbo MOV spsav,SP ;save stack pointer
- CMP.B cpmode,#$02 ;to COM or CHN ?
- JB turmem ;:no
- CMP.B txcomp,#$00 ;is it already compiled ?
- JZ turmem ;:no
- CMP.B cdinval,#$00 ;is it invalid ?
- JNZ turmem ;:yes
- CALL opendest ;open dest file
- CALL cvmemdsk ;change to disk code
- JMP.b turret ;'no error
- turmem CALL inittur ;init variables
- CMP.B cpmode,#$00 ;to memory ?
- JNZ turfil ;:no
- CALL copyrt ;make space, copy run-time lib
- JMP.b turmem2 ;'
- turfil CMP.B cpmode,#$02 ;COM / CHN ?
- JB turmem2 ;:no
- CALL opendest ;open dest file
- turmem2 CALL compile ;compile program
|