| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600 |
- readst POP errpos ;get ret addr
- MOV currfil,#stdin ;from std input
- MOV currfil1,DS
- AND.B stdinfl,#$DF ;clear flag: char read
- PUSH ES ;save dest var ptr
- PUSH DI
- PUSH AX ;save flag
- CALL rdedit ;read with editing
- POP AX ;restore flag
- OR.B AL,AL ;readln ?
- JZ readst2 ;:no
- CALL xwriteln ;do WriteLn
- readst2 POP DI ;restore dest var ptr
- POP ES
- JMP [errpos] ;"return
- rdedit XOR.B DH,DH ;Read line with editing: clr flag
- rdedit2 MOV.B CH,conbufln ;buffer length
- CMP.B CH,#$7E ;too big ?
- JB relimlen ;:no
- MOV CH,#$7E ;limit to 127 chars
- relimlen MOV.B conbufln,#$7E ;127 chars again
- MOV BX,#coninbuf
- MOV conbufpt,BX ;set input ptr
- rezero XOR.B CL,CL ;ptr into line
- reloop CALL keyget ;get char
- MOV DL,#$01 ;flag: one char
- CMP AL,#$08 ;BS ?
- JZ rebs ;:yes
- CMP AL,#$7F ;Delete ?
- JZ rebs ;:yes
- CMP AL,#$04 ;^D ?
- JZ recall ;yes, recall char from buffer
- DEC.B DL ;flag: all chars
- CMP AL,#$18 ;^X ?
- JZ rebs ;yes:erase input line
- CMP AL,#$1B ;ESC ?
- JZ rebs ;yes:erase input line
- CMP AL,#$12 ;^R ?
- JZ recall ;yes:recall last input line
- CMP AL,#$1A ;^Z ?
- JZ reeof ;:yes
- CMP AL,#$0D ;CR ?
- JZ recr ;:yes
- CMP AL,#$20 ;other control char ?
- JB reloop ;yes: ignore
- CMP.B CL,CH ;end of buffer reached ?
- JZ reloop
- MOV.B AH,[BX] ;get old char
- MOV.B [BX],AL ;store new char
- INC.B CL ;new pos
- INC BX
- CMP.B AH,#$20 ;was it old end of buffer ?
- JNB renotend ;:no
- MOV.B [BX],AH ;mark it again
- renotend CALL xputch ;display new char
- JMP reloop ;'next key
- rebs DEC.B CL ;go back one char
- JS rezero ;:beg of line
- CALL prints ;go back one char
- B $08," ",$08,$00
- DEC BX ;go back
- DEC.B DL ;another char ?
- JNZ rebs ;:yes
- JMP reloop ;'next key
- recall MOV.B AL,[BX] ;recall from buffer
- CMP AL,#$20 ;end of buffer
- JB reloop ;:yes
- CALL xputch ;display that char
- INC.B CL ;next one
- INC BX
- DEC.B DL ;another one ?
- JNZ recall ;:yes
- JMP reloop ;'next key
- reeof OR.B DH,DH ;test flag
- JZ reloop ;:no EOF allowed
- JMP.b resto ;'store it
- recr OR.B DH,DH ;test flag
- JNZ reend ;:no ^Z needed
- resto MOV.B [BX],#$1A ;store ^Z
- JMP.b reend2 ;'end it
- reend CALL xwriteln ;WriteLn
- MOV [BX],#$0A0D ;store CR,LF at end
- INC BX ;2 chars added
- reend2 INC BX ;1 char added
- MOV conbfend,BX ;store end pointer
- RET ;"
- xputch MOV.B AH,cbreak ;Put char: save break flag
- MOV.B cbreak,#$00 ;break allowed
- PUSH AX ;save flag
- CALL conput ;print char
- POP AX ;restore flag
- MOV.B cbreak,AH
- RET ;"
- getbyte LES DI,currfil ;Get byte from current file
- getbyte2 CMP.B errnum,#$00 ;error ?
- JNZ gbeof ;yes: return ^Z
- ES:
- MOV.B AL,[DI]$02 ;test flags:
- TEST AL,#$20 ;char pre-read ?
- JNZ gbfrbuf ;yes: return it
- AND AL,#$0F ;device ?
- JNZ gbdev ;:yes
- ES:
- MOV BX,[DI]$08 ;buffer pointer
- ES:
- CMP BX,[DI]$0A ;= buffer end ?
- JB gbnotend ;:no
- CALL gbrdbuf ;read buffer
- ES:
- MOV BX,[DI]$08 ;buffer ptr
- gbnotend ES:
- MOV.B AL,[BX] ;get byte
- INC BX ;advance ptr
- ES:
- MOV [DI]$08,BX ;store ptr
- JMP.b gbbuf2 ;'remember that char
- gbdev PUSH ES ;save file ptr
- PUSH DI ;test devices
- CMP AL,#$01 ;CON ?
- JNZ gbkbd ;:no
- MOV BX,conbufpt ;get from CON input buffer
- CMP BX,conbfend ;end of buffer reached ?
- JB gbget ;no: return char
- MOV.B DH,AL ;^Z allowed
- CALL rdedit2 ;read line
- MOV BX,conbufpt ;ptr to char
- gbget MOV.B AL,[BX] ;get char
- INC BX ;advance ptr
- MOV conbufpt,BX ;update ptr
- JMP.b gbbuf ;'done
- gbkbd CMP AL,#$02 ;KBD ?
- JNZ gbaux ;:no
- DEC SP ;(function:char)
- CALL [vkbdget] ;get char
- JMP.b gbbuf ;'return it
- gbaux CMP AL,#$04 ;AUX ?
- JNZ gbusr ;:no
- DEC SP
- CALL [vauxget] ;get char
- JMP.b gbbuf ;'return it
- gbusr DEC SP ;USR
- CALL [vusrget] ;get char
- gbbuf POP DI ;restore file var ptr
- POP ES
- gbbuf2 ES:
- MOV.B [DI]$03,AL ;store char in buffer
- ES:
- OR.B [DI]$02,#$20 ;set flag: char pre-read
- RET ;'
- gbfrbuf ES:
- MOV.B AL,[DI]$03 ;get char from buffer
- RET ;'
- gbeof MOV AL,#$1A ;return ^Z = EOF
- RET ;'
- gbrdbuf MOV AH,#$3F ;read buffer
- ES:
- MOV BX,[DI] ;file handle
- ES:
- MOV CX,[DI]$06 ;buffer size
- ES:
- MOV DX,[DI]$04 ;buffer offset
- PUSH DS ;save DS
- PUSH ES ;ES -> DS
- POP DS
- CALL dos ;do it
- POP DS ;restore DS
- JNB gbnoerr ;:no error
- XOR AX,AX ;nothing read
- gbnoerr ES:
- MOV BX,[DI]$04 ;buffer offset
- OR AX,AX ;anything read ?
- JNZ gbmakeof ;:yes
- ES:
- MOV.B [BX],#$1A ;store a ^Z
- INC AX ;1 char read
- gbmakeof ES:
- MOV [DI]$08,BX ;-> buffer pointer
- ADD BX,AX ;+ number chars read
- ES:
- MOV [DI]$0A,BX ;-> buffer end
- RET ;"
- readnum PUSH ES ;Read number
- PUSH DI ;save ptr
- MOV BX,#pnbuf ;buffer ptr
- rnspace PUSH BX ;save
- CALL getbyte ;get char
- POP BX ;restore ptr
- CMP AL,#$1A ;^Z ?
- JZ rnend ;yes: end
- ES:
- AND.B [DI]$02,#$DF ;clear flag: char pre-read
- CMP AL,#$20 ;space / control ?
- JBE rnspace ;yes: ignore
- rndig MOV.B [BX],AL ;store that char
- INC BX ;advance ptr
- CMP BX,#pnbufend ;end reached ?
- JZ rnend ;:yes
- PUSH BX ;save ptr
- CALL getbyte ;get char
- POP BX ;restore ptr
- CMP AL,#$20 ;space / control ?
- JBE rnend ;yes: end
- ES:
- AND.B [DI]$02,#$DF ;clear flag: char pre-read
- JMP rndig ;'next digit
- rnend MOV.B [BX],#$00 ;store a 0 at the end
- MOV BX,#pnbuf ;nothing entered ?
- CMP.B [BX],#$00
- POP DI ;restore ptr
- POP ES
- RET ;"
- chknum JB cnerr ;Check numeric format
- CMP.B [BX],#$00 ;end reached ?
- JZ cnret ;yes: ok
- cnerr MOV.B errnum,#$10 ;Error in numeric format
- STC
- cnret RET ;"
- xrdchar PUSH DI ;Read char: save ptr
- CALL getbyte ;get char
- ES:
- AND.B [DI]$02,#$DF ;clear flag: char pre-read
- POP DI ;var ofs
- POP BX ;ret addr
- POP ES ;var seg
- ES:
- MOV.B [DI],AL ;store char
- JMP BX ;"return
- xrdbyte CLC ;Read byte
- JMP.b rdi1 ;'
- xrdint STC ;Read integer
- rdi1 POP BX ;ret addr
- POP ES ;dest seg
- PUSH BX ;restore ret
- PUSHF ;save flag
- CALL readnum ;read number.
- JZ rdierr ;:nothing entered
- CALL ascint ;convert to integer
- CALL chknum ;check numeric format
- JB rdierr ;:error
- POPF ;restore flag
- JNB rdibyt ;:byte
- ES:
- MOV [DI],AX ;store integer
- RET ;'
- rdibyt ES:
- MOV.B [DI],AL ;store byte
- RET ;'
- rdierr POPF ;remove flag
- RET ;"error - don't change var
- xrdreal POP BX ;Read real
- POP ES ;dest seg
- PUSH BX ;restore ret
- CALL readnum ;read number
- JZ rdrret ;:nothing entered
- PUSH DI ;save dest ptr
- PUSH ES
- MOV DI,#prnum ;dest var
- CALL ascreal ;convert to real
- MOV SI,DI ;-> source ptr
- POP ES ;restore dest ptr
- POP DI
- CALL chknum ;check numeric format
- JB rdrret ;:error
- CLD ;store real number
- MOVS
- MOVS
- MOVS
- rdrret RET ;"
- xrdstr POP BX ;Read string var
- POP ES ;dest seg
- PUSH BX ;restore ret
- XOR BX,BX ;clear length of string
- XOR.B CH,CH ;count. CL=max len
- rdsloop PUSH ES ;save dest ptr
- PUSH DI
- PUSH BX ;save len, cnt
- PUSH CX
- CALL getbyte ;get char
- POP CX ;restore
- POP BX
- CMP AL,#$0D ;CR ?
- JZ rdsend ;:end
- CMP AL,#$1A ;^Z ?
- JZ rdsend ;:end
- ES:
- AND.B [DI]$02,#$DF ;clear flag: char pre-read
- POP DI ;restore dest ptr
- POP ES
- INC BX ;count len
- ES:
- MOV.B [BX_DI],AL ;store char
- LOOP rdsloop ;:another char
- JMP.b rdslen ;'store length
- rdsend POP DI ;restore dest ptr
- POP ES
- rdslen ES:
- MOV.B [DI],BL ;store length
- RET ;"
- xrdarrch POP BX ;Read array of char
- POP ES ;dest ptr
- PUSH BX ;restore ret
- XOR.B CH,CH ;CL=max len
- rdacloop PUSH ES ;save dest ptr
- PUSH DI
- PUSH CX ;save cnt
- CALL getbyte ;get a char
- POP CX ;restore cnt
- CLD
- CMP AL,#$0D ;CR ?
- JZ rdacend ;yes: end
- CMP AL,#$1A ;^Z ?
- JZ rdacend ;:yes
- ES:
- AND.B [DI]$02,#$DF ;clear flag: char pre-read
- POP DI ;restore dest ptr
- POP ES
- STOS.B ;store char
- LOOP rdacloop ;:another char
- RET ;'
- rdacend POP DI ;restore dest ptr
- POP ES
- MOV AL,#$20 ;pad with spaces
- REPZ
- STOS.B
- RET ;"
- xreadln CALL getbyte ;Readln: get char
- CMP AL,#$1A ;^Z ?
- JZ rdlnret ;yes: done
- ES:
- AND.B [DI]$02,#$DF ;clear flag: char pre-read
- CMP AL,#$0A ;LF ?
- JZ rdlnret ;yes: done
- CMP AL,#$0D ;CR ?
- JNZ xreadln ;no: continue
- CALL getbyte ;get next char
- CMP AL,#$0A ;LF ?
- JNZ rdlnret ;no: forget it
- ES:
- AND.B [DI]$02,#$DF ;clear flag: char pre-read
- rdlnret RET ;"
- putbyte LES DI,currfil ;put char to current file
- CMP.B errnum,#$00 ;error ?
- JNZ pbret ;yes: no output
- ES:
- MOV.B CL,[DI]$02 ;get flag
- AND.B CL,#$0F ;device ?
- JNZ pbdev ;:yes
- ES:
- MOV BX,[DI]$08 ;get buffer pointer
- ES:
- MOV.B [BX],AL ;store char
- INC BX ;advance pointer
- ES:
- MOV [DI]$08,BX ;update pointer
- ES:
- CMP BX,[DI]$0A ;= buffer end ?
- JZ pbflush ;yes: do flush
- RET ;'
- pbdev PUSH AX ;put char as parameter
- CMP.B CL,#$01 ;CON ?
- JZ pbcon ;:yes
- CMP.B CL,#$03 ;LST ?
- JZ pblst ;:yes
- CMP.B CL,#$04 ;AUX ?
- JZ pbaux ;:yes
- CALL [vusrput] ;USR out
- RET ;'
- pbcon CALL [vconput] ;CON out
- RET ;'
- pblst CALL [vprnput] ;LST out
- RET ;'
- pbaux CALL [vauxput] ;AUX out
- pbret RET ;'
- pbflush ES: ;flush output buffer
- MOV CX,[DI]$08 ;count=pointer-offset
- ES:
- SUB CX,[DI]$04
- JZ pbok ;:nothing to write
- MOV AH,#$40 ;write byte block
- ES:
- MOV BX,[DI] ;file handle
- ES:
- MOV DX,[DI]$04 ;buffer offset
- ES:
- MOV [DI]$08,DX ;reset buffer pointer
- PUSH DS ;save DS
- PUSH ES ;ES -> DS
- POP DS
- CALL dos ;do it
- POP DS ;restore DS
- JB pberr ;:error
- CMP AX,CX ;length = expected ?
- JZ pbok ;:yes
- pberr MOV.B errnum,#$F0 ;Disk write error
- pbok RET ;"
- xwrchar OR AX,AX ;Write char
- JZ wchdoit ;AX=formatting parm: nothing
- CALL limstind ;limit it
- CMP AL,#$01 ;<= 1 char ?
- JBE wchdoit
- XCHG AX,CX ;-> count
- DEC CX ;-1 for char itself
- wchpad MOV AL,#$20 ;put spaces
- PUSH CX ;save count
- CALL putbyte ;put it
- POP CX ;restore count
- LOOP wchpad ;:continue
- wchdoit POP BX ;ret addr
- POP AX ;get char
- PUSH BX ;restore ret
- JMP putbyte ;"put that char
- xwrint XCHG AX,CX ;Write integer: format parm
- POP BX ;return addr
- POP AX ;get number
- PUSH BX ;restore ret
- PUSH CX ;save format parm
- MOV BX,#pnbuf ;dest buffer
- CALL intasc ;Integer -> ASCII
- wintbuf POP AX ;restore format parm
- CALL limstind ;limit it
- SUB BX,#pnbuf ;calc length
- SUB AX,BX ;length of spaces ?
- JBE wintdoit ;:no space left
- XCHG AX,CX ;-> count
- PUSH BX ;save number length
- wintpad MOV AL,#$20 ;put spaces
- PUSH CX ;save count
- CALL putbyte ;put it
- POP CX ;restore count
- LOOP wintpad ;:another space
- POP BX ;restore number length
- wintdoit MOV CX,BX ;-> count
- MOV BX,#pnbuf ;buffer ptr
- wintloop MOV.B AL,[BX] ;get char
- PUSH BX ;save ptr, cnt
- PUSH CX
- CALL putbyte ;put it
- POP CX ;restore
- POP BX
- INC BX ;next char
- LOOP wintloop ;:again
- RET ;"
- xwrreal XCHG AX,DX ;Write real: second format parm
- POP BX ;ret addr
- POP CX ;first format parm
- MOV DI,#prnum ;get number from stack
- POP [DI]
- POP [DI]$02
- POP [DI]$04
- PUSH BX ;restore ret
- PUSH CX ;push format parm
- MOV BX,#pnbuf ;dest buffer
- CALL fmtreal ;Real -> ASCII
- JMP wintbuf ;"write buffer
- xwrbool POP BX ;write boolean
- POP CX ;get boolean
- PUSH BX ;restore ret
- MOV DI,#sttrue ;(true)
- OR CX,CX ;test boolean
- JNZ wbotrue ;:true
- MOV DI,#stfalse ;(false)
- wbotrue PUSH CS ;str segment
- CALL strload ;load string
- CALL xwrtstr ;write string
- RET ;"
- sttrue B $04,"TRUE"
- stfalse B $05,"FALSE" ;"
- xwrtstr CALL limstind ;Write string: format parm
- MOV BX,SP ;pos of string
- INC BX ;skip ret addr
- INC BX
- SS:
- SUB.B AL,[BX] ;field len - string len
- JBE wstdoit ;:too much - no padding
- MOV.B CL,AL ;-> count
- XOR.B CH,CH
- PUSH BX ;save string pos
- wstpad MOV AL,#$20 ;put spaces
- PUSH CX ;save count
- CALL putbyte ;put it
- POP CX ;restore count
- LOOP wstpad ;:another space
- POP BX ;restore string pos
- wstdoit SS:
- MOV.B CL,[BX] ;get length
- XOR.B CH,CH ;-> count
- INC BX ;point to first char
- OR CX,CX ;nothing to write ?
- JZ wstnil ;:yes
- wstloop SS:
- MOV.B AL,[BX] ;get char
- PUSH BX ;save ptr, cnt
- PUSH CX
- CALL putbyte ;put char
- POP CX ;restore
- POP BX
- INC BX ;next char
- LOOP wstloop ;:another
- wstnil POP DX ;ret addr
- MOV SP,BX ;remove string from stack
- JMP DX ;"return
- xwrtinl POP BX ;Write inline string
- CS:
- MOV.B CL,[BX] ;get length
- XOR.B CH,CH ;-> count
- INC BX ;point to first char
- JCXZ wstinil ;:null string
- wstiloop CS:
- MOV.B AL,[BX] ;get char
- PUSH BX ;save
- PUSH CX
- CALL putbyte ;put char
- POP CX
- POP BX ;restore
- INC BX ;next char
- LOOP wstiloop ;:another
- wstinil JMP BX ;"return - text skipped
- xwrln MOV AL,#$0D ;WriteLn
- CALL putbyte ;put CR
- MOV AL,#$0A
- JMP putbyte ;"put LF
- xseekeol MOV DX,#$010D ;SeekEOLN
- JMP.b seox1 ;'
- xeoln MOV DX,#$000D ;EOLN
- JMP.b seox1 ;'
- xseekeof MOV DX,#$011A ;SEEKEOF
- JMP.b seox1 ;'
- xeoftx MOV DX,#$001A ;EOF
- seox1 POP errpos ;get return addr
- POP ES ;file var seg
- PUSH errpos ;restore ret
- ES:
- TEST.B [DI]$02,#$80 ;open for input ?
- JZ sefalse ;no: false
- seloop PUSH DX ;save flag
- CALL getbyte2 ;get char from file
- POP DX ;restore flag
- CMP.B AL,DL ;= char searched ?
- JZ setrue ;yes: true
- CMP AL,#$1A ;EOF ?
- JZ setrue ;yes: true
- CMP AL,#$20 ;space / control ?
- JA sefalse ;no: false
- OR.B DH,DH ;seek it ?
- JZ sefalse ;:no, false
- ES:
- AND.B [DI]$02,#$DF ;clear flag: char pre-read
- JMP seloop ;'search it
- setrue XOR AX,AX ;return true
- INC AX ;setting flags
- RET ;'
- sefalse XOR AX,AX ;return false
- RET ;"
- xassign XOR.B AL,AL ;Assign: set function code
- JMP doassign ;"do assign
- xresetty XOR.B AL,AL ;Reset typed
- JMP.b openty1 ;'
- xrewrtty MOV AL,#$01 ;Rewrite typed
- openty1 MOV filfunc,AL ;store function code
- POP errpos ;get return addr
- POP ES ;file var ptr
- PUSH errpos ;restore ret
- PUSH CX ;save record length
- CALL closty1 ;clear record len, close file
- POP CX ;remove for error exit
- CMP.B errnum,#$00 ;error ?
- JNZ openty2 ;:yes
- PUSH CX
- CALL openfile ;open that file
- POP CX ;record len
- CMP.B errnum,#$00 ;error ?
- JNZ openty2 ;:yes
- ES:
- MOV [DI]$02,CX ;store record length
- openty2 RET ;"
- xtruncat POP errpos ;Truncate typed, untyped
- POP ES ;file var ptr
- PUSH errpos ;restore ret
- MOV AH,#$40 ;write
- ES:
- MOV BX,[DI] ;file handle
- XOR CX,CX ;length = 0 -> truncate
- JMP dos ;"do it
- xflushty RET $0002 ;"Flush typed, untyped
- xclosety POP errpos ;Close typed, untyped
- POP ES ;file var ptr
- PUSH errpos ;restore ret
- closty1 ES:
- MOV [DI]$02,#$0000 ;record len = 0
- JMP close2 ;"close it
- xfilsel POP errpos ;Select file
- POP ES ;file var ptr
- MOV currfil,DI ;-> current file
- MOV currfil1,ES
- ES:
- CMP [DI]$02,#$00 ;record len = 0 ?
- JNZ selret ;no: ok
- MOV.B errnum,#$04 ;File not open
- selret JMP [errpos] ;"ret
- xrdvar MOV filfunc,#$993F ;Read from typed file
- JMP.b filrw ;'read, unexpected EOF
- xwrvar MOV filfunc,#$F040 ;Write to typed file
- filrw POP BX ;write, disk write error
- POP SI ;var seg
- PUSH BX ;restore ret
- CMP.B errnum,#$00 ;error ?
- JNZ filrwret ;yes: no operation
- MOV DX,DI ;save DI
- LES DI,currfil ;current file var
- MOV.B AH,filfunc ;save function, error code
- ES:
- MOV BX,[DI] ;file handle
- ES:
- MOV CX,[DI]$02 ;record length
- PUSH DS ;save DS
- MOV DS,SI ;ptr var
- CALL dos ;do it
- POP DS ;restore DS
- JB filrwerr ;:error
- CMP AX,CX ;length = expected ?
- JZ filrwret ;:yes
- CMP.B filfunc,#$3F ;read ?
- JNZ filrwerr ;no: error
- OR AX,AX ;test count
- JZ filrwerr ;nothing done: error
- ES:
- MOV CX,[DI]$02 ;record length
- MOV DI,DX ;restore dest ofs
- ADD DI,AX ;add count read
- MOV ES,SI ;dest seg
- SUB CX,AX ;count to fill
- XOR AX,AX ;pad with zeroes
- CLD
- REPZ ;do fill
- STOS.B
- RET ;'
- filrwerr MOV AL,filerr ;error code -> error
- MOV errnum,AL
- filrwret RET ;"
- xseek XOR DX,DX ;Seek: clear high word
- seek1 POP errpos ;set error pos
- POP DI ;get file var ptr
- POP ES
- PUSH errpos ;restore ret
- ES:
- MOV CX,[DI]$02 ;get record length
- CALL cardmul ;* pos -> DX:AX
- MOV CX,DX ;-> CX:DX
- MOV DX,AX
- MOV AX,#$4200 ;seek absolute
- ES:
- MOV BX,[DI] ;file handle
- PUSH CX ;save pos wanted
- PUSH DX
- CALL dos ;do it
- POP CX ;restore pos wanted
- POP BX
- JB seekerr ;:error
- CMP AX,CX ;pos = expected ?
- JNZ seekerr ;:no
- CMP DX,BX
- JZ seekret ;:yes
- seekerr MOV.B errnum,#$91 ;Seek beyond EOF
- seekret RET ;"
- xlngseek CALL realcard ;LongSeek: convert real
- JMP seek1 ;"do it
- xeofty POP BX ;EOF typed, untyped
- POP ES ;get file var ptr
- PUSH BX ;restore ret
- MOV AX,#$4406 ;get unit status
- ES:
- MOV BX,[DI] ;file handle
- CALL dos ;do it
- OR.B AL,AL ;test result
- MOV AX,#$0000 ;false
- JNZ eoffalse ;:ok
- INC AX ;true
- eoffalse OR AX,AX ;set flags
- RET ;"
- xfilepos POP BX ;FilePos: ret addr
- POP ES ;file var ptr
- PUSH BX ;restore ret
- filpos1 MOV AX,#$4201 ;seek relative
- ES:
- MOV BX,[DI] ;file handle
- XOR CX,CX ;no offset
- XOR DX,DX
- CALL dos ;get position
- filpos2 ES:
- MOV CX,[DI]$02 ;record length
- JMP.b carddiv ;"pos / reclen -> filepos
- NOP ;LongFilePos
- xlfilpos POP BX ;return addr
- POP ES ;file var ptr
- PUSH BX ;restore ret
- CALL filpos1 ;do it
- JMP cardreal ;"result -> real
- xfilesiz POP BX ;FileSize: ret addr
- POP ES ;file var ptr
- PUSH BX ;restore ret
- filsiz1 MOV AX,#$4201 ;seek relative
- ES:
- MOV BX,[DI] ;file handle
- XOR CX,CX ;no offset
- XOR DX,DX
- CALL dos ;get current pos
- PUSH AX ;save it
- PUSH DX
- MOV AX,#$4202 ;seek from end
- ES:
- MOV BX,[DI] ;file handle
- XOR CX,CX ;no offset
- XOR DX,DX
- CALL dos ;get end position
- POP CX ;restore current pos
- POP BX
- PUSH AX ;save end pos
- PUSH DX
- MOV DX,BX ;restore file pos
- MOV AX,#$4200 ;seek absolute
- ES:
- MOV BX,[DI] ;file handle
- CALL dos ;go back to old pos
- POP DX ;end position
- POP AX
- ES:
- MOV CX,[DI]$02 ;(pos+reclen-1)
- DEC CX
- ADD AX,CX
- ADC DX,#$00
- JMP filpos2 ;"/ reclen -> position
- xlfilsiz POP BX ;LongFileSize: ret addr
- POP ES ;file var ptr
- PUSH BX ;restore ret
- CALL filsiz1 ;do it
- JMP cardreal ;"result -> real
- carddiv CMP CX,#$01 ;long cardinal division
- JZ cdret ;/ 1: done
- MOV SI,CX ;DX:AX / CX -> DX:AX
- XOR BX,BX ;clear result
- MOV CX,#$0021 ;32 bits
- cdloop RCL BX,1 ;shift in result
- SBB BX,SI ;try subtraction
- JNB cdbit1 ;:ok
- ADD BX,SI ;restore it
- STC
- cdbit1 CMC ;make flag to shift in
- RCL AX,1 ;shift in result
- RCL DX,1
- LOOP cdloop ;:another bit
- cdret RET ;"
- cardmul MOV BX,AX ;long card mul
- MOV AX,DX ;DX:AX * CX -> DX:AX
- MUL CX ;higher word
- XCHG AX,BX ;save it
- MUL CX ;lower word
- ADD DX,BX ;add higher result
- RET ;"
- xresetun XCHG AX,CX ;Reset untyped: record length
- POP BX ;ret addr
- POP DI ;file var ofs
- PUSH BX ;restore ret
- JMP xresetty ;"now like typed file
- xrewrtun XCHG AX,CX ;Rewrite untyped: record length
- POP BX ;ret addr
- POP DI ;file var ofs
- PUSH BX ;restore ret
- JMP xrewrtty ;"now like typed file
- xblkrd MOV filfunc,#$993F ;BlockRead
- JMP.b blrw1 ;'read, unexpected EOF
- xblkwr MOV filfunc,#$F040 ;BlockWrite
- blrw1 POP errpos ;write, disk write error
- POP DX ;var seg
- POP SI ;var ofs
- POP DI ;file var ptr
- POP ES
- PUSH AX ;save length
- CALL blrw ;do it
- POP CX ;restore len
- CMP.B errnum,#$00 ;error ?
- JNZ blrw1ok ;yes: return
- CMP AX,CX ;length = expected
- JZ blrw1ok ;:yes
- MOV AL,filerr ;error code -> error
- MOV errnum,AL
- blrw1ok JMP [errpos] ;"return
- xblkrdrd MOV filfunc,#$993F ;BlockRead with result var
- JMP.b blrwres ;'
- xblkwrrs MOV filfunc,#$F040 ;BlockWrite with result var
- blrwres POP errpos ;get error pos
- MOV CX,DI ;result var ptr
- POP BX
- POP AX ;length
- POP DX ;var seg
- POP SI ;var ofs
- POP DI ;file var ptr
- POP ES
- PUSH BX ;save result var ptr
- PUSH CX
- CALL blrw ;do it
- POP DI ;restore result var ptr
- POP ES
- ES:
- MOV [DI],AX ;store record count
- JMP [errpos] ;"return
- blrw ES: ;do Block-R/W
- CMP [DI]$02,#$00 ;record length = 0 ?
- JZ blrwerr ;yes: file not open
- ES:
- CMP [DI]$02,#$01 ;record len = 1 ?
- JZ blrwbyt ;:no calculation
- PUSH DX ;save
- ES:
- MUL [DI]$02 ;count * record length
- POP DX ;restore
- blrwbyt XCHG AX,CX ;length -> CX
- MOV.B AH,filfunc ;function code
- ES:
- MOV BX,[DI] ;file handle
- PUSH DS ;save DS
- MOV DS,SI ;var seg
- CALL dos ;do file operation
- POP DS ;restore DS
- JNB blrwok ;:ok
- MOV AL,filerr ;error code -> error
- MOV errnum,AL
- XOR AX,AX ;nothing read / written
- blrwok ES:
- MOV CX,[DI]$02 ;record length
- CMP CX,#$01 ;= 1 ?
- JZ blrwret ;yes: no division
- MOV DI,DX ;offset + count done
- ADD DI,AX
- XOR DX,DX ;clear hi
- DIV CX ;count done / record len
- OR DX,DX ;test remainder
- JZ blrwret ;:ok
- CMP.B filfunc,#$3F ;read ?
- JNZ blrwret ;no: end it
- PUSH AX ;save count done
- SUB CX,DX ;fill up the rest
- MOV ES,SI ;var seg
- XOR AX,AX ;with zeroes
- CLD
- REPZ ;do it
- STOS.B
- POP AX ;restore result
- INC AX ;+1
- blrwret RET ;'
- blrwerr MOV.B errnum,#$04 ;File not open
- RET ;"
- xerase POP errpos ;Erase
- POP ES ;file var ptr
- PUSH errpos ;restore ret
- MOV AH,#$41 ;delete file
- LEA DX,[DI]$0C ;ptr to filename
- PUSH DS ;save DS
- PUSH ES ;ES -> DS
- POP DS
- CALL dos ;do it
- POP DS ;restore DS
- JNB eraret ;:no error
- eraerr MOV.B errnum,#$01 ;file not found
- eraret RET ;"
- xrename POP errpos ;Rename
- CALL getpn ;convert string -> ASCIIZ
- POP DI ;file var ptr
- POP ES
- PUSH errpos ;restore ret
- MOV AH,#$56 ;Rename file
- LEA DX,[DI]$0C ;current file name
- PUSH DI ;save addr
- MOV DI,#pnbuf ;filename ptr
- PUSH DS ;ES <-> DS
- PUSH ES
- POP DS
- POP ES
- CALL dos ;do rename
- PUSH DS ;ES <-> DS
- PUSH ES
- POP DS
- POP ES
- POP DI ;restore addr
- JB eraerr ;:error
- MOV SI,#pnbuf ;copy new name into file var
- LEA DI,[DI]$0C ;file var offset
- MOV CX,#$0020 ;64 bytes
- CLD
- REPZ
- MOVS ;copy it
- RET ;"
- xchdir POP errpos ;ChDir: get error pos
- CALL getpn ;get path name
- PUSH errpos ;restore ret
- MOV AX,pnbuf ;get drive #
- OR.B AL,AL ;end of name ?
- JZ chdirret ;yes: return
- CMP.B AH,#$3A ;: ?
- JNZ chdir1 ;no: no drive specified
- CALL upcase ;upcase drive number
- SUB AL,#$41 ;- A
- JB eraerr ;<:error
- CMP AL,#$0F ;max. O
- JNB eraerr ;:error.
- ;Please note that MS-DOS now allows more drives !!!
- MOV AH,#$0E ;set default drive
- MOV.B DL,AL ;drive number
- CALL dos ;set it
- CMP.B pnbuf2,#$00 ;pathname ?
- JZ chdirret ;:none given
- chdir1 MOV AH,#$3B ;change dir
- chdir2 MOV DX,#pnbuf ;pointer to pathname
- CALL dos ;set it
- JB eraerr ;:error
- chdirret RET ;"
- xmkdir MOV BH,#$39 ;MkDir
- JMP.b rmdir1 ;'
- xrmdir MOV BH,#$3A ;RmDir
- rmdir1 POP errpos ;return addr -> error pos
- CALL getpn ;get path name
- PUSH errpos ;restore ret
- MOV.B AH,BH ;get function code
- JMP chdir2 ;"do it
- xgetdir POP errpos ;GetDir: CL=max. string len
- POP ES ;dest string
- POP AX ;drive number
- PUSH errpos ;restore ret
- OR.B AL,AL ;default drive ?
- JNZ gdnotdef ;:no
- MOV AH,#$19 ;get default drive number
- CALL dos
- INC.B AL ;+1
- gdnotdef MOV.B DL,AL ;drive number
- ADD AL,#$40 ;-> drive name
- MOV pnbuf,AL ;store in buffer
- MOV pnbuf1,#$5C3A ;store :\
- MOV AH,#$47 ;read current access path
- MOV SI,#pnbuf3 ;dest ptr
- CALL dos ;do it
- JNB gddone ;:ok
- MOV.B [SI],#$00 ;no path - mark end
- gddone MOV SI,#pnbuf ;pointer to path name
- XOR BX,BX ;clear len counter
- gdloop MOV.B AL,[SI] ;get char
- OR.B AL,AL ;end ?
- JZ gdend ;:yes
- INC SI ;next char
- INC BX ;count length
- ES:
- MOV.B [BX_DI],AL ;store in dest string
- DEC.B CL ;space available ?
- JNZ gdloop ;:yes
- gdend ES: ;store length
- MOV.B [DI],BL
- RET ;"
- xexecute MOV BX,#$2C7C ;Execute
- JMP.b chain1
- xchain XOR BX,BX ;Chain: load all of it
- chain1 POP errpos ;get ret addr
- POP ES ;file var ptr
- PUSH errpos ;restore ret
- TEST modeflg,#$0001 ;direct mode ?
- JNZ cherr2 ;yes: error
- PUSH BX ;save begin offset
- MOV AX,#$3D00 ;open file
- LEA DX,[DI]$0C ;ptr to filename
- CALL dos ;do it
- POP DX ;begin offset
- JB cherr1 ;:error
- MOV BX,AX
- MOV AX,#$4200 ;seek absolute
- XOR CX,CX ;clr hi word
- CALL dos ;do seek
- JB cherr1 ;:error
- PUSH DS ;save DS
- PUSH CS ;CS -> DS
- POP DS
- MOV AH,#$3F ;read byte block
- MOV CX,#$FFFF ;as much as possible
- MOV DX,#start ;destination
- CALL dos ;do it
- POP DS ;restore DS
- MOV AH,#$3E ;close file
- CALL dos
- MOV SP,spval ;restore SP
- CALL reinit2 ;reinit files, I/O
- MOV verror,#$10D0 ;set break vector
- JMP start2 ;'start - no memory init
- cherr1 MOV DL,#$01 ;File not found
- JMP operr ;'
- cherr2 MOV.B errnum,#$21 ;Not allowed in direct mode
- RET ;"
- start JMP.b kstart ;'skip message
- B "Licensed Material. Program Property of B"
- B "ORLAND." ;'
- kstart CALL readvers ;read version number
- MOV AX,#$9C06 ;(program size+15)/16
- MOV CL,#$04
- SHR AX,CL
- MOV DX,CS ;+CS -> DS
- ADD DX,AX
- MOV DS,DX
- CS:
- MOV AX,availmem ;top of memory
- SUB AX,DX
- MOV freemem,AX ;max memory size
- MOV BX,#$FFFE ;stack pointer
- SUB AX,#$1000 ;mem - 64K
- JNB kmembig ;:ok
- MOV BX,freemem ;max memory size
- MOV CL,#$04 ;small memory: SS at end of DS
- SHL BX,CL ;calc SP
- XOR AX,AX ;no segment offset
- kmembig ADD AX,DX ;add to DS
- MOV stackseg,AX ;-> stack segment
- MOV stackpt,BX ;-> stack pointer
- MOV AX,freemem ;max memory size
- SUB AX,#$0040 ;- 64 paragraphs
- CMP AX,#$1000 ;= 64K ?
- JB kmemlim ;:less
- MOV AX,#$1000 ;limit to 64K
- kmemlim MOV CL,#$04
- SHL AX,CL
- DEC AX
- MOV txmemend,AX ;store -> end of text space
- XOR AX,AX
- kmeminit MOV SS,stackseg ;set stack segment
- MOV SP,stackpt ;set stack pointer
- PUSH AX ;save flag
- MOV CX,#$0010 ;16 files
- CALL initio ;init files, I/O
- POP AX ;get flag
- OR AX,AX ;test it
- PUSH AX ;save it again
- JNZ kcrtinit ;:set
- CALL xcrtinit ;CrtInit
- kcrtinit CALL klowvid ;LowVideo
- CALL knrmvid ;NormVideo
- POP AX ;get flag
- OR AX,AX ;test it
- JZ kinitvar ;:init
- JMP kmainlp ;'go to main loop
- kinitvar MOV AX,#txstrt ;init vars
- MOV txbeg,AX ;beg of text
- MOV txend,AX ;end of text
- XOR AX,AX ;clear vars
- MOV mincssz,AX ;min CS-size = 0
- MOV mindssz,AX ;min DS-size = 0
- MOV minhpsz,#$0400 ;min free heap = 16K
- MOV maxhpsz,#$A000 ;max free heap = 640K
- MOV workpn,AL ;clear work filename
- MOV mainpn,AL ;clear main filename
- MOV parmlin,AL ;clear param line
- MOV errio,AL ;clear error
- MOV.B codedest,#$01 ;code destination: memory
- CALL inited ;init variables
- MOV AH,#$19 ;get default drive
- CALL dos
- MOV defdrv,AL ;store it
- CALL xclrscr ;ClrScr
- CALL prints ;write string
- B "---------------------------------------",$0D
- B $0A,"TURBO Pascal system ",$00
- CALL klowvid ;do LowVideo
- CALL prints ;write string
- B "Version 3.01A",$00
- CALL knrmvid ;do HighVideo
- CALL prints ;write string
- B $0D,$0A," ",$00
- CALL klowvid
- CALL prints
- B "PC-DOS",$00
- CALL knrmvid
- CALL prints
- B $0D,$0A,$0A,$00
- CALL klowvid
- CALL prints
- B "Copyright (C) 1983,84,85",$00
- CALL knrmvid
- CALL prints
- B " BORLAND Inc.",$0D,$0A,"-----------------------"
- B "----------------",$0D,$0A,$0A,$00
- MOV BX,#displstr ;write display type
- CALL putstr
- CALL prints
- B $0D,$0A,$0A,$0A,$0A,"Include error messages",$00
- CALL yornln ;Y or N ?
- MOV msgflg,AL ;store flag
- JZ kclr ;:no
- CALL kreaderr ;read error messages
- kclr CALL kclrtxt ;clear text
- CALL kmenu ;write menu
- kmainlp MOV SP,stackpt ;main loop: restore SP
- MOV BX,#kmainlp ;set a return addr
- PUSH BX
- CMP.B errio,#$00 ;error ?
- JZ kgetcmd ;:no
- JMP kdofind ;'search error
- kgetcmd CALL printatt ;write string with attributes
- B $8D,$8A,$BE,$00 ;CR,LF,>
- CALL knrmvid
- CALL keyget ;get command
- CALL upcase ;convert to upper case
- PUSH AX ;save it
- CALL xwriteln ;WriteLn
- POP AX ;restore command
- MOV SI,#kcmdtab ;ptr to command table
- CALL srchcmd ;search command
- JB kmenu ;not found: write menu
- CS:
- JMP [SI]$01 ;"execute command
- kreaddef CLD ;Transfer string into CON buffer
- MOV DI,#coninbuf ;dest ptr
- PUSH DS ;DS -> ES
- POP ES
- kreaddl LODS.B ;SI: source ptr
- STOS.B ;copy string
- OR.B AL,AL ;test for end
- JNZ kreaddl ;:no
- kreadln CALL prints ;Readln: write string
- B ": ",$00
- CALL rdedit ;read with editing
- MOV BX,#coninbuf ;buffer ptr
- CALL xwriteln ;WriteLn
- krdln1 MOV.B AL,[BX] ;get char from buffer
- CMP AL,#$1A ;^Z ?
- JZ krdlnret ;yes - end
- CMP AL,#$20 ;space ?
- JNZ krdlnret ;:no, ret
- INC BX ;skip spaces
- JMP krdln1 ;'continue scanning
- krdlnret RET ;"BX now points into buffer
- krdend CMP.B [BX],#$1A ;Test end of line
- RET ;"
- kmenu CALL knrmvid ;Write menu
- CALL xclrscr ;ClrScr
- CALL printatt
- B $CC,"ogged drive: ",$80,$00
- MOV AH,#$19 ;get default drive
- CALL dos
- ADD AL,#$41 ;convert to ASCII
- CALL conput ;write its name
- CALL printatt
- B $0D,$0A,$C1,"ctive directory: ",$DC,$00
- MOV AH,#$47 ;get active directory
- XOR.B DL,DL ;default drive
- MOV SI,#pnbuf ;dest buffer
- CALL dos ;do it: get pathname
- CALL printpn ;write that pathname
- CALL printatt
- B $0D,$0A,$0A,$D7,"ork file: ",$80,$00
- CALL kwworkpn ;write current filename
- CALL printatt
- B $0D,$0A,$CD,"ain file: ",$80,$00
- MOV SI,#mainpn ;main filename
- CALL printpn ;write it
- CALL printatt ;write command menu
- B $0D,$0A,$0A,$C5,"dit ",$C3,"ompile ",$D2,"un ",$D3
- B "ave",$0D,$0A,$0A,$C4,"ir ",$D1,"uit compiler ",$CF
- B "ptions",$0D,$0A,$0A,"Text: ",$00
- MOV AX,txend ;end of text
- SUB AX,txbeg ;- beg of text
- CALL kbytes ;print number
- CALL prints
- B "Free: ",$00
- MOV AX,txmemend ;top of text space
- SUB AX,txend ;- end of text
- kbytes CALL knumax ;print number
- CALL prints
- B " bytes",$0D,$0A,$00
- RET ;"
- kcdest DEC.B AL ;show code direction: this one ?
- JNZ kcdestno ;count it down: no
- CALL printatt
- B "compile -> ",$00
- RET ;'
- kcdestno CALL printatt ;clear field
- B " ",$00
- RET ;"
- optmenu MOV AX,#optmenu ;Option-menu
- PUSH AX ;put return addr
- optmenu2 CALL xclrscr ;ClrScr
- MOV AL,codedest ;code destination
- CALL kcdest ;show it
- CALL printatt
- B $CD,"emory",$0D,$0A,$00
- CALL kcdest ;show it
- CALL printatt
- B $C3,"om-file",$0D,$0A,$00
- CALL kcdest ;show it
- CALL printatt
- B "c",$C8,"n-file",$0D,$0A,$0A,$0A,$00
- CMP.B codedest,#$02 ;to COM-file ?
- JZ optmcom ;:yes
- JMP optmparm ;'
- optmcom CALL printatt ;display memory information
- B "minimum c",$CF,"de segment size: ",$00
- CALL knrmvid
- MOV AX,mincssz ;min CS size
- CALL whexword ;write hex
- CALL printatt
- B " (max ",$00
- MOV AX,#$2D8B ;-(runtime size+15)/16
- MOV CL,#$04
- SHR AX,CL
- NEG AX
- ADD AX,#$1000 ;+ 64K
- CALL kpara ;write paragraphs
- CALL printatt
- B ")",$0D,$0A,"minimum ",$C4,"ata segment size: ",$00
- CALL knrmvid
- MOV AX,mindssz ;min DS size
- CALL whexword ;write hex
- CALL printatt
- B " (max ",$00
- MOV AX,#$024F ;-(min vars used+15)/16
- MOV CL,#$04
- SHR AX,CL
- NEG AX
- ADD AX,#$1000 ;+ 64K
- CALL kpara ;write paragraphs
- CALL printatt
- B ")",$0D,$0A,"m",$C9,"nimum free dynamic memory: ",$00
- CALL knrmvid
- MOV AX,minhpsz ;min free heap
- CALL whexword ;write hex
- CALL klowvid
- CALL kparastr ;write paragraphs
- CALL printatt
- B $0D,$0A,"m",$C1,"ximum free dynamic memory: ",$00
- CALL knrmvid
- MOV AX,maxhpsz ;max free heap
- CALL whexword ;write hex
- CALL klowvid
- CALL kparastr ;write paragraphs
- JMP.b optmget
- optmparm CALL printatt
- B "command line ",$D0,"arameters: ",$00
- CALL knrmvid
- MOV SI,#parmlin ;display command line
- CALL kwstrsi
- optmget CALL printatt
- B $0D,$0A,$0A,$0A,$C6,"ind run-time error ",$D1,"uit",$0D
- B $0A,$0A,$BE,$00
- CALL knrmvid
- CALL keyget ;get command
- CALL upcase ;convert to upper case
- PUSH AX ;save it
- CALL xwriteln ;WriteLn
- POP AX ;restore cmd
- MOV SI,#ocmdtab ;ptr to command table
- CALL srchcmd ;search command
- JNB optexe ;:ok
- JMP optmenu2 ;'not found - repeat
- optexe CS:
- JMP [SI]$01 ;"execute command
- yornln CALL yorn ;Y or N ?
- PUSHF ;save result
- PUSH AX
- CALL xwriteln ;WriteLn
- POP AX ;restore result
- POPF
- RET ;"
- yorn CALL prints ;Y or N ?
- B " (Y/N)? ",$00
- yornlp CALL keyget ;get char
- CALL upcase ;convert to upper
- CMP AL,#$59 ;Y ?
- JZ yornok ;:yes
- CMP AL,#$4E ;N ?
- JNZ yornlp ;no: loop back
- yornok PUSH AX ;save key
- CALL conput ;display choice
- POP AX ;restore it
- SUB AL,#$4E ;set flags:
- RET ;"0=no
- waitesc CALL prints ;Wait for ESC
- B ". Press <ESC>",$00
- waitescl CALL keyget ;get char
- CMP AL,#$1B ;ESC ?
- JNZ waitescl ;:no, wait
- RET ;"
- srchcmd CS: ;Search command in table
- CMP.B AL,[SI] ;compare it
- JZ srcmdfnd ;:found
- ADD SI,#$03 ;go to next entry
- CS:
- CMP.B [SI],#$00 ;end of table ?
- JNZ srchcmd ;:no
- STC ;not found !
- srcmdfnd RET ;"
- kcmdtab B "L" ;main command table
- W klogged
- B "A"
- W kactdir
- B "W"
- W kwork
- B "M"
- W kmain
- B "E"
- W editor
- B "C"
- W kcomp
- B "R"
- W krun
- B "S"
- W ksave
- B "D"
- W kdir
- B "O"
- W optmenu
- B "Q"
- W kquit
- B $00 ;"end of table
- B "M" ;option command table
- W kmem
- B "C"
- W kcom
- B "H"
- W kchn
- B "O"
- W kcs
- B "D"
- W kds
- B "I"
- W kss
- B "A"
- W kmss
- B "P"
- W kparm
- B "F"
- W kfind
- B "Q"
- W optquit
- B $00 ;"end of table
- optquit POP AX ;Quit submenu
- JMP kmenu ;"jump to main menu
- ;pathname of message file (installed by TINST)
- errpath B "TURBO.MSG",$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
- B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ;"
- extpas B $04,".PAS" ;table of file extensions
- extcom B $04,".COM"
- extbak B $04,".BAK"
- extchn B $04,".CHN" ;"
- fnpath B $04,"\*.*" ;search parameters
- fnany B $03,"*.*" ;"
- kmain CALL prints ;M:Main file name
- B $0D,$0A,"Main file name",$00
- CALL knocode ;flag: text not compiled
- MOV SI,#mainpn ;pointer to pathname
- CALL kreaddef ;Enter new name
- MOV.B mainpn,#$00 ;mark end
- JZ kmret ;:nothing read
- CALL kpasext ;parse filename
- MOV DI,#mainpn ;dest buffer
- CALL fnscdi ;copy to main file name
- kmret RET ;"
- ;W:Work file name
- kwork MOV vnewfil,#flnew ;set error vec: new file
- CALL ksvchng ;save, if changed
- CALL prints
- B $0D,$0A,"Work file name",$00
- MOV SI,#workpn ;ptr work file name
- CALL kreaddef ;Enter new name
- MOV.B workpn,#$00 ;mark end
- JNZ kwok ;:something read
- CALL kclrtxt ;clear text
- JMP kmainlp ;'back to main menu
- kwok CALL kpasext ;parse filename
- MOV DI,#workpn ;copy to work file name
- CALL fnscdi
- JMP.b kw2 ;'now load it
- kwload MOV vnewfil,#flescclr ;set error vec: not found
- kw2 MOV vfilbig,#flbigclr ;set error vec: too big
- CALL kclrtxt ;clear text
- MOV SI,#workpn ;work file name
- kwload2 MOV BX,txbeg ;beg of text
- PUSH BX ;save parms
- PUSH SI
- CALL clred ;clear editor vars
- POP SI
- POP BX ;restore
- MOV DX,BX ;begin addr
- MOV CX,txmemend ;end of space
- CALL kload ;load file
- INC BX
- MOV txend,BX ;set end of text
- RET ;"
- kload PUSH DX ;Load file: save start pos
- PUSH CX ;save end pos
- CALL fnsisc ;copy pathname[SI]
- CALL prints
- B $0D,$0A,"Loading ",$00
- CALL kwscrpn ;write pathname
- MOV AX,#$3D00 ;open file
- MOV DX,#scrpn ;current pathname
- PUSH DS ;DS -> ES
- POP ES
- CALL dos ;do it
- MOV BX,AX ;file handle
- POP CX ;restore parms
- POP DX
- JB flntfnd ;:error
- kload2 SUB CX,DX ;calc max length
- MOV AH,#$3F ;read byte block
- CALL dos ;do it
- JB flntfnd ;:error
- CMP AX,CX ;length = expected ?
- JZ fltoobig ;yes: too big !
- XCHG AX,CX ;get length done
- MOV DI,DX ;end addr
- PUSH DS ;DS -> ES
- POP ES
- MOV AL,#$1A ;search ^Z in the block
- CLD
- REPNZ
- SCAS.B
- JNZ klnoeof ;:not found
- DEC DI ;go back one byte
- klnoeof MOV AH,#$3E ;close file
- CALL dos
- DEC DI
- MOV BX,DI ;end pos of text read
- RET ;"
- fltoobig CALL klnoeof ;file too large: close file
- MOV BX,DX ;end of text space
- INC BX ;+1
- JMP [vfilbig] ;"handle error
- flntfnd MOV BX,DX ;file not found
- DEC BX ;end addr
- JMP [vnewfil] ;"handle error
- flesc CALL xwriteln ;File not found - ESC
- CALL vidattr3 ;attribute #3
- CALL prints
- B "File not found",$00
- flesc2 CALL waitesc ;wait for ESC
- JMP knrmvid ;"HighVideo
- flescclr CALL flesc ;file not found - ESC
- JMP.b flclr ;"clear work file name
- flnew CMP AL,#$03 ;New file: test error code
- JZ fldir ;:invalid dir
- CALL xwriteln ;WriteLn
- CALL vidattr2 ;attribute #2
- CALL prints
- B "New File",$00
- CALL knrmvid
- PUSH BX ;save end pos
- MOV BX,#$07D0 ;wait 2 s
- CALL delaybx
- POP BX ;restore
- RET ;'
- fldir CALL xwriteln ;WriteLn
- CALL vidattr3 ;Attribute #3
- CALL prints
- B "Invalid directory",$00
- JMP.b flclr ;"clear work file name
- flbig CALL xwriteln ;File too big
- CALL vidattr3
- CALL prints
- B "File too big",$00
- MOV BX,txend ;end of text-1 -> BX
- DEC BX
- JMP flesc2 ;"wait for ESC
- flbigclr CALL flbig ;file too big
- flclr MOV.B workpn,#$00 ;clear work file name
- JMP kmainlp ;"main loop
- ksvchng XOR AX,AX ;Save if modified
- INC AX ;set flag
- JMP.b ksv2 ;'
- ksvnoask XOR AX,AX
- ksv2 CMP.B txchg,#$00 ;text changed ?
- JZ ksvret ;:no - ret
- OR AX,AX ;test flag
- JZ ksave
- CALL prints
- B "Workfile ",$00
- CALL kwworkpn ;write path name
- CALL prints
- B " not saved. Save",$00
- MOV.B txchg,#$00 ;clear change flag
- CALL yornln ;Y or N ?
- JNZ ksave ;:yes
- ksvret RET ;'
- ksave CALL kgetfn ;S:Save file - get filename
- MOV.B txchg,#$00 ;clear change flag
- MOV SI,#workpn ;ptr work file name
- CALL fnsisc ;copy it
- CALL prints
- B $0D,$0A,"Saving ",$00
- CALL kwworkpn ;write path name
- MOV DI,#pnbuf
- CALL fnscdi ;copy filename into buffer
- MOV SI,#extbak ;extension .BAK
- CALL kext ;modify file name
- MOV AH,#$41 ;delete old .BAK file
- MOV DX,#scrpn ;scratch file name
- CALL dos ;do it
- MOV AH,#$56 ;rename file
- MOV DX,#pnbuf ;current filename
- MOV DI,#scrpn ;new filename
- CALL dos ;do it: rename to .BAK
- MOV AH,#$3C ;create new file
- XOR CX,CX ;no attribute
- MOV DX,#pnbuf ;current filename
- PUSH DS ;DS -> ES
- POP ES
- CALL dos ;do create
- JB ksren ;:error
- XCHG AX,BX ;file handle
- MOV DX,txbeg ;beg -> offset
- MOV CX,txend ;end of text
- MOV DI,CX
- MOV.B [DI],#$1A ;store ^Z at the end
- SUB CX,DX ;calc length
- INC CX ;+1
- MOV AH,#$40 ;write byte block
- CALL dos ;do it
- JB kserr ;:error
- CMP AX,CX ;length = expected ?
- JNZ kserr ;:no
- JMP klnoeof ;'close that file
- kserr MOV.B txchg,#$FF ;set changed flag
- CALL klnoeof ;close that file
- MOV AH,#$41 ;erase new file
- MOV DX,#pnbuf
- CALL dos
- ksren MOV AH,#$56 ;rename it back to .PAS
- MOV DX,#scrpn ;.BAK
- MOV DI,#pnbuf ;-> .PAS
- CALL dos ;do it
- CALL xwriteln ;WriteLn
- CALL ksfull ;write message
- JMP kmainlp ;"return to main menu
- ksfull CALL vidattr3 ;File not saved
- CALL prints
- B "Disk full or invalid directory path",$00
- CALL waitesc ;wait for ESC
- JMP knrmvid ;"
- kdir CALL prints ;D:Directory
- B "Dir mask",$00
- CALL kreadln ;enter dir mask
- MOV CX,#$000D ;*, ? allowed
- CALL kparse2 ;parse filename
- CALL krdend ;line end ?
- MOV AH,#$1A ;set DMA transfer addr
- MOV DX,#pnbuf ;buffer
- CALL dos
- MOV SI,#scrpn ;test pathname
- kdtest MOV.B AL,[SI] ;get char
- INC SI ;go to next
- CMP AL,#$2A ;* ?
- JZ kddoit ;:yes
- CMP AL,#$3F ;?
- JZ kddoit ;:yes
- OR.B AL,AL ;end of string ?
- JNZ kdtest ;:no
- MOV.B AL,[SI]-$02 ;get last char
- MOV SI,#fnany ;ptr to *.*
- CMP AL,#$3A ;: ?
- JZ kdwrit ;:yes
- CMP AL,#$5C ;\ ?
- JZ kdwrit ;:yes
- MOV AH,#$4E ;search first dir entry
- MOV CX,#$0010 ;attribute
- MOV DX,#scrpn ;pathname
- CALL dos ;do it
- JB kddoit ;:error
- TEST.B pndiratt,#$10 ;attribute ok ?
- JZ kddoit ;yes, take it
- MOV SI,#fnpath ;ptr to \*.*
- kdwrit CALL kext2
- kddoit CALL prints
- B "Directory of ",$00
- CALL kwscrpn ;write path name
- CALL xwriteln ;WriteLn
- MOV AH,#$4E ;get first entry
- MOV CX,#$0010 ;attribute
- MOV DX,#scrpn ;path name
- CALL dos ;do it
- JB kderr ;:error
- XOR.B DL,DL ;clear flag
- kddis OR.B DL,DL ;test flag
- JNZ kdnocr ;:not first entry in line
- CS:
- MOV AL,txwinx2 ;line length / 16
- XOR.B AH,AH
- MOV DL,#$10
- DIV.B DL
- MOV.B DL,AL
- kdnocr MOV SI,#pndirnm ;ptr to filename
- TEST.B [SI]-$09,#$10 ;test attribute
- JZ kdnodir ;:ok
- CMP.B [SI],#$2E ;directory ?
- JZ kdnext
- CALL klowvid ;LowVideo
- kdnodir CALL printpn ;write name
- CALL knrmvid ;NormVideo
- DEC.B DL ;another one in this line ?
- JZ kdnextln ;:no
- MOV CX,#pndirpad ;end for padding
|