| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600 |
- SUB CX,SI ;calc length
- kdpad MOV AL,#$20 ;pad with spaces
- CALL conput ;write space
- LOOP kdpad ;:another one
- JMP.b kdnext ;'next dir entry
- kdnextln CALL xwriteln ;WriteLn
- kdnext MOV AH,#$4F ;get next entry
- PUSH DX ;save tab
- CALL dos ;get it
- POP DX ;restore tab
- JNB kddis ;:ok, write it
- OR.B DL,DL ;(redundant !)
- JMP.b kdend ;'end it
- kderr CALL xwriteln ;WriteLn
- CALL vidattr2
- CALL prints
- B "No files",$00
- CALL knrmvid
- MOV DL,#$01 ;do CR
- kdend OR.B DL,DL ;test tab flag
- JZ kdend2 ;:no CR
- CALL xwriteln ;WriteLn
- kdend2 CALL xwriteln ;WriteLn
- MOV.B DL,scrpn ;get drive number
- SUB.B DL,#$40 ;convert
- MOV AH,#$36 ;get disk free space
- CALL dos
- CMP AX,#$FFFF ;invalid drive ?
- JZ kdret ;:yes
- MUL CX ;calc bytes/block
- OR DX,DX ;many ?
- JNZ kdret ;:yes
- MUL BX ;* number free blocks
- MOV CL,#$0A ;DIV 1024
- SHR AX,CL
- MOV CL,#$06
- SHL DX,CL
- ADD AX,DX
- CALL knum1 ;write number
- CALL prints
- B "k bytes free",$00
- kdret RET ;"
- klogged CALL prints ;L:Logged drive
- B "New drive",$00
- CALL kreadln ;Read line
- MOV.B AL,[BX] ;get char from buffer
- CMP AL,#$1A ;EOF ?
- JNZ kldef ;:no
- MOV AH,#$19 ;get default drive
- CALL dos
- JMP.b kldef2 ;'ok
- kldef CALL upcase ;convert it
- SUB AL,#$41 ;< A ?
- JB klret ;:wrong
- CMP AL,#$0F ;> O ?
- JA klret ;:wrong
- kldef2 PUSH AX ;save it
- MOV AH,#$0D ;reset disk system
- CALL dos
- POP DX ;restore drive
- MOV AH,#$0E ;set default drive
- CALL dos
- klret RET ;"
- kactdir CALL prints ;A:Active directory
- B "New directory",$00
- CALL kreadln ;read string
- JZ karet ;nothing: ret
- MOV SI,BX ;source
- MOV DX,#pnbuf ;dest: std pathname
- MOV DI,DX
- MOV CX,#$0040 ;64 bytes
- PUSH DS ;DS -> ES
- POP ES
- CLD ;copy it
- REPZ
- MOVS.B
- MOV DI,DX ;restore ptr to beg
- MOV AL,#$1A ;search ^Z
- MOV CX,#$0040
- REPNZ
- SCAS.B
- JNZ kaerr ;not found: invalid
- MOV.B [DI]-$01,#$00 ;mark end with 0
- MOV AH,#$3B ;change directory
- CALL dos
- OR.B AL,AL ;error ?
- JZ karet ;:no
- kaerr MOV AL,#$07 ;Bell
- CALL conput ;write it
- karet RET ;"
- kspace CALL prints ;Display space information
- B "Code: ",$00
- MOV BX,#$2D8B ;(code size-runtime length)/16
- MOV CL,#$04
- SHR BX,CL
- MOV AX,codesize ;(already in paras)
- SUB AX,BX
- AND AX,#$0FFF
- CALL ksize ;write number
- CALL prints
- B ", ",$00
- MOV AX,#$1000 ;(64K-code size)/16
- SUB AX,codesize
- AND AX,#$0FFF
- CALL kpara ;write para
- CALL prints
- B " free",$0D,$0A,"Data: ",$00
- MOV BX,#$024F ;(Data size-std vars)/16
- MOV CL,#$04
- SHR BX,CL
- MOV AX,datasize ;(already paras)
- SUB AX,BX
- AND AX,#$0FFF
- CALL ksize ;write number
- CALL prints
- B ", ",$00
- MOV AX,#$1000 ;(64K-data size)/16
- SUB AX,datasize
- AND AX,#$0FFF
- CALL kpara ;write para
- CALL prints
- B " free",$0D,$0A,$00
- CMP.B codedest,#$01 ;code destination ?
- JZ kspmem ;:memory
- CMP.B codedest,#$02
- JZ kspcom ;:COM-File
- RET ;'
- kspmem CALL prints
- B "Stack/Heap: ",$00
- MOV AX,minstksz ;display min stack size
- CALL ksize ;write number
- JMP xwriteln ;'WriteLn
- kspcom CALL prints
- B "Stack/Heap: ",$00
- MOV AX,minhpsz ;min heap/stack size
- CALL ksize ;write number
- CALL prints
- B " (minimum)",$0D,$0A," ",$00
- MOV AX,maxhpsz ;max heap/stack size
- CALL ksize ;write number
- CALL prints
- B " (maximum)",$0D,$0A,$00
- RET ;"
- ksize PUSH AX ;write number hex and dec
- CALL kpara ;write para
- CALL prints
- B " (",$00
- POP AX ;restore number
- XOR DX,DX ;clear hi
- MOV CX,#$0004
- ksize2 SHL AX,1 ;* 16
- RCL DX,1
- LOOP ksize2 ;:another shift
- MOV BX,AX ;number
- MOV CX,#$0006 ;field length
- CALL knum ;write DX:BX
- CALL prints
- B " bytes)",$00
- RET ;"
- kpara CALL whexword ;Write para: hex number
- kparastr CALL prints
- B " paragraphs",$00
- RET ;"
- CALL kpara ;WriteLn para
- JMP xwriteln ;"
- krdhex XOR AX,AX ;Read hex
- krxlp PUSH AX ;save number
- MOV.B AL,[BX] ;get char
- CALL upcase ;UpCase
- MOV.B CH,AL ;-> CH
- POP AX ;restore number
- SUB.B CH,#$30 ;ASCII-translation
- JB krxend ;:< 0 - end
- CMP.B CH,#$0A ;> 9 ?
- JB krxok ;no: ok
- SUB.B CH,#$07 ;A..F
- CMP.B CH,#$0A ;< A ?
- JB krxend ;yes: end
- CMP.B CH,#$10 ;> F ?
- JNB krxend ;yes: end
- krxok MOV CL,#$04 ;number * 16
- SHL AX,CL
- OR.B AL,CH ;add digit
- INC BX ;next char
- JMP krxlp ;'continue
- krxend RET ;"
- kfind CALL prints ;F:Find Error
- B "Enter PC",$00
- CALL kreadln ;ReadLn
- JNZ kfind2 ;:ok
- RET ;'nothing entered
- kfind2 CALL krdhex ;read hex
- MOV errpos2,AX ;store error position
- CALL knocode ;set flag: not compiled
- kdofind CALL kgetfile ;get file, if necessary
- MOV.B cpmode,#$01 ;set flag: searching
- CALL prints
- B $0D,$0A,"Searching",$00
- JMP.b kcnofile ;"do it...
- kcomp CALL kgetfile ;C:Compile - get file
- CALL kdestfil ;set dest file
- CALL prints
- B $0D,$0A,"Compiling",$00
- CMP.B cpmode,#$00 ;to memory ?
- JZ kcnofile ;:yes
- CALL prints
- B " --> ",$00
- MOV SI,#scrpn ;display dest path name
- CALL printpn
- kcnofile CALL xwriteln ;WriteLn
- CALL turbo ;Call compiler
- CMP.B cpmode,#$02 ;COM/CHN produced ?
- JB kcnoerr ;:no
- CMP.B cperr,#$00 ;error ?
- JZ kcnoerr ;:no
- CALL kdestfil ;set dest file
- MOV AH,#$41 ;delete it
- MOV DX,#destpn
- CALL dos
- kcnoerr CMP.B cperr,#$CA ;Compilation aborted ?
- JNZ kcnoabrt ;:no
- CALL xwriteln ;WriteLn
- CALL xwriteln ;WriteLn
- CALL vidattr2
- CALL prints
- B "Compilation aborted",$00
- JMP kmainlp ;'return to main menu
- kcnoabrt CALL prints
- B " lines",$0D,$0A,$0A,$00
- CMP.B cperr,#$00 ;error ?
- JNZ kctest ;:yes
- CMP.B cpmode,#$01 ;find error pos ?
- JZ kcnotfnd ;:yes
- CALL kspace ;display space info
- RET ;'
- kcnotfnd CALL vidattr3 ;error pos not found
- CALL prints
- B "Run-time error position not found",$00
- CALL knrmvid
- JMP.b kwlnret ;'return to main
- kctest CMP.B cperr,#$C9 ;I/O-error ?
- JNZ kcfound ;:no
- CALL ksfull ;write message
- kwlnret CALL xwriteln ;WriteLn
- JMP kmainlp ;'return to main menu
- kcfound CMP.B cperr,#$C8 ;Error pos found ?
- JNZ kcerror ;:no
- CALL prints
- B "Run-time error position found",$00
- JMP kcwend ;'jump to this position
- kcerror CALL vidattr3 ;Error message
- CALL prints
- B "Error ",$00
- XOR AX,AX ;get error number
- MOV AL,cperr
- CALL knum1 ;write it
- TEST.B msgflg,#$FF ;error msgs included ?
- JZ kcwend ;:no
- MOV BX,#txstrt ;pointer to messages
- kcmsr MOV.B AL,[BX] ;get char
- CMP AL,#$1A ;^Z ?
- JZ kcwend ;yes: not found
- CMP AL,#$20 ;control char ?
- JB kcmsr2 ;:yes
- SUB AL,#$30 ;get digit
- MOV.B AH,AL ;* 10
- ADD.B AL,AL
- ADD.B AL,AL
- ADD.B AL,AH
- ADD.B AL,AL
- INC BX
- ADD.B AL,[BX] ;get second digit
- SUB AL,#$30 ;convert
- INC BX ;next char
- CMP.B AL,cperr ;= error number ?
- JZ kcwmsg ;:yes
- kcmsr2 MOV.B AL,[BX] ;get char
- INC BX ;next one
- CMP AL,#$0D ;end of line ?
- JNZ kcmsr2 ;no: search it
- INC BX ;next char: skip LF
- JMP kcmsr ;'continue searching
- kcwmsg CALL prints ;Display error message
- B ": ",$00
- kcwlp MOV.B AL,[BX] ;get char
- CMP AL,#$0D ;CR ?
- JZ kcwend ;yes: done
- CMP AL,#$20 ;control char ?
- JNB kcwchar ;:no - write it
- CMP AL,#$1A ;^Z ?
- JZ kcwend ;yes: done
- MOV SI,#txstrt ;pointer to messages
- kcsubsr MOV.B AL,[SI] ;get char
- INC SI ;go to next
- CMP AL,#$20 ;control char ?
- JNB kcwsub ;no: search end of line
- CMP.B AL,[BX] ;is it the right one ?
- JNZ kcwsub ;:no, next line
- kcsubsr2 MOV.B AL,[SI] ;get char - write sub-message
- CMP AL,#$0D ;CR ?
- JZ kcwnext ;:end
- CALL conput ;write it
- INC SI ;next one
- JMP kcsubsr2 ;'continue
- kcwsub MOV.B AL,[SI] ;search end of line
- INC SI ;next char
- CMP AL,#$0D ;CR ?
- JNZ kcwsub ;:no
- INC SI ;skip LF
- JMP kcsubsr ;'continue searching
- kcwchar CALL conput ;display char
- kcwnext INC BX ;go to next
- JMP kcwlp ;'continue
- kcwend MOV.B mainflg,#$00 ;work file used
- CMP.B inclflg,#$00 ;error in include file ?
- JZ kcnoincl ;:no
- MOV AL,#$2E
- CALL conput ;write char
- CALL knrmvid
- CALL ksvnoask
- MOV SI,#inclpn ;copy include file name
- MOV DI,#workpn ;into work file name
- CALL fncopy ;do it
- CALL kwload ;load that file
- CALL xwriteln ;WriteLn
- CALL vidattr3
- CALL prints
- B "Error found in above include file",$00
- JMP.b kcwait ;'go into editor
- kcnoincl CMP.B mainpn,#$00 ;main file exists ?
- JZ kcwait ;:no
- MOV SI,#mainpn ;copy main into
- MOV DI,#workpn ;work file name
- CALL fncopy ;do it
- kcwait CALL waitesc ;wait for ESC
- MOV BX,txerrpos ;get error pos in text
- DEC BX
- JMP editor2 ;"jump into editor
- kmem MOV.B codedest,#$01 ;M:memory
- RET ;"set flag
- kcom MOV.B codedest,#$02 ;C:COM file
- RET ;"set flag
- kchn MOV.B codedest,#$03 ;H:CHN file
- RET ;"set flag
- kcs CALL prints ;O:CS size
- B "Minimum Code Segment size",$00
- CALL kreadln ;read it
- MOV AX,#$0000 ;default
- JZ kcsdef ;:nothing entered
- CALL krdhex ;read hex
- MOV BX,#$2D8B ;add runtime size
- MOV CL,#$04 ;convert to paras
- SHR BX,CL
- ADD AX,BX
- kcsdef MOV mincssz,AX ;store min CS
- RET ;"
- kds CALL prints ;D:DS size
- B "Minimum Data Segment size",$00
- CALL kreadln ;read it
- MOV AX,#$0000 ;default
- JZ kdsdef ;nothing entered: set it
- CALL krdhex ;read hex
- MOV BX,#$024F ;add std vars size
- MOV CL,#$04
- SHR BX,CL ;convert to paras
- ADD AX,BX
- kdsdef MOV mindssz,AX ;store min DS
- RET ;"
- kss CALL prints ;S:SS size
- B "Minimum Stack Segment size",$00
- CALL kreadln ;read it
- MOV AX,#$0400 ;default: 16K
- JZ kssdef ;nothing entered: set it
- CALL krdhex ;read hex
- kssdef MOV minhpsz,AX ;store min SS
- RET ;"
- kmss CALL prints ;A:Max. SS size
- B "Maximum Stack Segment size",$00
- CALL kreadln ;read it
- MOV AX,#$A000 ;default: 640K
- JZ kmssdef ;nothing entered: set it
- CALL krdhex ;read hex
- kmssdef MOV maxhpsz,AX ;store max SS
- RET ;"
- kparm CALL prints ;P:Parameter line
- B "Parameters",$00
- MOV SI,#parmlin ;ptr to buffer
- CALL kreaddef ;Read line with default
- MOV DI,#parmlin ;copy it
- MOV CX,#$003B ;count
- kparml MOV.B AL,[BX] ;get char
- CMP AL,#$1A ;^Z ?
- JZ kparme ;yes: end
- MOV.B [DI],AL ;store in buffer
- INC BX ;next char
- INC DI
- LOOP kparml ;:another char
- kparme MOV.B [DI],#$00 ;mark end of param line
- RET ;"
- kgetfile CMP.B workpn,#$00 ;load file, if necessary
- JNZ kget1 ;:work file defined
- CALL kgetfn ;get work file name
- kget1 CMP.B mainpn,#$00 ;main file ?
- kget2 MOV SI,#workpn
- JNZ kget3 ;:work file exists
- CALL kgetfn ;copy work -> main file name
- MOV AL,#$00 ;use work file
- JMP.b kget4 ;'
- kget3 CALL kcmpfn ;work = main ?
- JZ kget2 ;:yes
- CALL ksvnoask ;save without question
- MOV vfilbig,#flbigclr ;set error vectors
- MOV vnewfil,#flescclr
- MOV SI,#mainpn ;main file
- CALL kwload2 ;load it
- MOV AL,#$FF ;set flag: main file
- kget4 MOV mainflg,AL ;store flag
- MOV.B errio,#$00 ;clear error flag
- RET ;"
- kdestfil MOV SI,#mainpn ;Set dest file name
- CMP.B [SI],#$00 ;main file name ok ?
- JNZ kdsmain ;not null - ok
- MOV SI,#workpn ;use work file name
- kdsmain CALL fnsisc ;copy to scratch file name
- MOV SI,#extcom ;set extension .COM
- MOV AL,codedest
- MOV.B cpmode,#$00 ;set flag: memory
- DEC.B AL ;memory ?
- JZ kdsmem ;:yes
- MOV.B cpmode,#$02 ;flag: file
- DEC.B AL ;COM ?
- JZ kdsmem ;:yes
- MOV.B cpmode,#$03 ;flag: CHN
- MOV SI,#extchn ;set extension .CHN
- kdsmem CALL kext ;modify file name
- MOV DI,#destpn ;-> dest file name
- CALL fnscdi ;copy it
- RET ;"
- krun CMP.B txcomp,#$00 ;R:Run
- JNZ krok ;:already compiled
- CALL kcomp ;compile it
- krok CMP.B codedest,#$01 ;memory: ok
- JZ krmem ;yes: do it
- CMP.B codedest,#$02 ;COM-file ?
- JNZ krchn
- CALL xwriteln ;WriteLn
- CALL vidattr2
- CALL prints
- B "Please Quit TURBO to run .COM file",$00
- krchn JMP kmainlp ;'return to menu
- krmem MOV SI,#parmlin ;copy command line
- MOV DI,#paramlin ;to start of CS
- MOV ES,destseg ;seg of compiled program
- XOR BX,BX ;clear offset
- krparml MOV.B AL,[SI] ;get char
- CMP AL,#$00 ;end ?
- JZ krparme ;:yes
- INC SI ;next char
- INC BX
- ES:
- MOV.B [BX_DI],AL ;store that char
- JMP krparml ;'continue
- krparme ES:
- MOV.B [BX_DI]$01,#$0D ;store CR at the end
- ES:
- MOV.B [DI],BL ;store length
- CALL prints
- B $0D,$0A,"Running",$0D,$0A,$00
- PUSH destseg ;CS of program
- MOV AX,#$0100 ;start of program
- PUSH AX
- RETF ;'start program
- turboret ES: ;return point from program
- MOV AL,errio ;error ?
- MOV errio,AL
- ES:
- MOV AX,errpos2 ;get error position
- MOV errpos2,AX
- MOV AX,#$FFFF ;flag
- JMP kmeminit ;"reinit
- kclrtxt MOV BX,txbeg ;Clear text
- MOV txend,BX ;text beg -> text end
- MOV.B txchg,#$00 ;text not changed
- MOV.B mainflg,#$00 ;work file
- knocode MOV.B txcomp,#$00 ;text not compiled
- RET ;"
- kquit CALL ksvchng ;Q:Quit - save changes
- CALL xcrtexit ;CrtExit
- MOV AH,#$4C ;end of process
- JMP dos ;"return to MS-DOS
- kgetfn CMP.B workpn,#$00 ;Get current file name
- JNZ kgf2 ;:work file
- CMP.B mainpn,#$00 ;main file ?
- JNZ kgfmain ;:yes
- CALL kwork ;set work file name
- JMP.b kgf2 ;'
- kgfmain MOV SI,#mainpn ;main -> work file name
- MOV DI,#workpn
- CALL fncopy
- MOV.B mainflg,#$FF ;flag: main file
- CALL kgetfn ;get filename
- kgf2 CMP.B mainflg,#$00 ;main file ?
- JZ kgfret ;:no
- CALL ksvnoask ;save without question
- CALL kwload ;load that file
- kgfret RET ;"
- kcmpfn MOV SI,#workpn ;main = work file ?
- MOV DI,#mainpn
- kcmpl MOV.B AL,[SI] ;get char
- CMP.B AL,[DI] ;compare it
- JNZ kcmpnoeq ;:not equal
- OR.B AL,AL ;end ?
- JZ kcmpret ;:yes
- INC SI ;next char
- INC DI
- JMP kcmpl ;'continue
- kcmpnoeq MOV AL,#$01 ;set flag: false
- kcmpret RET ;"
- kreaderr MOV AX,#txstrt ;Read error message file
- MOV txbeg,AX ;set text beg
- MOV vnewfil,#flesc ;set error vectors
- MOV vfilbig,#flbig
- MOV SI,#errpath ;ptr to pathname
- MOV DI,#scrpn ;scratch pathname
- PUSH DI ;save ptr
- PUSH DS ;DS -> ES
- POP ES
- PUSH CS ;CS -> DS
- POP DS
- CALL fncopy1 ;copy filename
- PUSH ES ;ES -> DS
- POP DS
- POP SI ;restore ptr
- CALL kwload2 ;load file
- MOV BX,txend ;store its end position
- MOV.B [BX],#$1A ;store ^Z at the end
- INC BX ;next char
- MOV txbeg,BX ;-> new text beg
- RET ;"
- kwstrsi PUSH BX ;write string [SI]
- MOV BX,#prpnret ;no change
- JMP.b prpn2 ;'
- printpn PUSH BX ;write pathname: save BX
- MOV BX,#upcase ;vector: UpCase
- prpn2 CLD
- LODS.B ;get char
- OR.B AL,AL ;end ?
- JZ prpne ;:no
- CALL BX ;modify char
- CALL conput ;write it
- JMP prpn2 ;'continue
- prpne POP BX ;restore
- prpnret RET ;"
- knum1 XOR CX,CX ;write number - unformatted
- CALL knum2 ;do it
- RET ;"
- knumax MOV CX,#$0005 ;write number - 5 digits
- XOR DX,DX ;clear hi word
- JMP.b knum2 ;'
- knum2 XOR DX,DX ;write number DX:BX
- knum PUSH SI ;save regs
- PUSH DI
- PUSH ES
- PUSH DS ;DS -> ES
- POP ES
- PUSH CS ;CS -> DS
- POP DS
- MOV DI,#knumbuf ;dest buffer
- MOV BX,AX ;number to write
- PUSH CX ;save field size
- CLD
- XOR CX,CX ;format flag (leading zeroes)
- MOV SI,#kndectab ;ptr decimal table
- MOV AH,#$07 ;7 digits
- kndig XOR.B AL,AL ;clear digit
- kndiglp INC.B AL ;count up
- SUB BX,[SI] ;do successive subtraction
- SBB DX,[SI]$02
- JNB kndiglp ;:continue
- ADD BX,[SI] ;restore number
- ADC DX,[SI]$02
- ADD SI,#$04 ;next table entry
- DEC.B AL ;restore digit
- JNZ knnot0 ;:not zero
- OR CX,CX ;test flag
- JZ knnoput
- knnot0 ADD AL,#$30 ;convert to ASCII
- STOS.B ;store in dest buffer
- INC CX ;set flag
- knnoput DEC.B AH ;another digit ?
- JNZ kndig ;:yes
- OR CX,CX ;digits done ?
- JNZ knnot00 ;:yes
- MOV AL,#$30 ;put a 0
- STOS.B
- INC CX ;digit count
- knnot00 XOR AX,AX ;write a zero at the end
- STOS.B
- POP AX ;restore field size
- PUSH ES ;ES -> DS
- POP DS
- SUB AX,CX ;fill up with spaces ?
- JBE knnopad ;:no
- INC CX ;space count
- DEC DI
- MOV SI,DI ;make space in buffer
- ADD DI,AX
- STD
- REPZ ;move it up
- MOVS.B
- MOV CX,AX ;now fill with spaces
- MOV AL,#$20
- REPZ
- STOS.B
- knnopad MOV SI,#knumbuf ;buffer ptr
- CALL kwstrsi ;write string
- POP ES ;restore regs
- POP DI
- POP SI
- RET ;"
- kndectab W $4240,$000F ;1000000 decimal table
- W $86A0,$0001 ; 100000
- W $2710,$0000 ; 10000
- W $03E8,$0000 ; 1000
- W $0064,$0000 ; 100
- W $000A,$0000 ; 10
- W $0001,$0000 ;" 1
- kparse MOV CX,#$000F ;parse filename: no wildcards allowed
- kparse2 MOV DI,#scrpn ;dest: scratch file name
- MOV AX,[BX] ;get 2 chars: drive spec
- CALL upcase ;UpCase
- CMP AL,#$20 ;control char ?
- JB kpdefdrv ;:yes
- CMP.B AH,#$3A ;: ?
- JNZ kpdefdrv ;:no
- INC BX ;next char
- INC BX
- JMP.b kpdrv ;'set drive
- kpdefdrv MOV AH,#$19 ;get default drive
- CALL dos
- ADD AL,#$41 ;-> ASCII
- MOV AH,#$3A
- kpdrv MOV [DI],AX ;store drive spec
- INC DI
- INC DI
- OR.B CH,CH ;test path ?
- JNZ kpendpn2 ;:no
- CMP.B [BX],#$5C ;\ ?
- JZ kpendpn2 ;:yes
- MOV.B [DI],#$5C ;store \
- INC DI
- MOV AH,#$47 ;get current path
- MOV.B DL,AL ;drive number
- SUB.B DL,#$40
- MOV SI,DI ;destination
- CALL dos ;do it
- JB kpendpn2 ;:error
- CMP.B [DI],#$00 ;search end of path
- JZ kpendpn2 ;:found
- kpendsr MOV.B AL,[DI] ;get char
- OR.B AL,AL ;end ?
- JZ kpendpn ;:found
- INC DI ;next char
- CMP DI,#scrpnend ;end of buffer ?
- JB kpendsr ;:not yet
- JMP.b kpend ;'end it
- kpendpn MOV.B [DI],#$5C ;store \
- INC DI ;next char
- CMP DI,#scrpnend ;end of buffer ?
- ;:yes
- JZ kpend
- kpendpn2 XOR.B CH,CH ;clear flag
- PUSH CS ;CS -> ES
- POP ES
- CLD
- kpchklp MOV.B AL,[BX] ;get char
- CMP AL,#$20 ;control / space ?
- JBE kpend ;:yes
- PUSH CX ;save cnt, dest ptr
- PUSH DI
- MOV DI,#kpinval ;test: illegal char ?
- REPNZ ;CL is count for this search
- SCAS.B ;search char in table
- POP DI ;restore
- POP CX
- JZ kpend ;found: end it
- INC BX ;next char
- MOV.B [DI],AL ;store it
- INC DI ;next char in dest
- CMP DI,#scrpnend ;end of buffer ?
- JB kpchklp ;:no
- kpend MOV.B [DI],#$00 ;mark end
- RET ;"
- kpinval B $22,"+,/;<=>[]{|}*?" ;"table of illegal chars
- kpasext MOV SI,#extpas ;pointer: .PAS
- kextdef PUSH SI ;save extension ptr
- CALL kparse ;parse filename
- POP SI ;restore ext ptr
- MOV DL,#$01 ;only set if no ext
- JMP.b kx1 ;'do it
- kext2 MOV DL,#$02
- JMP.b kx1 ;'
- kext XOR.B DL,DL ;set file extension
- kx1 MOV DI,#insline2 ;ptr scratch file name
- XOR CX,CX ;clr dot pos
- kxsrdot MOV.B AL,[DI] ;get char
- OR.B AL,AL ;end ?
- JZ kxend ;:yes
- INC DI ;next one
- CMP.B DL,#$02 ;search dot ?
- JZ kxsrdot ;:no
- CMP AL,#$2E
- JNZ kxnodot ;:no
- MOV CX,DI ;store pos of dot
- kxnodot CMP AL,#$5C ;\ ?
- JNZ kxsrdot ;:no
- XOR CX,CX ;clear dot pos
- JMP kxsrdot ;'continue
- kxend OR CX,CX ;test dot pos
- JZ kxnodotf ;:not set
- OR.B DL,DL ;set extension ?
- JNZ kxret ;:no
- MOV DI,CX ;dot position
- DEC DI ;go back
- kxnodotf CS: ;set extension
- MOV.B CL,[SI] ;length of extension
- XOR.B CH,CH ;-> count
- JCXZ kxexte ;:nothing to do
- kxextl CMP DI,#scrpnend ;buffer end ?
- JZ kxexte ;:yes
- INC SI ;next pos
- CS:
- MOV.B AL,[SI] ;get ext char
- MOV.B [DI],AL ;store it
- INC DI ;next one
- LOOP kxextl ;:another char
- kxexte MOV.B [DI],#$00 ;mark end
- kxret RET ;"
- fnscdi MOV SI,#scrpn ;copy scratch -> [DI]
- JMP.b fncopy ;'
- fnsisc MOV DI,#scrpn ;copy [SI] -> scratch
- fncopy PUSH DS ;DS -> ES
- POP ES
- fncopy1 MOV CX,#$0020 ;copy 64 bytes
- CLD
- REPZ
- MOVS ;do it
- RET ;"
- kwscrpn MOV SI,#scrpn ;write scratch file name
- JMP printpn ;"
- kwworkpn MOV SI,#workpn ;write work file name
- JMP printpn ;"
- kdworkfn MOV SI,#workpn ;Display work file name
- PUSH DS ;DS -> ES
- POP ES
- CLD
- LODS.B ;get char
- CALL upcase ;UpCase
- CALL conput ;write it (drive)
- LODS.B ;get char
- CALL conput ;write it (:)
- MOV DI,SI ;search end of filename
- XOR.B AL,AL
- MOV CX,#$FFFF ;any length
- CLD
- REPNZ
- SCAS.B ;search it
- STD ;backward search !
- MOV AL,#$5C ;now search \
- MOV CX,#$FFFF ;any length
- DEC DI
- REPNZ
- SCAS.B ;do it
- MOV SI,DI ;position of file name
- INC SI ;without dir path
- INC SI
- JMP printpn ;"write it
- printatt PUSH BP ;Print string with highlighting
- MOV BP,SP ;string: inline, 0=end
- XCHG BX,[BP]$02 ;get return addr
- PUSH AX ;save
- PUSHF
- pralp CS: ;get char
- MOV.B AL,[BX]
- INC BX ;go to next
- OR.B AL,AL ;end ?
- JZ praend ;:yes
- CMP AL,#$80 ;highlighted ?
- JNB prahi ;:yes
- CALL klowvid ;LowVideo
- JMP.b pralo ;'write it
- prahi CALL knrmvid ;NormVideo
- AND AL,#$7F ;mask out bit 7
- JZ pralp ;zero: end
- pralo CALL conput ;write it
- JMP pralp ;'next char
- praend POPF ;restore
- POP AX
- XCHG BX,[BP]$02 ;restore ret
- POP BP
- RET ;"
- knrmvid CMP.B curatt,#$00 ;NormVideo
- JZ knrmret ;already set: ret
- MOV.B curatt,#$00 ;set flag
- JMP xnormvid ;'do it
- knrmret RET ;"
- klowvid CMP.B curatt,#$01 ;LowVideo
- JZ knrmret ;:already set
- MOV.B curatt,#$01 ;set it
- JMP xlowvid ;"
- vidattr3 CMP.B curatt,#$03 ;Attribute #3
- JZ knrmret ;:already set
- MOV.B curatt,#$03 ;set it
- PUSH AX ;save
- MOV AL,att3 ;set that attribute
- MOV attcur,AL
- POP AX ;restore
- RET ;"
- vidattr2 CMP.B curatt,#$02 ;Attribute #2
- JZ knrmret ;:already set
- MOV.B curatt,#$02 ;set it
- PUSH AX ;save
- MOV AL,att2 ;set that attribute
- MOV attcur,AL
- POP AX ;restore
- RET ;"
- movebk MOV SI,BX ;Block transfer [BX]->[DX]
- MOV DI,DX ;forward = delete
- PUSH DS ;DS -> ES
- POP ES
- CLD
- REPZ ;CX=count
- MOVS.B ;do it
- MOV BX,SI ;point to block end
- MOV DX,DI
- RET ;"
- movebkb MOV SI,BX ;Block transfer [BX]->[DX]
- MOV DI,DX ;backward = insert
- PUSH DS ;DS -> ES
- POP ES ;BX,DX point to block END !
- STD
- REPZ
- MOVS.B ;do it
- CLD ;reset dir flag
- MOV BX,SI ;point to block beg
- MOV DX,DI
- RET ;"
- inited XOR AX,AX ;Init editor vars
- MOV editflg,AL
- MOV DI,#srend ;390..3B0:=0
- MOV CX,#$0021
- PUSH DS ;DS -> ES
- POP ES
- CLD ;fill
- REPZ
- STOS.B
- INC AX ;3B1..3B2:=1
- MOV DI,#oldlen ;old len, redisplay from
- MOV CX,#$0002
- REPZ
- STOS.B
- INC AX ;Words 3BA..3BD:=2
- MOV DI,#bkbegl ;block pos in buffer
- MOV CX,#$0002
- REPZ
- STOS
- MOV AX,#$FFFF ;3B3..3B8:=FF
- MOV DI,#overflg ;set flags:
- MOV CX,#$0006 ;insert, indent, display
- REPZ ;redisplay
- STOS.B
- MOV AX,#line ;Words 3BE..3C8:=046C
- MOV DI,#edpos ;current pos, pos in line buffer
- MOV CX,#$0006 ;pos FIFO = beg of line buffer
- REPZ
- STOS
- MOV AL,#$00 ;3CA..45F:=0
- MOV DI,#cmdbuf ;command entry buffer, search,
- MOV CX,#$0096 ;replace, option, filename
- REPZ
- STOS.B
- MOV.B cmdbuf,#$03 ;command buf: 3 chars
- MOV.B srword,#$1E ;search word: 30 chars
- MOV.B srrepl,#$1E ;replce word: 30 chars
- MOV.B stopt,#$0A ;option word: 10 chars
- MOV.B fnbuf,#$40 ;file name: 64 chars
- MOV.B fnbufend,#$1A ;end file name buffer
- MOV lineend,#$0A0D ;end line input buffer
- MOV AL,#$00 ;no flicker
- MOV DX,#$B000 ;mono screen segment
- CMP.B scrmod,#$07 ;mode = 7 ?
- JZ inited1 ;yes: mono
- CS:
- MOV AL,scrflick ;get flicker flag
- MOV DH,#$B8 ;set segment
- inited1 MOV scrbad,AL ;store flicker flag
- MOV scrseg,DX ;store segment
- RET ;"
- clred MOV bkbeg,BX ;Clear editor vars
- MOV bkend,BX ;set to beg of text = BX
- MOV edpos,BX
- MOV posfifo,BX
- MOV qppos,BX
- MOV disbeg,BX
- RET ;"
- ekd CALL eflush ;flush changes
- CS:
- MOV.B DL,txwiny2 ;bottom-1
- DEC.B DL
- MOV DH,#$00
- CALL setcpos ;set cursor pos
- CALL knrmvid ;NormVideo
- DEC txend ;end of text
- MOV BX,txend
- MOV.B [BX],#$1A ;store ^Z at the end
- JMP kmainlp ;"return to main menu
- editor CALL kgetfn ;E:Editor - get file name
- MOV BX,#$FFFF ;position flag
- editor2 PUSH BX ;save pos
- MOV BX,txend ;end of text
- MOV [BX],#$0A0D ;store CR,LF there
- INC txend
- MOV.B statobs,#$00 ;status line obsolete
- MOV.B dislin,#$01 ;redisplay all
- MOV sepptr,#eseptab ;pos of word separator tab
- CALL knrmvid ;NormVideo
- CALL xclrscr ;ClrScr
- POP BX ;relative text pos
- ADD BX,txbeg ;+text beg+1
- INC BX
- CALL efsetpos ;set new pos
- edmain CALL eredispl ;redisplay
- MOV.B CL,statera ;clear status line
- OR.B CL,CL ;anything to erase ?
- JZ ednoera ;:no
- MOV BX,#$0000 ;cursor pos: home
- CALL esetcur
- CALL esetlow ;LowVideo
- MOV AL,#$20 ;space
- edera CALL ewritch ;write char
- DEC.B CL ;another ?
- JNZ edera ;:yes
- MOV.B statera,CL ;clear erase flag
- ednoera CALL estat ;display status line
- CALL edproc ;get command
- JNB edchg ;:no command - enter char
- JZ edmain ;:not found
- CMP.B DH,#$7F ;MSB vector = 1 ?
- JB ednochg ;:no
- MOV.B txchg,#$FF ;set flag: text changed
- MOV.B txcomp,#$00 ;code invalid
- AND.B DH,#$7F ;mask vector
- ednochg MOV BX,#edmain ;store return addr
- PUSH BX ;-> main loop
- PUSH DX
- MOV BX,#pfifosrc ;do position FIFO
- MOV DX,#pfifodst
- MOV CX,#$0008 ;8 bytes
- JMP movebkb ;'move back, jump to command
- eprefix CALL eddiscmd ;^P:Control char prefix - display
- CALL keyget ;get char
- JMP.b edput ;'enter this char
- edchg MOV txchg,AL ;flag: text changed
- MOV.B txcomp,#$00 ;code invalid
- edput MOV BX,lnpos ;pos in line
- CMP BX,#lineend0 ;line full ?
- JNB edmain ;yes: ignore char
- CMP.B overflg,#$00 ;overwrite ?
- JZ edover ;:yes
- PUSH AX ;save it
- CALL einsch ;make space for char
- POP AX ;restore it
- edover MOV.B [BX],AL ;store char
- INC BX ;cursor right
- PUSH BX
- CALL eredlin ;redisplay line
- POP BX
- MOV lnpos,BX ;new pos in line buffer
- CALL erepos ;reposition in line
- JMP edmain ;"main loop
- edproc CALL keyget ;Get command: get key
- CMP AL,#$7F ;Delete ?
- JZ edpdel ;:yes
- CMP AL,#$20 ;control char ?
- JNB edpret ;no: no command
- edpdel MOV BX,#cmdbuf ;pointer to cmd buf
- MOV.B [BX],#$01 ;store length
- INC BX
- MOV.B [BX],AL ;store char
- edploop PUSH BX ;save pos in buf
- MOV BX,#cmdbuf ;ptr cmd buf
- MOV SI,#ecmd1 ;ptr first cmd table
- MOV CH,#$FF ;must be equal
- CALL edsrcmd ;search in table
- POP BX ;restore pos
- OR.B AL,AL ;test result
- JNZ edpfnd ;:found
- PUSH BX ;save again
- MOV BX,#cmdbuf ;ptr cmd buf
- MOV SI,#ecmd2 ;ptr second cmd table
- MOV CH,#$1F ;second char without ctrl ok
- CALL edsrcmd ;search in table
- POP BX ;restore pos
- OR.B AL,AL ;test result
- STC
- JZ edpret ;:not found
- edpfnd DEC.B AL
- JZ edpcont ;:need another key
- MOV BX,#ejmptab ;ptr jump table
- ADD BX,CX ;+2*cmd number
- ADD BX,CX
- CS:
- MOV DX,[BX] ;get jump addr
- STC ;ok
- edpret RET ;'
- edpcont CALL eddiscmd ;display command char
- PUSHF ;save stat
- CALL keyget ;get key
- INC.B cmdbuf ;inc lenght cmd buf
- INC BX ;next pos
- MOV.B [BX],AL ;store char
- POPF ;restore stat: function key ?
- JNZ edploop ;:continue
- CALL eddiscmd ;display
- JMP edploop ;"try it again
- eddiscmd CALL ekbdstat ;display command sequence
- JNZ edpret ;late - ret
- PUSH BX ;save pos
- XOR BX,BX ;clear char count
- MOV.B statera,BL ;number of chars to erase
- CALL esetcur ;set position: home
- MOV BX,#cmdbuf ;ptr cmd buf
- MOV.B AL,[BX] ;get cmd length
- eddislp PUSH AX ;save len
- INC BX ;next char
- MOV.B AL,[BX] ;get char
- ADD.B statera,#$02 ;2 chars to erase
- CALL edcntput ;put char
- POP AX ;restore len
- DEC.B AL ;another char ?
- JNZ eddislp ;:yes
- POP BX ;restore
- RET ;"
- edcntput PUSH AX ;Display control code - save char
- CALL esetnrm ;set attribute
- POP AX ;restore char
- CMP AL,#$20 ;control ?
- JB edcntl ;:yes
- JMP ewritch ;'write char
- edcntl PUSH AX ;save char
- PUSH AX
- MOV AL,#$5E ;write ^
- CALL ewritch
- POP AX ;restore char
- ADD AL,#$40 ;-> normal char
- CALL ewritch ;write it
- POP AX ;restore char
- RET ;"
- edsrcmd MOV CL,#$FF ;Search command in table
- PUSH CX ;save cmd comparison mask
- PUSH BX ;command buf ptr
- edsclp POP BX ;restore
- POP CX
- CS:
- MOV.B AL,[SI] ;get char from table
- INC SI ;next pos
- OR.B AL,AL ;end of table ?
- JZ edscret ;:yes
- INC.B CL ;command number
- PUSH CX ;save
- PUSH BX
- MOV.B CL,[BX] ;get command len
- INC BX ;go to first char
- SUB.B AL,CL ;>= table len ?
- JNB edsc1 ;:yes
- ADD.B CL,AL ;skip this entry
- JMP.b edscnxt1 ;'try next one
- edsc1 LAHF ;save flags
- PUSH AX ;save table entry length
- edsccmp CS:
- MOV.B AL,[SI] ;char from table
- SUB.B AL,[BX] ;compare them
- AND.B AL,CH ;mask difference
- JNZ edscnext ;:not equal - next one
- INC SI ;next char
- INC BX
- DEC.B CL ;= length of cmd ?
- JNZ edsccmp ;no: compare
- POP AX ;restore flag, table entry length
- SAHF
- POP BX ;restore
- POP CX
- MOV CH,#$00 ;mode: none
- MOV AL,#$FF ;found
- JZ edscret ;:found
- MOV AL,#$01 ;need another char
- edscret RET ;'
- edscnext POP AX ;restore length
- ADD.B AL,CL ;skip entry
- MOV.B CL,AL
- edscnxt1 MOV CH,#$00 ;clr hi
- ADD SI,CX ;add to ptr
- JMP edsclp ;"try next one
- estat CALL ekbdstat ;Display status line: Get KBD stat
- JNZ edscret ;late: ret
- CALL klowvid ;LowVideo
- CMP.B statobs,#$FF ;obsolete ?
- JZ estnrm ;no:just display pos
- MOV.B statobs,#$FF ;clear flag
- MOV BX,#$0000 ;screen position
- MOV oldpos,BX ;remember cursor pos
- MOV.B edcol,BL ;column
- CALL esetcur ;set cursor pos
- CALL eclrlin ;clear line
- CS:
- CMP.B txwinx2,#$38 ;screen width sufficient ?
- JB estshrt ;:no
- MOV BX,#$2A00 ;set cursor pos
- CALL esetcur
- CALL kdworkfn ;display filename
- estshrt MOV BX,#$0600 ;cursor pos
- CALL ewritpos ;put string
- B "Line ",$00
- MOV BX,#$1000 ;cursor pos
- CALL ewritpos ;put string
- B "Col ",$00
- MOV BX,#$1800 ;cursor pos
- CMP.B overflg,#$00 ;Overwrite ?
- JZ estover ;:yes
- CALL ewritpos ;put string
- B "Insert ",$00
- JMP.b estins ;'
- NOP
- estover CALL ewritpos ;put string
- B "Overwrite ",$00
- estins CMP.B indntflg,#$00 ;Indent ?
- JZ estnrm ;:no
- CALL ewrits ;put string
- B "Indent",$00
- estnrm MOV AL,horscr ;calc column
- ADD.B AL,phcol
- INC.B AL
- CMP.B AL,edcol ;= old col ?
- JZ estnocol
- MOV edcol,AL ;set that column
- MOV BX,#$1400 ;cursor pos
- CALL esetcur ;set it
- CALL klowvid ;LowVideo
- MOV.B BL,AL ;number -> BX
- MOV BH,#$00 ;clr hi
- MOV AL,#$03 ;3 chars
- CALL ednum ;display number
- estnocol MOV BX,edpos ;current pos = old pos ?
- CMP BX,oldpos
- JNZ estrow ;no: display line number
- JMP eposcur ;'restore cursor pos
- estrow CALL eposcur ;restore cursor pos
- CALL ekbdstat ;Get KBD stat
- JNZ estend
- MOV DI,txbeg ;beg of text
- MOV CX,edpos
- MOV DX,#$0001 ;line number
- SUB CX,DI ;calc count
- JZ estrow2 ;:done
- estcnt CLD ;forward search
- PUSH DS ;DS -> ES
- POP ES
- estlf MOV AL,#$0A ;search LF
- REPNZ
- SCAS.B
- JNZ estrow2 ;:not found, done
- INC DX ;count it
- OR.B DL,DL ;256 lines counted ?
- JNZ estlf ;:no, continue
- CALL ekbdstat ;Get KBD stat
- JZ estcnt ;:nothing entered
- JMP.b estend
- estrow2 MOV BX,#$0B00 ;cursor pos
- PUSH DX ;save line number
- CALL esetcur ;set cursor pos
- CALL klowvid ;LowVideo
- POP BX ;restore number
- MOV AL,#$05 ;5 digits
- CALL ednum ;write it
- MOV BX,edpos ;current pos -> old pos
- MOV oldpos,BX
- estend JMP eposcur ;"restore cursor pos
- ednum PUSH AX ;Write number: save field length
- MOV CH,#$00 ;clear flag
- CALL edcvt ;convert number
- POP AX ;restore length
- ADD.B AL,CH ;counter
- JZ ednret ;:done
- ;counter
- MOV.B CH,AL
- MOV AL,#$20 ;pad with spaces
- ednpad CALL ewritch ;put it
- DEC.B CH ;another ?
- JNZ ednpad ;:yes
- ednret RET ;"
- edcvt CMP BX,#$00 ;number -> decimal
- MOV AL,#$30
- JZ edcvno0 ;0: store a 0
- MOV DX,#$2710 ;digit 10000
- CALL edcvdig
- MOV DX,#$03E8 ;digit 1000
- CALL edcvdig
- MOV DX,#$0064 ;digit 100
- CALL edcvdig
- MOV DX,#$000A ;digit 10
- CALL edcvdig
- MOV DX,#$0001 ;digit 1
- edcvdig XOR.B AL,AL ;clear digit
- edcvdlp SUB BX,DX ;do successive subtraction
- JB edcvput ;:done
- INC.B AL ;count digit
- JMP edcvdlp ;'
- edcvput ADD BX,DX ;restore number
- ADD AL,#$30 ;convert to ASCII
- CMP AL,#$30 ;0 ?
- JNZ edcvno0 ;:no
- OR.B CH,CH ;is it a leading zero ?
- JZ ednret
- edcvno0 DEC.B CH ;set flag
- JMP ewritch ;"write char
- edreadst CALL prints ;Input from status line
- B ": ",$00
- MOV BX,DX ;destination ptr
- MOV SI,DX
- INC BX ;point to string
- MOV.B DH,[BX] ;get old length
- MOV.B [BX],#$00 ;clr old length
- INC BX ;go to string
- erloop MOV.B disflg,#$00 ;flag: editing stat line
- PUSH DX ;save regs
- PUSH BX
- PUSH SI
- CALL edproc ;process key
- POP SI
- POP BX
- POP DX
- MOV.B disflg,#$FF ;restore flag
- JNB erput ;no command: put char
- JNZ ercr ;:valid command
- MOV AL,cmdbuf1 ;get command
- CALL etstint ;test for interrupt
- JMP erloop ;'loop back
- ercr MOV.B AL,CL ;command code
- CMP AL,#$00 ;CR ?
- JNZ errt ;:no
- MOV.B [BX],#$1A ;store ^Z at the end
- RET ;'return
- errt CMP AL,#$03 ;Character right ?
- JNZ errecall ;:no
- MOV.B AL,[SI]$01 ;get length
- CMP.B AL,DH ;= pos ?
- JNB erloop
- INC.B [SI]$01 ;go right
- JMP.b errest ;'get char from old value
- errecall CMP AL,#$05 ;word right ?
- JNZ erclr ;:no
- errec1 MOV.B AL,[SI]$01 ;length = old len ?
- CMP.B AL,DH
- JZ erloop ;yes: loop
- MOV.B AL,[BX] ;get char
- CALL edcntput ;write it
- INC BX ;next one
- INC.B [SI]$01 ;inc len
- JMP errec1 ;'until end
- erclr CMP AL,#$04 ;Word left ?
- JNZ erprefix ;:no
- erclrl CALL erdelc ;delete char
- JNZ erclrl ;:ok, continue
- JMP erloop ;'end reached, loop
- erprefix CMP AL,#$2D ;Control char prefix ?
- JNZ erdel ;:no
- CALL keyget ;get a key
- JMP.b erput ;'put it
- erdel CMP AL,#$1B ;Test delete codes
- JZ erdel1 ;:delete left
- CMP AL,#$1C
- JZ erdel1 ;:del left
- CMP AL,#$01
- JZ erdel1 ;:char left
- CMP AL,#$02
- JNZ erinv ;:no delete
- erdel1 CALL erdelc ;delete char
- JMP erloop ;'loop back
- erinv CMP.B cmdbuf1,#$12 ;word right ?
- JZ errec1 ;:yes
- JMP erloop ;'loop back
- erput MOV.B DL,AL ;save char
- MOV.B AL,[SI]$01 ;current len
- CMP.B AL,[SI] ;< max len ?
- JB erput2 ;:ok
- JMP erloop ;'loop back
- erput2 INC.B [SI]$01 ;inc length
- MOV.B [BX],DL ;store char
- errest MOV.B AL,[BX] ;get char
- INC BX ;go to next
- CALL edcntput ;display it
- MOV.B AL,[SI]$01 ;get current len
- CMP.B AL,DH ;= old len ?
- JNB ergend ;:no
- JMP erloop ;'loop back
- ergend MOV.B DH,[SI]$01 ;get pos
- JMP erloop ;'loop back
- erdelc MOV.B AL,[SI]$01 ;Delete char: get len
- OR.B AL,AL ;0 ?
- JZ erdelret ;yes: nothing to delete
- DEC.B [SI]$01 ;dec length
- DEC BX ;go back one char
- CMP.B [BX],#$20 ;was it a control char ?
- JNB erdelcc ;:no
- CALL erdelcc ;delete two chars
- erdelcc CALL prints ;delete one char
- B $08," ",$08,$00
- MOV AL,#$FF ;set flag
- OR.B AL,AL
- erdelret RET ;"
- efind MOV.B srmode,#$00 ;^QF:Find - set mode flag
- CALL eqffind ;get find word
- CALL eqfopt ;get option string
- JMP.b efnd1 ;"do it
- eqffind CALL eclrstat ;Get find word: clear stat line
- CALL ewrits ;write string
- B "Find",$00
- MOV DX,#srword ;dest: find word
- JMP edreadst ;"read string
- eqfrepl CALL eclrs2 ;Get repl word: clear stat line
- CALL ewrits ;write string
- B "Replace with",$00
- MOV DX,#srrepl ;dest var
- JMP edreadst ;"read string
- eqfopt CALL eclrs2 ;Get Options: clear stat line
- CALL ewrits ;write string
- B "Options",$00
- MOV DX,#stopt ;dest var
- CALL edreadst ;read string
- CS:
- MOV.B BH,txwinx2 ;end of screen
- DEC.B BH
- MOV BL,#$00 ;beg of line
- JMP esetcur ;"set cursor pos
- ereplace MOV.B srmode,#$FF ;^QA:Search & Replace
- CALL eqffind ;get find word
- CALL eqfrepl ;get replacement word
- CALL eqfopt ;get option string
- JMP.b efnd1 ;"do it
- erepeat CALL eddiscmd ;^L:Repeat last find
- efnd1 CALL eflush ;write back current line
- CALL esrcend ;end of line buffer
- INC BX ;+1
- MOV DX,lnpos ;or current pos in line
- CALL emin
- MOV DX,#line ;- beg of buffer
- SUB BX,DX
- MOV DX,edpos ;+ current pos
- ADD BX,DX
- MOV srpos,BX ;-> search pos
- MOV srcnt,#$0000 ;line count
- MOV CX,txend ;text end-1
- DEC CX
- MOV srend,CX ;-> search end
- MOV CX,txbeg ;text beg -> search beg
- MOV srbeg,CX
- MOV BX,#sropt1 ;ptr option string
- MOV.B CH,[BX] ;get length
- MOV.B sropt,#$00 ;clear option flag
- OR.B CH,CH ;empty ?
- JNZ efndcnt ;:no
- JMP.b efndopte ;'no options set
- NOP ;Process option line
- efndcnt INC BX ;next char
- MOV.B AL,[BX] ;get char
- CMP AL,#$30 ;valid digit ?
- JB efndopt ;:no
- CMP AL,#$3A ;> 9 ?
- JNB efndopt ;:no digit
- SUB AL,#$30 ;-> number. Get line count
- CBW
- PUSH AX ;save digit
- MOV AL,#$0A ;current count * 10
- IMUL srcnt
- POP DX ;+ digit
- ADD AX,DX
- MOV srcnt,AX ;-> line count
- JMP.b efndo2 ;'continue
- efndopt CALL upcase ;UpCase
- CMP AL,#$57 ;W ?
- JNZ efndu ;:no
- OR.B sropt,#$01 ;flag: whole words
- efndu CMP AL,#$55 ;U ?
- JNZ efndn ;:no
- OR.B sropt,#$04 ;flag: ignore upper/lower
- efndn CMP AL,#$4E ;N ?
- JNZ efndg ;:no
- OR.B sropt,#$02 ;flag: replace without asking
- efndg CMP AL,#$47 ;G ?
- JNZ efndb ;:no
- OR.B sropt,#$08 ;flag: global
- efndb CMP AL,#$42 ;B ?
- JNZ efndl ;:no
- OR.B sropt,#$10 ;flag: backwards
- efndl CMP AL,#$4C ;L ?
- JNZ efndo2 ;:no
- OR.B sropt,#$20 ;flag: search block
- AND.B sropt,#$F7 ;clear global
- MOV CX,bkend ;search block, only
- MOV srend,CX ;block end -> search end
- MOV CX,bkbeg ;block beg -> search beg
- MOV srbeg,CX
- efndo2 DEC.B CH ;another option char ?
- JNZ efndcnt ;:yes
- efndopte CMP srcnt,#$01 ;at least one line to do
- JA efndcnok ;:ok
- MOV srcnt,#$0001
- efndcnok MOV BX,srbeg ;begin limit
- MOV AL,sropt ;option
- TEST AL,#$10 ;backwards ?
- JZ efndfwd ;:no
- MOV BX,srend ;end limit
- efndfwd TEST AL,#$28 ;block & global ?
- JNZ efndrep ;:no
- MOV BX,srpos ;current pos
- efndrep MOV srpos,BX ;store search pos
- TEST.B sropt,#$10 ;backwards ?
- JNZ efndbkw ;:yes
- CMP BX,srend ;= search limit ?
- JB efndsrc ;:no, continue
- JMP efndexit ;'done
- efndbkw DEC BX ;go back
- CMP BX,srbeg ;= search limit ?
- JNB efndsrc ;:no
- JMP efndexit ;'end it
- efndsrc MOV DX,#srword2 ;ptr searched word
- MOV AL,srword1 ;get length
- MOV.B CH,AL
- TEST.B sropt,#$10 ;backwards ?
- JZ efndfw2 ;:no
- DEC.B AL ;go to its end
- ADD.B AL,DL
- MOV.B DL,AL
- JNB efndfw2
- INC.B DH
- efndfw2 TEST.B sropt,#$01 ;whole words ?
- JZ efndall1 ;:no
- PUSH DX ;save
- PUSH BX
- CALL edbeg ;at the beginning ?
- MOV.B AL,[BX] ;get char
- POP BX ;restore
- POP DX
- JB efndall1 ;:at beg
- CALL edfnchar ;is it alphanum ?
- JB efndpos ;:yes - continue searching
- efndall1 OR.B CH,CH ;length = 0 ?
- JZ efndnil ;:found
- efndcmp CALL edcmp ;compare chars
- JNZ efndpos ;:not the same
- DEC.B CH ;another char ?
- JNZ efndnch ;:yes
- efndnil TEST.B sropt,#$01 ;whole words ?
- JZ efndall2 ;:no
- PUSH BX ;save
- CALL edend ;end ?
- MOV.B AL,[BX] ;get char
- POP BX ;restore
- JB efndall2 ;:at the end
- CALL edfnchar ;alphanum ?
- JB efndpos ;yes: not valid
- efndall2 TEST.B sropt,#$10 ;backwards ?
- JNZ efndbw2 ;:yes
- INC BX ;end of text ?
- CMP BX,txend
- efndbw2 CMP.B srmode,#$00 ;search mode ?
- JZ efndfnd ;:find
- CALL edoreplc ;replace it
- efndfnd TEST.B sropt,#$28 ;block global ?
- JZ efndnxt ;:yes
- JMP efndrep ;'continue
- efndnxt DEC srcnt ;another line to process ?
- JZ efndend ;:no
- JMP efndrep ;'continue
- efndend JMP.b efsetpos ;'set new pos
- NOP
- efndnch PUSH DX ;save pos
- CALL edend ;at the end ?
- POP DX ;restore
- JB efndexit ;:yes
- TEST.B sropt,#$10 ;backwards ?
- JZ efndfw3 ;:no
- DEC DX ;go back
- JMP efndcmp ;'
- efndfw3 INC DX ;next char
- JMP efndcmp ;'continue
- efndpos MOV BX,srpos ;get current search pos
- CALL edend ;at the end ?
- JB efndexit ;:yes
- JMP efndrep ;'continue
- efndexit CALL edrange ;end search: limit new pos
- CALL efsetpos ;set pos
- TEST.B sropt,#$28 ;global block ?
- JNZ espret ;:no
- CALL eclrstat ;clear status line
- CALL ewriterr ;write string
- B "Search string not found",$00
- JMP waitesc ;"wait for ESC
- efsetpos CALL esetpos ;set position
- JMP erstlin ;"restore line
- esetpos MOV DX,txend ;Set pos
- DEC DX ;text end - 1
- CMP BX,DX ;= current ?
- JB esp2 ;:below
- XCHG BX,DX ;limit it
- esp2 PUSH BX ;save
- PUSH BX
- CALL esrcbeg ;search beg of that line
- MOV edpos,BX ;-> current pos
- XCHG BX,DX ;-> DX
- POP BX ;restore
- SUB BX,DX ;calc pos in line
- MOV DX,#line ;+ buffer offset
- ADD BX,DX
- MOV lnpos,BX ;-> pos in line buffer
- CALL erepos ;reposition in current line
- CALL eseldisp ;do selective rewrite
- POP BX ;restore pos
- espret RET ;"
- edrange MOV DX,txbeg ;bring BX into range:
- CALL emin ;>= text beg,
- MOV BX,txend
- DEC BX
- JMP emin ;"< text end
- edfnchar CMP AL,#$30 ;char in alphanum ?
- JB edfnch2 ;<0: no
- CMP AL,#$3A
- JB edfnchrt ;0..9: yes
- CMP AL,#$41
- JB edfnch2 ;<A: no
- CMP AL,#$5B
- JB edfnchrt ;A..Z: yes
- CMP AL,#$61
- JB edfnch2 ;<a: no
- CMP AL,#$7B
- JB edfnchrt ;a..z: yes
- edfnch2 OR.B AL,AL ;test flag
- RET ;"
- edbeg TEST.B sropt,#$10 ;At the beginning ?
- JZ edend2 ;:forward
- edbeg2 INC BX
- CMP BX,srend ;= search limit end ?
- CMC
- edfnchrt RET ;'
- edend TEST.B sropt,#$10 ;end reached ?
- JZ edbeg2 ;:forward
- edend2 DEC BX
- CMP BX,srbeg ;= search limit beg ?
- RET ;"
- edcmp XCHG DX,BX ;Compare chars
- MOV.B AL,[BX] ;get char in search string
- XCHG DX,BX
- CMP AL,#$01 ;wild card ?
- JZ edfnchrt ;yes: ok
- CMP.B AL,[BX] ;compare it
- JZ edfnchrt ;yes: ok
- TEST.B sropt,#$04 ;ignore upper/lower ?
- JZ edcmp2 ;:no, just compare
- CALL edfnchar ;is it a valid char ?
- JNB edcmp2 ;:no
- XOR.B AL,[BX] ;mask different bits
- AND AL,#$DF
- RET ;'
- edcmp2 CMP.B AL,[BX] ;compare it
- RET ;"
- edoreplc PUSH BX ;Do replace
- CALL ekbdstat ;get KBD stat
- JZ erpdis ;nothing: display it
- TEST.B sropt,#$02 ;replace without asking ?
- JNZ erpdoit ;:yes
- erpdis CALL efsetpos ;set new position
- CALL eredispl ;redisplay
- TEST.B sropt,#$02 ;replace without asking ?
- JNZ erpdoit ;:yes
- CALL eclrs2 ;clear status line
- CALL printatt ;write string
- B "Replace (",$D9,"/",$CE,"): ",$00
- erpblnk MOV.B BL,phrow ;Blink cursor: alternate
- MOV.B BH,phcol ;status line / cursor pos
- CALL esetcur ;set cursor pos
- MOV CX,#$0004 ;do 4 times
- erpbw1 CALL ekbdstat ;get KBD stat
- JNZ erpbw2 ;:key pressed
- MOV BX,#$0064 ;wait 100 ms
- PUSH CX ;save count
- CALL delaybx ;Delay
- POP CX ;restore
- LOOP erpbw1 ;:another
- MOV BX,#$0F00 ;pos:status line
- CALL esetcur ;set cursor pos
|