TPSRC4 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. readst POP errpos ;get ret addr
  2. MOV currfil,#stdin ;from std input
  3. MOV currfil1,DS
  4. AND.B stdinfl,#$DF ;clear flag: char read
  5. PUSH ES ;save dest var ptr
  6. PUSH DI
  7. PUSH AX ;save flag
  8. CALL rdedit ;read with editing
  9. POP AX ;restore flag
  10. OR.B AL,AL ;readln ?
  11. JZ readst2 ;:no
  12. CALL xwriteln ;do WriteLn
  13. readst2 POP DI ;restore dest var ptr
  14. POP ES
  15. JMP [errpos] ;"return
  16. rdedit XOR.B DH,DH ;Read line with editing: clr flag
  17. rdedit2 MOV.B CH,conbufln ;buffer length
  18. CMP.B CH,#$7E ;too big ?
  19. JB relimlen ;:no
  20. MOV CH,#$7E ;limit to 127 chars
  21. relimlen MOV.B conbufln,#$7E ;127 chars again
  22. MOV BX,#coninbuf
  23. MOV conbufpt,BX ;set input ptr
  24. rezero XOR.B CL,CL ;ptr into line
  25. reloop CALL keyget ;get char
  26. MOV DL,#$01 ;flag: one char
  27. CMP AL,#$08 ;BS ?
  28. JZ rebs ;:yes
  29. CMP AL,#$7F ;Delete ?
  30. JZ rebs ;:yes
  31. CMP AL,#$04 ;^D ?
  32. JZ recall ;yes, recall char from buffer
  33. DEC.B DL ;flag: all chars
  34. CMP AL,#$18 ;^X ?
  35. JZ rebs ;yes:erase input line
  36. CMP AL,#$1B ;ESC ?
  37. JZ rebs ;yes:erase input line
  38. CMP AL,#$12 ;^R ?
  39. JZ recall ;yes:recall last input line
  40. CMP AL,#$1A ;^Z ?
  41. JZ reeof ;:yes
  42. CMP AL,#$0D ;CR ?
  43. JZ recr ;:yes
  44. CMP AL,#$20 ;other control char ?
  45. JB reloop ;yes: ignore
  46. CMP.B CL,CH ;end of buffer reached ?
  47. JZ reloop
  48. MOV.B AH,[BX] ;get old char
  49. MOV.B [BX],AL ;store new char
  50. INC.B CL ;new pos
  51. INC BX
  52. CMP.B AH,#$20 ;was it old end of buffer ?
  53. JNB renotend ;:no
  54. MOV.B [BX],AH ;mark it again
  55. renotend CALL xputch ;display new char
  56. JMP reloop ;'next key
  57. rebs DEC.B CL ;go back one char
  58. JS rezero ;:beg of line
  59. CALL prints ;go back one char
  60. B $08," ",$08,$00
  61. DEC BX ;go back
  62. DEC.B DL ;another char ?
  63. JNZ rebs ;:yes
  64. JMP reloop ;'next key
  65. recall MOV.B AL,[BX] ;recall from buffer
  66. CMP AL,#$20 ;end of buffer
  67. JB reloop ;:yes
  68. CALL xputch ;display that char
  69. INC.B CL ;next one
  70. INC BX
  71. DEC.B DL ;another one ?
  72. JNZ recall ;:yes
  73. JMP reloop ;'next key
  74. reeof OR.B DH,DH ;test flag
  75. JZ reloop ;:no EOF allowed
  76. JMP.b resto ;'store it
  77. recr OR.B DH,DH ;test flag
  78. JNZ reend ;:no ^Z needed
  79. resto MOV.B [BX],#$1A ;store ^Z
  80. JMP.b reend2 ;'end it
  81. reend CALL xwriteln ;WriteLn
  82. MOV [BX],#$0A0D ;store CR,LF at end
  83. INC BX ;2 chars added
  84. reend2 INC BX ;1 char added
  85. MOV conbfend,BX ;store end pointer
  86. RET ;"
  87. xputch MOV.B AH,cbreak ;Put char: save break flag
  88. MOV.B cbreak,#$00 ;break allowed
  89. PUSH AX ;save flag
  90. CALL conput ;print char
  91. POP AX ;restore flag
  92. MOV.B cbreak,AH
  93. RET ;"
  94. getbyte LES DI,currfil ;Get byte from current file
  95. getbyte2 CMP.B errnum,#$00 ;error ?
  96. JNZ gbeof ;yes: return ^Z
  97. ES:
  98. MOV.B AL,[DI]$02 ;test flags:
  99. TEST AL,#$20 ;char pre-read ?
  100. JNZ gbfrbuf ;yes: return it
  101. AND AL,#$0F ;device ?
  102. JNZ gbdev ;:yes
  103. ES:
  104. MOV BX,[DI]$08 ;buffer pointer
  105. ES:
  106. CMP BX,[DI]$0A ;= buffer end ?
  107. JB gbnotend ;:no
  108. CALL gbrdbuf ;read buffer
  109. ES:
  110. MOV BX,[DI]$08 ;buffer ptr
  111. gbnotend ES:
  112. MOV.B AL,[BX] ;get byte
  113. INC BX ;advance ptr
  114. ES:
  115. MOV [DI]$08,BX ;store ptr
  116. JMP.b gbbuf2 ;'remember that char
  117. gbdev PUSH ES ;save file ptr
  118. PUSH DI ;test devices
  119. CMP AL,#$01 ;CON ?
  120. JNZ gbkbd ;:no
  121. MOV BX,conbufpt ;get from CON input buffer
  122. CMP BX,conbfend ;end of buffer reached ?
  123. JB gbget ;no: return char
  124. MOV.B DH,AL ;^Z allowed
  125. CALL rdedit2 ;read line
  126. MOV BX,conbufpt ;ptr to char
  127. gbget MOV.B AL,[BX] ;get char
  128. INC BX ;advance ptr
  129. MOV conbufpt,BX ;update ptr
  130. JMP.b gbbuf ;'done
  131. gbkbd CMP AL,#$02 ;KBD ?
  132. JNZ gbaux ;:no
  133. DEC SP ;(function:char)
  134. CALL [vkbdget] ;get char
  135. JMP.b gbbuf ;'return it
  136. gbaux CMP AL,#$04 ;AUX ?
  137. JNZ gbusr ;:no
  138. DEC SP
  139. CALL [vauxget] ;get char
  140. JMP.b gbbuf ;'return it
  141. gbusr DEC SP ;USR
  142. CALL [vusrget] ;get char
  143. gbbuf POP DI ;restore file var ptr
  144. POP ES
  145. gbbuf2 ES:
  146. MOV.B [DI]$03,AL ;store char in buffer
  147. ES:
  148. OR.B [DI]$02,#$20 ;set flag: char pre-read
  149. RET ;'
  150. gbfrbuf ES:
  151. MOV.B AL,[DI]$03 ;get char from buffer
  152. RET ;'
  153. gbeof MOV AL,#$1A ;return ^Z = EOF
  154. RET ;'
  155. gbrdbuf MOV AH,#$3F ;read buffer
  156. ES:
  157. MOV BX,[DI] ;file handle
  158. ES:
  159. MOV CX,[DI]$06 ;buffer size
  160. ES:
  161. MOV DX,[DI]$04 ;buffer offset
  162. PUSH DS ;save DS
  163. PUSH ES ;ES -> DS
  164. POP DS
  165. CALL dos ;do it
  166. POP DS ;restore DS
  167. JNB gbnoerr ;:no error
  168. XOR AX,AX ;nothing read
  169. gbnoerr ES:
  170. MOV BX,[DI]$04 ;buffer offset
  171. OR AX,AX ;anything read ?
  172. JNZ gbmakeof ;:yes
  173. ES:
  174. MOV.B [BX],#$1A ;store a ^Z
  175. INC AX ;1 char read
  176. gbmakeof ES:
  177. MOV [DI]$08,BX ;-> buffer pointer
  178. ADD BX,AX ;+ number chars read
  179. ES:
  180. MOV [DI]$0A,BX ;-> buffer end
  181. RET ;"
  182. readnum PUSH ES ;Read number
  183. PUSH DI ;save ptr
  184. MOV BX,#pnbuf ;buffer ptr
  185. rnspace PUSH BX ;save
  186. CALL getbyte ;get char
  187. POP BX ;restore ptr
  188. CMP AL,#$1A ;^Z ?
  189. JZ rnend ;yes: end
  190. ES:
  191. AND.B [DI]$02,#$DF ;clear flag: char pre-read
  192. CMP AL,#$20 ;space / control ?
  193. JBE rnspace ;yes: ignore
  194. rndig MOV.B [BX],AL ;store that char
  195. INC BX ;advance ptr
  196. CMP BX,#pnbufend ;end reached ?
  197. JZ rnend ;:yes
  198. PUSH BX ;save ptr
  199. CALL getbyte ;get char
  200. POP BX ;restore ptr
  201. CMP AL,#$20 ;space / control ?
  202. JBE rnend ;yes: end
  203. ES:
  204. AND.B [DI]$02,#$DF ;clear flag: char pre-read
  205. JMP rndig ;'next digit
  206. rnend MOV.B [BX],#$00 ;store a 0 at the end
  207. MOV BX,#pnbuf ;nothing entered ?
  208. CMP.B [BX],#$00
  209. POP DI ;restore ptr
  210. POP ES
  211. RET ;"
  212. chknum JB cnerr ;Check numeric format
  213. CMP.B [BX],#$00 ;end reached ?
  214. JZ cnret ;yes: ok
  215. cnerr MOV.B errnum,#$10 ;Error in numeric format
  216. STC
  217. cnret RET ;"
  218. xrdchar PUSH DI ;Read char: save ptr
  219. CALL getbyte ;get char
  220. ES:
  221. AND.B [DI]$02,#$DF ;clear flag: char pre-read
  222. POP DI ;var ofs
  223. POP BX ;ret addr
  224. POP ES ;var seg
  225. ES:
  226. MOV.B [DI],AL ;store char
  227. JMP BX ;"return
  228. xrdbyte CLC ;Read byte
  229. JMP.b rdi1 ;'
  230. xrdint STC ;Read integer
  231. rdi1 POP BX ;ret addr
  232. POP ES ;dest seg
  233. PUSH BX ;restore ret
  234. PUSHF ;save flag
  235. CALL readnum ;read number.
  236. JZ rdierr ;:nothing entered
  237. CALL ascint ;convert to integer
  238. CALL chknum ;check numeric format
  239. JB rdierr ;:error
  240. POPF ;restore flag
  241. JNB rdibyt ;:byte
  242. ES:
  243. MOV [DI],AX ;store integer
  244. RET ;'
  245. rdibyt ES:
  246. MOV.B [DI],AL ;store byte
  247. RET ;'
  248. rdierr POPF ;remove flag
  249. RET ;"error - don't change var
  250. xrdreal POP BX ;Read real
  251. POP ES ;dest seg
  252. PUSH BX ;restore ret
  253. CALL readnum ;read number
  254. JZ rdrret ;:nothing entered
  255. PUSH DI ;save dest ptr
  256. PUSH ES
  257. MOV DI,#prnum ;dest var
  258. CALL ascreal ;convert to real
  259. MOV SI,DI ;-> source ptr
  260. POP ES ;restore dest ptr
  261. POP DI
  262. CALL chknum ;check numeric format
  263. JB rdrret ;:error
  264. CLD ;store real number
  265. MOVS
  266. MOVS
  267. MOVS
  268. rdrret RET ;"
  269. xrdstr POP BX ;Read string var
  270. POP ES ;dest seg
  271. PUSH BX ;restore ret
  272. XOR BX,BX ;clear length of string
  273. XOR.B CH,CH ;count. CL=max len
  274. rdsloop PUSH ES ;save dest ptr
  275. PUSH DI
  276. PUSH BX ;save len, cnt
  277. PUSH CX
  278. CALL getbyte ;get char
  279. POP CX ;restore
  280. POP BX
  281. CMP AL,#$0D ;CR ?
  282. JZ rdsend ;:end
  283. CMP AL,#$1A ;^Z ?
  284. JZ rdsend ;:end
  285. ES:
  286. AND.B [DI]$02,#$DF ;clear flag: char pre-read
  287. POP DI ;restore dest ptr
  288. POP ES
  289. INC BX ;count len
  290. ES:
  291. MOV.B [BX_DI],AL ;store char
  292. LOOP rdsloop ;:another char
  293. JMP.b rdslen ;'store length
  294. rdsend POP DI ;restore dest ptr
  295. POP ES
  296. rdslen ES:
  297. MOV.B [DI],BL ;store length
  298. RET ;"
  299. xrdarrch POP BX ;Read array of char
  300. POP ES ;dest ptr
  301. PUSH BX ;restore ret
  302. XOR.B CH,CH ;CL=max len
  303. rdacloop PUSH ES ;save dest ptr
  304. PUSH DI
  305. PUSH CX ;save cnt
  306. CALL getbyte ;get a char
  307. POP CX ;restore cnt
  308. CLD
  309. CMP AL,#$0D ;CR ?
  310. JZ rdacend ;yes: end
  311. CMP AL,#$1A ;^Z ?
  312. JZ rdacend ;:yes
  313. ES:
  314. AND.B [DI]$02,#$DF ;clear flag: char pre-read
  315. POP DI ;restore dest ptr
  316. POP ES
  317. STOS.B ;store char
  318. LOOP rdacloop ;:another char
  319. RET ;'
  320. rdacend POP DI ;restore dest ptr
  321. POP ES
  322. MOV AL,#$20 ;pad with spaces
  323. REPZ
  324. STOS.B
  325. RET ;"
  326. xreadln CALL getbyte ;Readln: get char
  327. CMP AL,#$1A ;^Z ?
  328. JZ rdlnret ;yes: done
  329. ES:
  330. AND.B [DI]$02,#$DF ;clear flag: char pre-read
  331. CMP AL,#$0A ;LF ?
  332. JZ rdlnret ;yes: done
  333. CMP AL,#$0D ;CR ?
  334. JNZ xreadln ;no: continue
  335. CALL getbyte ;get next char
  336. CMP AL,#$0A ;LF ?
  337. JNZ rdlnret ;no: forget it
  338. ES:
  339. AND.B [DI]$02,#$DF ;clear flag: char pre-read
  340. rdlnret RET ;"
  341. putbyte LES DI,currfil ;put char to current file
  342. CMP.B errnum,#$00 ;error ?
  343. JNZ pbret ;yes: no output
  344. ES:
  345. MOV.B CL,[DI]$02 ;get flag
  346. AND.B CL,#$0F ;device ?
  347. JNZ pbdev ;:yes
  348. ES:
  349. MOV BX,[DI]$08 ;get buffer pointer
  350. ES:
  351. MOV.B [BX],AL ;store char
  352. INC BX ;advance pointer
  353. ES:
  354. MOV [DI]$08,BX ;update pointer
  355. ES:
  356. CMP BX,[DI]$0A ;= buffer end ?
  357. JZ pbflush ;yes: do flush
  358. RET ;'
  359. pbdev PUSH AX ;put char as parameter
  360. CMP.B CL,#$01 ;CON ?
  361. JZ pbcon ;:yes
  362. CMP.B CL,#$03 ;LST ?
  363. JZ pblst ;:yes
  364. CMP.B CL,#$04 ;AUX ?
  365. JZ pbaux ;:yes
  366. CALL [vusrput] ;USR out
  367. RET ;'
  368. pbcon CALL [vconput] ;CON out
  369. RET ;'
  370. pblst CALL [vprnput] ;LST out
  371. RET ;'
  372. pbaux CALL [vauxput] ;AUX out
  373. pbret RET ;'
  374. pbflush ES: ;flush output buffer
  375. MOV CX,[DI]$08 ;count=pointer-offset
  376. ES:
  377. SUB CX,[DI]$04
  378. JZ pbok ;:nothing to write
  379. MOV AH,#$40 ;write byte block
  380. ES:
  381. MOV BX,[DI] ;file handle
  382. ES:
  383. MOV DX,[DI]$04 ;buffer offset
  384. ES:
  385. MOV [DI]$08,DX ;reset buffer pointer
  386. PUSH DS ;save DS
  387. PUSH ES ;ES -> DS
  388. POP DS
  389. CALL dos ;do it
  390. POP DS ;restore DS
  391. JB pberr ;:error
  392. CMP AX,CX ;length = expected ?
  393. JZ pbok ;:yes
  394. pberr MOV.B errnum,#$F0 ;Disk write error
  395. pbok RET ;"
  396. xwrchar OR AX,AX ;Write char
  397. JZ wchdoit ;AX=formatting parm: nothing
  398. CALL limstind ;limit it
  399. CMP AL,#$01 ;<= 1 char ?
  400. JBE wchdoit
  401. XCHG AX,CX ;-> count
  402. DEC CX ;-1 for char itself
  403. wchpad MOV AL,#$20 ;put spaces
  404. PUSH CX ;save count
  405. CALL putbyte ;put it
  406. POP CX ;restore count
  407. LOOP wchpad ;:continue
  408. wchdoit POP BX ;ret addr
  409. POP AX ;get char
  410. PUSH BX ;restore ret
  411. JMP putbyte ;"put that char
  412. xwrint XCHG AX,CX ;Write integer: format parm
  413. POP BX ;return addr
  414. POP AX ;get number
  415. PUSH BX ;restore ret
  416. PUSH CX ;save format parm
  417. MOV BX,#pnbuf ;dest buffer
  418. CALL intasc ;Integer -> ASCII
  419. wintbuf POP AX ;restore format parm
  420. CALL limstind ;limit it
  421. SUB BX,#pnbuf ;calc length
  422. SUB AX,BX ;length of spaces ?
  423. JBE wintdoit ;:no space left
  424. XCHG AX,CX ;-> count
  425. PUSH BX ;save number length
  426. wintpad MOV AL,#$20 ;put spaces
  427. PUSH CX ;save count
  428. CALL putbyte ;put it
  429. POP CX ;restore count
  430. LOOP wintpad ;:another space
  431. POP BX ;restore number length
  432. wintdoit MOV CX,BX ;-> count
  433. MOV BX,#pnbuf ;buffer ptr
  434. wintloop MOV.B AL,[BX] ;get char
  435. PUSH BX ;save ptr, cnt
  436. PUSH CX
  437. CALL putbyte ;put it
  438. POP CX ;restore
  439. POP BX
  440. INC BX ;next char
  441. LOOP wintloop ;:again
  442. RET ;"
  443. xwrreal XCHG AX,DX ;Write real: second format parm
  444. POP BX ;ret addr
  445. POP CX ;first format parm
  446. MOV DI,#prnum ;get number from stack
  447. POP [DI]
  448. POP [DI]$02
  449. POP [DI]$04
  450. PUSH BX ;restore ret
  451. PUSH CX ;push format parm
  452. MOV BX,#pnbuf ;dest buffer
  453. CALL fmtreal ;Real -> ASCII
  454. JMP wintbuf ;"write buffer
  455. xwrbool POP BX ;write boolean
  456. POP CX ;get boolean
  457. PUSH BX ;restore ret
  458. MOV DI,#sttrue ;(true)
  459. OR CX,CX ;test boolean
  460. JNZ wbotrue ;:true
  461. MOV DI,#stfalse ;(false)
  462. wbotrue PUSH CS ;str segment
  463. CALL strload ;load string
  464. CALL xwrtstr ;write string
  465. RET ;"
  466. sttrue B $04,"TRUE"
  467. stfalse B $05,"FALSE" ;"
  468. xwrtstr CALL limstind ;Write string: format parm
  469. MOV BX,SP ;pos of string
  470. INC BX ;skip ret addr
  471. INC BX
  472. SS:
  473. SUB.B AL,[BX] ;field len - string len
  474. JBE wstdoit ;:too much - no padding
  475. MOV.B CL,AL ;-> count
  476. XOR.B CH,CH
  477. PUSH BX ;save string pos
  478. wstpad MOV AL,#$20 ;put spaces
  479. PUSH CX ;save count
  480. CALL putbyte ;put it
  481. POP CX ;restore count
  482. LOOP wstpad ;:another space
  483. POP BX ;restore string pos
  484. wstdoit SS:
  485. MOV.B CL,[BX] ;get length
  486. XOR.B CH,CH ;-> count
  487. INC BX ;point to first char
  488. OR CX,CX ;nothing to write ?
  489. JZ wstnil ;:yes
  490. wstloop SS:
  491. MOV.B AL,[BX] ;get char
  492. PUSH BX ;save ptr, cnt
  493. PUSH CX
  494. CALL putbyte ;put char
  495. POP CX ;restore
  496. POP BX
  497. INC BX ;next char
  498. LOOP wstloop ;:another
  499. wstnil POP DX ;ret addr
  500. MOV SP,BX ;remove string from stack
  501. JMP DX ;"return
  502. xwrtinl POP BX ;Write inline string
  503. CS:
  504. MOV.B CL,[BX] ;get length
  505. XOR.B CH,CH ;-> count
  506. INC BX ;point to first char
  507. JCXZ wstinil ;:null string
  508. wstiloop CS:
  509. MOV.B AL,[BX] ;get char
  510. PUSH BX ;save
  511. PUSH CX
  512. CALL putbyte ;put char
  513. POP CX
  514. POP BX ;restore
  515. INC BX ;next char
  516. LOOP wstiloop ;:another
  517. wstinil JMP BX ;"return - text skipped
  518. xwrln MOV AL,#$0D ;WriteLn
  519. CALL putbyte ;put CR
  520. MOV AL,#$0A
  521. JMP putbyte ;"put LF
  522. xseekeol MOV DX,#$010D ;SeekEOLN
  523. JMP.b seox1 ;'
  524. xeoln MOV DX,#$000D ;EOLN
  525. JMP.b seox1 ;'
  526. xseekeof MOV DX,#$011A ;SEEKEOF
  527. JMP.b seox1 ;'
  528. xeoftx MOV DX,#$001A ;EOF
  529. seox1 POP errpos ;get return addr
  530. POP ES ;file var seg
  531. PUSH errpos ;restore ret
  532. ES:
  533. TEST.B [DI]$02,#$80 ;open for input ?
  534. JZ sefalse ;no: false
  535. seloop PUSH DX ;save flag
  536. CALL getbyte2 ;get char from file
  537. POP DX ;restore flag
  538. CMP.B AL,DL ;= char searched ?
  539. JZ setrue ;yes: true
  540. CMP AL,#$1A ;EOF ?
  541. JZ setrue ;yes: true
  542. CMP AL,#$20 ;space / control ?
  543. JA sefalse ;no: false
  544. OR.B DH,DH ;seek it ?
  545. JZ sefalse ;:no, false
  546. ES:
  547. AND.B [DI]$02,#$DF ;clear flag: char pre-read
  548. JMP seloop ;'search it
  549. setrue XOR AX,AX ;return true
  550. INC AX ;setting flags
  551. RET ;'
  552. sefalse XOR AX,AX ;return false
  553. RET ;"
  554. xassign XOR.B AL,AL ;Assign: set function code
  555. JMP doassign ;"do assign
  556. xresetty XOR.B AL,AL ;Reset typed
  557. JMP.b openty1 ;'
  558. xrewrtty MOV AL,#$01 ;Rewrite typed
  559. openty1 MOV filfunc,AL ;store function code
  560. POP errpos ;get return addr
  561. POP ES ;file var ptr
  562. PUSH errpos ;restore ret
  563. PUSH CX ;save record length
  564. CALL closty1 ;clear record len, close file
  565. POP CX ;remove for error exit
  566. CMP.B errnum,#$00 ;error ?
  567. JNZ openty2 ;:yes
  568. PUSH CX
  569. CALL openfile ;open that file
  570. POP CX ;record len
  571. CMP.B errnum,#$00 ;error ?
  572. JNZ openty2 ;:yes
  573. ES:
  574. MOV [DI]$02,CX ;store record length
  575. openty2 RET ;"
  576. xtruncat POP errpos ;Truncate typed, untyped
  577. POP ES ;file var ptr
  578. PUSH errpos ;restore ret
  579. MOV AH,#$40 ;write
  580. ES:
  581. MOV BX,[DI] ;file handle
  582. XOR CX,CX ;length = 0 -> truncate
  583. JMP dos ;"do it
  584. xflushty RET $0002 ;"Flush typed, untyped
  585. xclosety POP errpos ;Close typed, untyped
  586. POP ES ;file var ptr
  587. PUSH errpos ;restore ret
  588. closty1 ES:
  589. MOV [DI]$02,#$0000 ;record len = 0
  590. JMP close2 ;"close it
  591. xfilsel POP errpos ;Select file
  592. POP ES ;file var ptr
  593. MOV currfil,DI ;-> current file
  594. MOV currfil1,ES
  595. ES:
  596. CMP [DI]$02,#$00 ;record len = 0 ?
  597. JNZ selret ;no: ok
  598. MOV.B errnum,#$04 ;File not open
  599. selret JMP [errpos] ;"ret
  600. xrdvar MOV filfunc,#$993F ;Read from typed file
  601. JMP.b filrw ;'read, unexpected EOF
  602. xwrvar MOV filfunc,#$F040 ;Write to typed file
  603. filrw POP BX ;write, disk write error
  604. POP SI ;var seg
  605. PUSH BX ;restore ret
  606. CMP.B errnum,#$00 ;error ?
  607. JNZ filrwret ;yes: no operation
  608. MOV DX,DI ;save DI
  609. LES DI,currfil ;current file var
  610. MOV.B AH,filfunc ;save function, error code
  611. ES:
  612. MOV BX,[DI] ;file handle
  613. ES:
  614. MOV CX,[DI]$02 ;record length
  615. PUSH DS ;save DS
  616. MOV DS,SI ;ptr var
  617. CALL dos ;do it
  618. POP DS ;restore DS
  619. JB filrwerr ;:error
  620. CMP AX,CX ;length = expected ?
  621. JZ filrwret ;:yes
  622. CMP.B filfunc,#$3F ;read ?
  623. JNZ filrwerr ;no: error
  624. OR AX,AX ;test count
  625. JZ filrwerr ;nothing done: error
  626. ES:
  627. MOV CX,[DI]$02 ;record length
  628. MOV DI,DX ;restore dest ofs
  629. ADD DI,AX ;add count read
  630. MOV ES,SI ;dest seg
  631. SUB CX,AX ;count to fill
  632. XOR AX,AX ;pad with zeroes
  633. CLD
  634. REPZ ;do fill
  635. STOS.B
  636. RET ;'
  637. filrwerr MOV AL,filerr ;error code -> error
  638. MOV errnum,AL
  639. filrwret RET ;"
  640. xseek XOR DX,DX ;Seek: clear high word
  641. seek1 POP errpos ;set error pos
  642. POP DI ;get file var ptr
  643. POP ES
  644. PUSH errpos ;restore ret
  645. ES:
  646. MOV CX,[DI]$02 ;get record length
  647. CALL cardmul ;* pos -> DX:AX
  648. MOV CX,DX ;-> CX:DX
  649. MOV DX,AX
  650. MOV AX,#$4200 ;seek absolute
  651. ES:
  652. MOV BX,[DI] ;file handle
  653. PUSH CX ;save pos wanted
  654. PUSH DX
  655. CALL dos ;do it
  656. POP CX ;restore pos wanted
  657. POP BX
  658. JB seekerr ;:error
  659. CMP AX,CX ;pos = expected ?
  660. JNZ seekerr ;:no
  661. CMP DX,BX
  662. JZ seekret ;:yes
  663. seekerr MOV.B errnum,#$91 ;Seek beyond EOF
  664. seekret RET ;"
  665. xlngseek CALL realcard ;LongSeek: convert real
  666. JMP seek1 ;"do it
  667. xeofty POP BX ;EOF typed, untyped
  668. POP ES ;get file var ptr
  669. PUSH BX ;restore ret
  670. MOV AX,#$4406 ;get unit status
  671. ES:
  672. MOV BX,[DI] ;file handle
  673. CALL dos ;do it
  674. OR.B AL,AL ;test result
  675. MOV AX,#$0000 ;false
  676. JNZ eoffalse ;:ok
  677. INC AX ;true
  678. eoffalse OR AX,AX ;set flags
  679. RET ;"
  680. xfilepos POP BX ;FilePos: ret addr
  681. POP ES ;file var ptr
  682. PUSH BX ;restore ret
  683. filpos1 MOV AX,#$4201 ;seek relative
  684. ES:
  685. MOV BX,[DI] ;file handle
  686. XOR CX,CX ;no offset
  687. XOR DX,DX
  688. CALL dos ;get position
  689. filpos2 ES:
  690. MOV CX,[DI]$02 ;record length
  691. JMP.b carddiv ;"pos / reclen -> filepos
  692. NOP ;LongFilePos
  693. xlfilpos POP BX ;return addr
  694. POP ES ;file var ptr
  695. PUSH BX ;restore ret
  696. CALL filpos1 ;do it
  697. JMP cardreal ;"result -> real
  698. xfilesiz POP BX ;FileSize: ret addr
  699. POP ES ;file var ptr
  700. PUSH BX ;restore ret
  701. filsiz1 MOV AX,#$4201 ;seek relative
  702. ES:
  703. MOV BX,[DI] ;file handle
  704. XOR CX,CX ;no offset
  705. XOR DX,DX
  706. CALL dos ;get current pos
  707. PUSH AX ;save it
  708. PUSH DX
  709. MOV AX,#$4202 ;seek from end
  710. ES:
  711. MOV BX,[DI] ;file handle
  712. XOR CX,CX ;no offset
  713. XOR DX,DX
  714. CALL dos ;get end position
  715. POP CX ;restore current pos
  716. POP BX
  717. PUSH AX ;save end pos
  718. PUSH DX
  719. MOV DX,BX ;restore file pos
  720. MOV AX,#$4200 ;seek absolute
  721. ES:
  722. MOV BX,[DI] ;file handle
  723. CALL dos ;go back to old pos
  724. POP DX ;end position
  725. POP AX
  726. ES:
  727. MOV CX,[DI]$02 ;(pos+reclen-1)
  728. DEC CX
  729. ADD AX,CX
  730. ADC DX,#$00
  731. JMP filpos2 ;"/ reclen -> position
  732. xlfilsiz POP BX ;LongFileSize: ret addr
  733. POP ES ;file var ptr
  734. PUSH BX ;restore ret
  735. CALL filsiz1 ;do it
  736. JMP cardreal ;"result -> real
  737. carddiv CMP CX,#$01 ;long cardinal division
  738. JZ cdret ;/ 1: done
  739. MOV SI,CX ;DX:AX / CX -> DX:AX
  740. XOR BX,BX ;clear result
  741. MOV CX,#$0021 ;32 bits
  742. cdloop RCL BX,1 ;shift in result
  743. SBB BX,SI ;try subtraction
  744. JNB cdbit1 ;:ok
  745. ADD BX,SI ;restore it
  746. STC
  747. cdbit1 CMC ;make flag to shift in
  748. RCL AX,1 ;shift in result
  749. RCL DX,1
  750. LOOP cdloop ;:another bit
  751. cdret RET ;"
  752. cardmul MOV BX,AX ;long card mul
  753. MOV AX,DX ;DX:AX * CX -> DX:AX
  754. MUL CX ;higher word
  755. XCHG AX,BX ;save it
  756. MUL CX ;lower word
  757. ADD DX,BX ;add higher result
  758. RET ;"
  759. xresetun XCHG AX,CX ;Reset untyped: record length
  760. POP BX ;ret addr
  761. POP DI ;file var ofs
  762. PUSH BX ;restore ret
  763. JMP xresetty ;"now like typed file
  764. xrewrtun XCHG AX,CX ;Rewrite untyped: record length
  765. POP BX ;ret addr
  766. POP DI ;file var ofs
  767. PUSH BX ;restore ret
  768. JMP xrewrtty ;"now like typed file
  769. xblkrd MOV filfunc,#$993F ;BlockRead
  770. JMP.b blrw1 ;'read, unexpected EOF
  771. xblkwr MOV filfunc,#$F040 ;BlockWrite
  772. blrw1 POP errpos ;write, disk write error
  773. POP DX ;var seg
  774. POP SI ;var ofs
  775. POP DI ;file var ptr
  776. POP ES
  777. PUSH AX ;save length
  778. CALL blrw ;do it
  779. POP CX ;restore len
  780. CMP.B errnum,#$00 ;error ?
  781. JNZ blrw1ok ;yes: return
  782. CMP AX,CX ;length = expected
  783. JZ blrw1ok ;:yes
  784. MOV AL,filerr ;error code -> error
  785. MOV errnum,AL
  786. blrw1ok JMP [errpos] ;"return
  787. xblkrdrd MOV filfunc,#$993F ;BlockRead with result var
  788. JMP.b blrwres ;'
  789. xblkwrrs MOV filfunc,#$F040 ;BlockWrite with result var
  790. blrwres POP errpos ;get error pos
  791. MOV CX,DI ;result var ptr
  792. POP BX
  793. POP AX ;length
  794. POP DX ;var seg
  795. POP SI ;var ofs
  796. POP DI ;file var ptr
  797. POP ES
  798. PUSH BX ;save result var ptr
  799. PUSH CX
  800. CALL blrw ;do it
  801. POP DI ;restore result var ptr
  802. POP ES
  803. ES:
  804. MOV [DI],AX ;store record count
  805. JMP [errpos] ;"return
  806. blrw ES: ;do Block-R/W
  807. CMP [DI]$02,#$00 ;record length = 0 ?
  808. JZ blrwerr ;yes: file not open
  809. ES:
  810. CMP [DI]$02,#$01 ;record len = 1 ?
  811. JZ blrwbyt ;:no calculation
  812. PUSH DX ;save
  813. ES:
  814. MUL [DI]$02 ;count * record length
  815. POP DX ;restore
  816. blrwbyt XCHG AX,CX ;length -> CX
  817. MOV.B AH,filfunc ;function code
  818. ES:
  819. MOV BX,[DI] ;file handle
  820. PUSH DS ;save DS
  821. MOV DS,SI ;var seg
  822. CALL dos ;do file operation
  823. POP DS ;restore DS
  824. JNB blrwok ;:ok
  825. MOV AL,filerr ;error code -> error
  826. MOV errnum,AL
  827. XOR AX,AX ;nothing read / written
  828. blrwok ES:
  829. MOV CX,[DI]$02 ;record length
  830. CMP CX,#$01 ;= 1 ?
  831. JZ blrwret ;yes: no division
  832. MOV DI,DX ;offset + count done
  833. ADD DI,AX
  834. XOR DX,DX ;clear hi
  835. DIV CX ;count done / record len
  836. OR DX,DX ;test remainder
  837. JZ blrwret ;:ok
  838. CMP.B filfunc,#$3F ;read ?
  839. JNZ blrwret ;no: end it
  840. PUSH AX ;save count done
  841. SUB CX,DX ;fill up the rest
  842. MOV ES,SI ;var seg
  843. XOR AX,AX ;with zeroes
  844. CLD
  845. REPZ ;do it
  846. STOS.B
  847. POP AX ;restore result
  848. INC AX ;+1
  849. blrwret RET ;'
  850. blrwerr MOV.B errnum,#$04 ;File not open
  851. RET ;"
  852. xerase POP errpos ;Erase
  853. POP ES ;file var ptr
  854. PUSH errpos ;restore ret
  855. MOV AH,#$41 ;delete file
  856. LEA DX,[DI]$0C ;ptr to filename
  857. PUSH DS ;save DS
  858. PUSH ES ;ES -> DS
  859. POP DS
  860. CALL dos ;do it
  861. POP DS ;restore DS
  862. JNB eraret ;:no error
  863. eraerr MOV.B errnum,#$01 ;file not found
  864. eraret RET ;"
  865. xrename POP errpos ;Rename
  866. CALL getpn ;convert string -> ASCIIZ
  867. POP DI ;file var ptr
  868. POP ES
  869. PUSH errpos ;restore ret
  870. MOV AH,#$56 ;Rename file
  871. LEA DX,[DI]$0C ;current file name
  872. PUSH DI ;save addr
  873. MOV DI,#pnbuf ;filename ptr
  874. PUSH DS ;ES <-> DS
  875. PUSH ES
  876. POP DS
  877. POP ES
  878. CALL dos ;do rename
  879. PUSH DS ;ES <-> DS
  880. PUSH ES
  881. POP DS
  882. POP ES
  883. POP DI ;restore addr
  884. JB eraerr ;:error
  885. MOV SI,#pnbuf ;copy new name into file var
  886. LEA DI,[DI]$0C ;file var offset
  887. MOV CX,#$0020 ;64 bytes
  888. CLD
  889. REPZ
  890. MOVS ;copy it
  891. RET ;"
  892. xchdir POP errpos ;ChDir: get error pos
  893. CALL getpn ;get path name
  894. PUSH errpos ;restore ret
  895. MOV AX,pnbuf ;get drive #
  896. OR.B AL,AL ;end of name ?
  897. JZ chdirret ;yes: return
  898. CMP.B AH,#$3A ;: ?
  899. JNZ chdir1 ;no: no drive specified
  900. CALL upcase ;upcase drive number
  901. SUB AL,#$41 ;- A
  902. JB eraerr ;<:error
  903. CMP AL,#$0F ;max. O
  904. JNB eraerr ;:error.
  905. ;Please note that MS-DOS now allows more drives !!!
  906. MOV AH,#$0E ;set default drive
  907. MOV.B DL,AL ;drive number
  908. CALL dos ;set it
  909. CMP.B pnbuf2,#$00 ;pathname ?
  910. JZ chdirret ;:none given
  911. chdir1 MOV AH,#$3B ;change dir
  912. chdir2 MOV DX,#pnbuf ;pointer to pathname
  913. CALL dos ;set it
  914. JB eraerr ;:error
  915. chdirret RET ;"
  916. xmkdir MOV BH,#$39 ;MkDir
  917. JMP.b rmdir1 ;'
  918. xrmdir MOV BH,#$3A ;RmDir
  919. rmdir1 POP errpos ;return addr -> error pos
  920. CALL getpn ;get path name
  921. PUSH errpos ;restore ret
  922. MOV.B AH,BH ;get function code
  923. JMP chdir2 ;"do it
  924. xgetdir POP errpos ;GetDir: CL=max. string len
  925. POP ES ;dest string
  926. POP AX ;drive number
  927. PUSH errpos ;restore ret
  928. OR.B AL,AL ;default drive ?
  929. JNZ gdnotdef ;:no
  930. MOV AH,#$19 ;get default drive number
  931. CALL dos
  932. INC.B AL ;+1
  933. gdnotdef MOV.B DL,AL ;drive number
  934. ADD AL,#$40 ;-> drive name
  935. MOV pnbuf,AL ;store in buffer
  936. MOV pnbuf1,#$5C3A ;store :\
  937. MOV AH,#$47 ;read current access path
  938. MOV SI,#pnbuf3 ;dest ptr
  939. CALL dos ;do it
  940. JNB gddone ;:ok
  941. MOV.B [SI],#$00 ;no path - mark end
  942. gddone MOV SI,#pnbuf ;pointer to path name
  943. XOR BX,BX ;clear len counter
  944. gdloop MOV.B AL,[SI] ;get char
  945. OR.B AL,AL ;end ?
  946. JZ gdend ;:yes
  947. INC SI ;next char
  948. INC BX ;count length
  949. ES:
  950. MOV.B [BX_DI],AL ;store in dest string
  951. DEC.B CL ;space available ?
  952. JNZ gdloop ;:yes
  953. gdend ES: ;store length
  954. MOV.B [DI],BL
  955. RET ;"
  956. xexecute MOV BX,#$2C7C ;Execute
  957. JMP.b chain1
  958. xchain XOR BX,BX ;Chain: load all of it
  959. chain1 POP errpos ;get ret addr
  960. POP ES ;file var ptr
  961. PUSH errpos ;restore ret
  962. TEST modeflg,#$0001 ;direct mode ?
  963. JNZ cherr2 ;yes: error
  964. PUSH BX ;save begin offset
  965. MOV AX,#$3D00 ;open file
  966. LEA DX,[DI]$0C ;ptr to filename
  967. CALL dos ;do it
  968. POP DX ;begin offset
  969. JB cherr1 ;:error
  970. MOV BX,AX
  971. MOV AX,#$4200 ;seek absolute
  972. XOR CX,CX ;clr hi word
  973. CALL dos ;do seek
  974. JB cherr1 ;:error
  975. PUSH DS ;save DS
  976. PUSH CS ;CS -> DS
  977. POP DS
  978. MOV AH,#$3F ;read byte block
  979. MOV CX,#$FFFF ;as much as possible
  980. MOV DX,#start ;destination
  981. CALL dos ;do it
  982. POP DS ;restore DS
  983. MOV AH,#$3E ;close file
  984. CALL dos
  985. MOV SP,spval ;restore SP
  986. CALL reinit2 ;reinit files, I/O
  987. MOV verror,#$10D0 ;set break vector
  988. JMP start2 ;'start - no memory init
  989. cherr1 MOV DL,#$01 ;File not found
  990. JMP operr ;'
  991. cherr2 MOV.B errnum,#$21 ;Not allowed in direct mode
  992. RET ;"
  993. start JMP.b kstart ;'skip message
  994. B "Licensed Material. Program Property of B"
  995. B "ORLAND." ;'
  996. kstart CALL readvers ;read version number
  997. MOV AX,#$9C06 ;(program size+15)/16
  998. MOV CL,#$04
  999. SHR AX,CL
  1000. MOV DX,CS ;+CS -> DS
  1001. ADD DX,AX
  1002. MOV DS,DX
  1003. CS:
  1004. MOV AX,availmem ;top of memory
  1005. SUB AX,DX
  1006. MOV freemem,AX ;max memory size
  1007. MOV BX,#$FFFE ;stack pointer
  1008. SUB AX,#$1000 ;mem - 64K
  1009. JNB kmembig ;:ok
  1010. MOV BX,freemem ;max memory size
  1011. MOV CL,#$04 ;small memory: SS at end of DS
  1012. SHL BX,CL ;calc SP
  1013. XOR AX,AX ;no segment offset
  1014. kmembig ADD AX,DX ;add to DS
  1015. MOV stackseg,AX ;-> stack segment
  1016. MOV stackpt,BX ;-> stack pointer
  1017. MOV AX,freemem ;max memory size
  1018. SUB AX,#$0040 ;- 64 paragraphs
  1019. CMP AX,#$1000 ;= 64K ?
  1020. JB kmemlim ;:less
  1021. MOV AX,#$1000 ;limit to 64K
  1022. kmemlim MOV CL,#$04
  1023. SHL AX,CL
  1024. DEC AX
  1025. MOV txmemend,AX ;store -> end of text space
  1026. XOR AX,AX
  1027. kmeminit MOV SS,stackseg ;set stack segment
  1028. MOV SP,stackpt ;set stack pointer
  1029. PUSH AX ;save flag
  1030. MOV CX,#$0010 ;16 files
  1031. CALL initio ;init files, I/O
  1032. POP AX ;get flag
  1033. OR AX,AX ;test it
  1034. PUSH AX ;save it again
  1035. JNZ kcrtinit ;:set
  1036. CALL xcrtinit ;CrtInit
  1037. kcrtinit CALL klowvid ;LowVideo
  1038. CALL knrmvid ;NormVideo
  1039. POP AX ;get flag
  1040. OR AX,AX ;test it
  1041. JZ kinitvar ;:init
  1042. JMP kmainlp ;'go to main loop
  1043. kinitvar MOV AX,#txstrt ;init vars
  1044. MOV txbeg,AX ;beg of text
  1045. MOV txend,AX ;end of text
  1046. XOR AX,AX ;clear vars
  1047. MOV mincssz,AX ;min CS-size = 0
  1048. MOV mindssz,AX ;min DS-size = 0
  1049. MOV minhpsz,#$0400 ;min free heap = 16K
  1050. MOV maxhpsz,#$A000 ;max free heap = 640K
  1051. MOV workpn,AL ;clear work filename
  1052. MOV mainpn,AL ;clear main filename
  1053. MOV parmlin,AL ;clear param line
  1054. MOV errio,AL ;clear error
  1055. MOV.B codedest,#$01 ;code destination: memory
  1056. CALL inited ;init variables
  1057. MOV AH,#$19 ;get default drive
  1058. CALL dos
  1059. MOV defdrv,AL ;store it
  1060. CALL xclrscr ;ClrScr
  1061. CALL prints ;write string
  1062. B "---------------------------------------",$0D
  1063. B $0A,"TURBO Pascal system ",$00
  1064. CALL klowvid ;do LowVideo
  1065. CALL prints ;write string
  1066. B "Version 3.01A",$00
  1067. CALL knrmvid ;do HighVideo
  1068. CALL prints ;write string
  1069. B $0D,$0A," ",$00
  1070. CALL klowvid
  1071. CALL prints
  1072. B "PC-DOS",$00
  1073. CALL knrmvid
  1074. CALL prints
  1075. B $0D,$0A,$0A,$00
  1076. CALL klowvid
  1077. CALL prints
  1078. B "Copyright (C) 1983,84,85",$00
  1079. CALL knrmvid
  1080. CALL prints
  1081. B " BORLAND Inc.",$0D,$0A,"-----------------------"
  1082. B "----------------",$0D,$0A,$0A,$00
  1083. MOV BX,#displstr ;write display type
  1084. CALL putstr
  1085. CALL prints
  1086. B $0D,$0A,$0A,$0A,$0A,"Include error messages",$00
  1087. CALL yornln ;Y or N ?
  1088. MOV msgflg,AL ;store flag
  1089. JZ kclr ;:no
  1090. CALL kreaderr ;read error messages
  1091. kclr CALL kclrtxt ;clear text
  1092. CALL kmenu ;write menu
  1093. kmainlp MOV SP,stackpt ;main loop: restore SP
  1094. MOV BX,#kmainlp ;set a return addr
  1095. PUSH BX
  1096. CMP.B errio,#$00 ;error ?
  1097. JZ kgetcmd ;:no
  1098. JMP kdofind ;'search error
  1099. kgetcmd CALL printatt ;write string with attributes
  1100. B $8D,$8A,$BE,$00 ;CR,LF,>
  1101. CALL knrmvid
  1102. CALL keyget ;get command
  1103. CALL upcase ;convert to upper case
  1104. PUSH AX ;save it
  1105. CALL xwriteln ;WriteLn
  1106. POP AX ;restore command
  1107. MOV SI,#kcmdtab ;ptr to command table
  1108. CALL srchcmd ;search command
  1109. JB kmenu ;not found: write menu
  1110. CS:
  1111. JMP [SI]$01 ;"execute command
  1112. kreaddef CLD ;Transfer string into CON buffer
  1113. MOV DI,#coninbuf ;dest ptr
  1114. PUSH DS ;DS -> ES
  1115. POP ES
  1116. kreaddl LODS.B ;SI: source ptr
  1117. STOS.B ;copy string
  1118. OR.B AL,AL ;test for end
  1119. JNZ kreaddl ;:no
  1120. kreadln CALL prints ;Readln: write string
  1121. B ": ",$00
  1122. CALL rdedit ;read with editing
  1123. MOV BX,#coninbuf ;buffer ptr
  1124. CALL xwriteln ;WriteLn
  1125. krdln1 MOV.B AL,[BX] ;get char from buffer
  1126. CMP AL,#$1A ;^Z ?
  1127. JZ krdlnret ;yes - end
  1128. CMP AL,#$20 ;space ?
  1129. JNZ krdlnret ;:no, ret
  1130. INC BX ;skip spaces
  1131. JMP krdln1 ;'continue scanning
  1132. krdlnret RET ;"BX now points into buffer
  1133. krdend CMP.B [BX],#$1A ;Test end of line
  1134. RET ;"
  1135. kmenu CALL knrmvid ;Write menu
  1136. CALL xclrscr ;ClrScr
  1137. CALL printatt
  1138. B $CC,"ogged drive: ",$80,$00
  1139. MOV AH,#$19 ;get default drive
  1140. CALL dos
  1141. ADD AL,#$41 ;convert to ASCII
  1142. CALL conput ;write its name
  1143. CALL printatt
  1144. B $0D,$0A,$C1,"ctive directory: ",$DC,$00
  1145. MOV AH,#$47 ;get active directory
  1146. XOR.B DL,DL ;default drive
  1147. MOV SI,#pnbuf ;dest buffer
  1148. CALL dos ;do it: get pathname
  1149. CALL printpn ;write that pathname
  1150. CALL printatt
  1151. B $0D,$0A,$0A,$D7,"ork file: ",$80,$00
  1152. CALL kwworkpn ;write current filename
  1153. CALL printatt
  1154. B $0D,$0A,$CD,"ain file: ",$80,$00
  1155. MOV SI,#mainpn ;main filename
  1156. CALL printpn ;write it
  1157. CALL printatt ;write command menu
  1158. B $0D,$0A,$0A,$C5,"dit ",$C3,"ompile ",$D2,"un ",$D3
  1159. B "ave",$0D,$0A,$0A,$C4,"ir ",$D1,"uit compiler ",$CF
  1160. B "ptions",$0D,$0A,$0A,"Text: ",$00
  1161. MOV AX,txend ;end of text
  1162. SUB AX,txbeg ;- beg of text
  1163. CALL kbytes ;print number
  1164. CALL prints
  1165. B "Free: ",$00
  1166. MOV AX,txmemend ;top of text space
  1167. SUB AX,txend ;- end of text
  1168. kbytes CALL knumax ;print number
  1169. CALL prints
  1170. B " bytes",$0D,$0A,$00
  1171. RET ;"
  1172. kcdest DEC.B AL ;show code direction: this one ?
  1173. JNZ kcdestno ;count it down: no
  1174. CALL printatt
  1175. B "compile -> ",$00
  1176. RET ;'
  1177. kcdestno CALL printatt ;clear field
  1178. B " ",$00
  1179. RET ;"
  1180. optmenu MOV AX,#optmenu ;Option-menu
  1181. PUSH AX ;put return addr
  1182. optmenu2 CALL xclrscr ;ClrScr
  1183. MOV AL,codedest ;code destination
  1184. CALL kcdest ;show it
  1185. CALL printatt
  1186. B $CD,"emory",$0D,$0A,$00
  1187. CALL kcdest ;show it
  1188. CALL printatt
  1189. B $C3,"om-file",$0D,$0A,$00
  1190. CALL kcdest ;show it
  1191. CALL printatt
  1192. B "c",$C8,"n-file",$0D,$0A,$0A,$0A,$00
  1193. CMP.B codedest,#$02 ;to COM-file ?
  1194. JZ optmcom ;:yes
  1195. JMP optmparm ;'
  1196. optmcom CALL printatt ;display memory information
  1197. B "minimum c",$CF,"de segment size: ",$00
  1198. CALL knrmvid
  1199. MOV AX,mincssz ;min CS size
  1200. CALL whexword ;write hex
  1201. CALL printatt
  1202. B " (max ",$00
  1203. MOV AX,#$2D8B ;-(runtime size+15)/16
  1204. MOV CL,#$04
  1205. SHR AX,CL
  1206. NEG AX
  1207. ADD AX,#$1000 ;+ 64K
  1208. CALL kpara ;write paragraphs
  1209. CALL printatt
  1210. B ")",$0D,$0A,"minimum ",$C4,"ata segment size: ",$00
  1211. CALL knrmvid
  1212. MOV AX,mindssz ;min DS size
  1213. CALL whexword ;write hex
  1214. CALL printatt
  1215. B " (max ",$00
  1216. MOV AX,#$024F ;-(min vars used+15)/16
  1217. MOV CL,#$04
  1218. SHR AX,CL
  1219. NEG AX
  1220. ADD AX,#$1000 ;+ 64K
  1221. CALL kpara ;write paragraphs
  1222. CALL printatt
  1223. B ")",$0D,$0A,"m",$C9,"nimum free dynamic memory: ",$00
  1224. CALL knrmvid
  1225. MOV AX,minhpsz ;min free heap
  1226. CALL whexword ;write hex
  1227. CALL klowvid
  1228. CALL kparastr ;write paragraphs
  1229. CALL printatt
  1230. B $0D,$0A,"m",$C1,"ximum free dynamic memory: ",$00
  1231. CALL knrmvid
  1232. MOV AX,maxhpsz ;max free heap
  1233. CALL whexword ;write hex
  1234. CALL klowvid
  1235. CALL kparastr ;write paragraphs
  1236. JMP.b optmget
  1237. optmparm CALL printatt
  1238. B "command line ",$D0,"arameters: ",$00
  1239. CALL knrmvid
  1240. MOV SI,#parmlin ;display command line
  1241. CALL kwstrsi
  1242. optmget CALL printatt
  1243. B $0D,$0A,$0A,$0A,$C6,"ind run-time error ",$D1,"uit",$0D
  1244. B $0A,$0A,$BE,$00
  1245. CALL knrmvid
  1246. CALL keyget ;get command
  1247. CALL upcase ;convert to upper case
  1248. PUSH AX ;save it
  1249. CALL xwriteln ;WriteLn
  1250. POP AX ;restore cmd
  1251. MOV SI,#ocmdtab ;ptr to command table
  1252. CALL srchcmd ;search command
  1253. JNB optexe ;:ok
  1254. JMP optmenu2 ;'not found - repeat
  1255. optexe CS:
  1256. JMP [SI]$01 ;"execute command
  1257. yornln CALL yorn ;Y or N ?
  1258. PUSHF ;save result
  1259. PUSH AX
  1260. CALL xwriteln ;WriteLn
  1261. POP AX ;restore result
  1262. POPF
  1263. RET ;"
  1264. yorn CALL prints ;Y or N ?
  1265. B " (Y/N)? ",$00
  1266. yornlp CALL keyget ;get char
  1267. CALL upcase ;convert to upper
  1268. CMP AL,#$59 ;Y ?
  1269. JZ yornok ;:yes
  1270. CMP AL,#$4E ;N ?
  1271. JNZ yornlp ;no: loop back
  1272. yornok PUSH AX ;save key
  1273. CALL conput ;display choice
  1274. POP AX ;restore it
  1275. SUB AL,#$4E ;set flags:
  1276. RET ;"0=no
  1277. waitesc CALL prints ;Wait for ESC
  1278. B ". Press <ESC>",$00
  1279. waitescl CALL keyget ;get char
  1280. CMP AL,#$1B ;ESC ?
  1281. JNZ waitescl ;:no, wait
  1282. RET ;"
  1283. srchcmd CS: ;Search command in table
  1284. CMP.B AL,[SI] ;compare it
  1285. JZ srcmdfnd ;:found
  1286. ADD SI,#$03 ;go to next entry
  1287. CS:
  1288. CMP.B [SI],#$00 ;end of table ?
  1289. JNZ srchcmd ;:no
  1290. STC ;not found !
  1291. srcmdfnd RET ;"
  1292. kcmdtab B "L" ;main command table
  1293. W klogged
  1294. B "A"
  1295. W kactdir
  1296. B "W"
  1297. W kwork
  1298. B "M"
  1299. W kmain
  1300. B "E"
  1301. W editor
  1302. B "C"
  1303. W kcomp
  1304. B "R"
  1305. W krun
  1306. B "S"
  1307. W ksave
  1308. B "D"
  1309. W kdir
  1310. B "O"
  1311. W optmenu
  1312. B "Q"
  1313. W kquit
  1314. B $00 ;"end of table
  1315. B "M" ;option command table
  1316. W kmem
  1317. B "C"
  1318. W kcom
  1319. B "H"
  1320. W kchn
  1321. B "O"
  1322. W kcs
  1323. B "D"
  1324. W kds
  1325. B "I"
  1326. W kss
  1327. B "A"
  1328. W kmss
  1329. B "P"
  1330. W kparm
  1331. B "F"
  1332. W kfind
  1333. B "Q"
  1334. W optquit
  1335. B $00 ;"end of table
  1336. optquit POP AX ;Quit submenu
  1337. JMP kmenu ;"jump to main menu
  1338. ;pathname of message file (installed by TINST)
  1339. errpath B "TURBO.MSG",$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  1340. B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ;"
  1341. extpas B $04,".PAS" ;table of file extensions
  1342. extcom B $04,".COM"
  1343. extbak B $04,".BAK"
  1344. extchn B $04,".CHN" ;"
  1345. fnpath B $04,"\*.*" ;search parameters
  1346. fnany B $03,"*.*" ;"
  1347. kmain CALL prints ;M:Main file name
  1348. B $0D,$0A,"Main file name",$00
  1349. CALL knocode ;flag: text not compiled
  1350. MOV SI,#mainpn ;pointer to pathname
  1351. CALL kreaddef ;Enter new name
  1352. MOV.B mainpn,#$00 ;mark end
  1353. JZ kmret ;:nothing read
  1354. CALL kpasext ;parse filename
  1355. MOV DI,#mainpn ;dest buffer
  1356. CALL fnscdi ;copy to main file name
  1357. kmret RET ;"
  1358. ;W:Work file name
  1359. kwork MOV vnewfil,#flnew ;set error vec: new file
  1360. CALL ksvchng ;save, if changed
  1361. CALL prints
  1362. B $0D,$0A,"Work file name",$00
  1363. MOV SI,#workpn ;ptr work file name
  1364. CALL kreaddef ;Enter new name
  1365. MOV.B workpn,#$00 ;mark end
  1366. JNZ kwok ;:something read
  1367. CALL kclrtxt ;clear text
  1368. JMP kmainlp ;'back to main menu
  1369. kwok CALL kpasext ;parse filename
  1370. MOV DI,#workpn ;copy to work file name
  1371. CALL fnscdi
  1372. JMP.b kw2 ;'now load it
  1373. kwload MOV vnewfil,#flescclr ;set error vec: not found
  1374. kw2 MOV vfilbig,#flbigclr ;set error vec: too big
  1375. CALL kclrtxt ;clear text
  1376. MOV SI,#workpn ;work file name
  1377. kwload2 MOV BX,txbeg ;beg of text
  1378. PUSH BX ;save parms
  1379. PUSH SI
  1380. CALL clred ;clear editor vars
  1381. POP SI
  1382. POP BX ;restore
  1383. MOV DX,BX ;begin addr
  1384. MOV CX,txmemend ;end of space
  1385. CALL kload ;load file
  1386. INC BX
  1387. MOV txend,BX ;set end of text
  1388. RET ;"
  1389. kload PUSH DX ;Load file: save start pos
  1390. PUSH CX ;save end pos
  1391. CALL fnsisc ;copy pathname[SI]
  1392. CALL prints
  1393. B $0D,$0A,"Loading ",$00
  1394. CALL kwscrpn ;write pathname
  1395. MOV AX,#$3D00 ;open file
  1396. MOV DX,#scrpn ;current pathname
  1397. PUSH DS ;DS -> ES
  1398. POP ES
  1399. CALL dos ;do it
  1400. MOV BX,AX ;file handle
  1401. POP CX ;restore parms
  1402. POP DX
  1403. JB flntfnd ;:error
  1404. kload2 SUB CX,DX ;calc max length
  1405. MOV AH,#$3F ;read byte block
  1406. CALL dos ;do it
  1407. JB flntfnd ;:error
  1408. CMP AX,CX ;length = expected ?
  1409. JZ fltoobig ;yes: too big !
  1410. XCHG AX,CX ;get length done
  1411. MOV DI,DX ;end addr
  1412. PUSH DS ;DS -> ES
  1413. POP ES
  1414. MOV AL,#$1A ;search ^Z in the block
  1415. CLD
  1416. REPNZ
  1417. SCAS.B
  1418. JNZ klnoeof ;:not found
  1419. DEC DI ;go back one byte
  1420. klnoeof MOV AH,#$3E ;close file
  1421. CALL dos
  1422. DEC DI
  1423. MOV BX,DI ;end pos of text read
  1424. RET ;"
  1425. fltoobig CALL klnoeof ;file too large: close file
  1426. MOV BX,DX ;end of text space
  1427. INC BX ;+1
  1428. JMP [vfilbig] ;"handle error
  1429. flntfnd MOV BX,DX ;file not found
  1430. DEC BX ;end addr
  1431. JMP [vnewfil] ;"handle error
  1432. flesc CALL xwriteln ;File not found - ESC
  1433. CALL vidattr3 ;attribute #3
  1434. CALL prints
  1435. B "File not found",$00
  1436. flesc2 CALL waitesc ;wait for ESC
  1437. JMP knrmvid ;"HighVideo
  1438. flescclr CALL flesc ;file not found - ESC
  1439. JMP.b flclr ;"clear work file name
  1440. flnew CMP AL,#$03 ;New file: test error code
  1441. JZ fldir ;:invalid dir
  1442. CALL xwriteln ;WriteLn
  1443. CALL vidattr2 ;attribute #2
  1444. CALL prints
  1445. B "New File",$00
  1446. CALL knrmvid
  1447. PUSH BX ;save end pos
  1448. MOV BX,#$07D0 ;wait 2 s
  1449. CALL delaybx
  1450. POP BX ;restore
  1451. RET ;'
  1452. fldir CALL xwriteln ;WriteLn
  1453. CALL vidattr3 ;Attribute #3
  1454. CALL prints
  1455. B "Invalid directory",$00
  1456. JMP.b flclr ;"clear work file name
  1457. flbig CALL xwriteln ;File too big
  1458. CALL vidattr3
  1459. CALL prints
  1460. B "File too big",$00
  1461. MOV BX,txend ;end of text-1 -> BX
  1462. DEC BX
  1463. JMP flesc2 ;"wait for ESC
  1464. flbigclr CALL flbig ;file too big
  1465. flclr MOV.B workpn,#$00 ;clear work file name
  1466. JMP kmainlp ;"main loop
  1467. ksvchng XOR AX,AX ;Save if modified
  1468. INC AX ;set flag
  1469. JMP.b ksv2 ;'
  1470. ksvnoask XOR AX,AX
  1471. ksv2 CMP.B txchg,#$00 ;text changed ?
  1472. JZ ksvret ;:no - ret
  1473. OR AX,AX ;test flag
  1474. JZ ksave
  1475. CALL prints
  1476. B "Workfile ",$00
  1477. CALL kwworkpn ;write path name
  1478. CALL prints
  1479. B " not saved. Save",$00
  1480. MOV.B txchg,#$00 ;clear change flag
  1481. CALL yornln ;Y or N ?
  1482. JNZ ksave ;:yes
  1483. ksvret RET ;'
  1484. ksave CALL kgetfn ;S:Save file - get filename
  1485. MOV.B txchg,#$00 ;clear change flag
  1486. MOV SI,#workpn ;ptr work file name
  1487. CALL fnsisc ;copy it
  1488. CALL prints
  1489. B $0D,$0A,"Saving ",$00
  1490. CALL kwworkpn ;write path name
  1491. MOV DI,#pnbuf
  1492. CALL fnscdi ;copy filename into buffer
  1493. MOV SI,#extbak ;extension .BAK
  1494. CALL kext ;modify file name
  1495. MOV AH,#$41 ;delete old .BAK file
  1496. MOV DX,#scrpn ;scratch file name
  1497. CALL dos ;do it
  1498. MOV AH,#$56 ;rename file
  1499. MOV DX,#pnbuf ;current filename
  1500. MOV DI,#scrpn ;new filename
  1501. CALL dos ;do it: rename to .BAK
  1502. MOV AH,#$3C ;create new file
  1503. XOR CX,CX ;no attribute
  1504. MOV DX,#pnbuf ;current filename
  1505. PUSH DS ;DS -> ES
  1506. POP ES
  1507. CALL dos ;do create
  1508. JB ksren ;:error
  1509. XCHG AX,BX ;file handle
  1510. MOV DX,txbeg ;beg -> offset
  1511. MOV CX,txend ;end of text
  1512. MOV DI,CX
  1513. MOV.B [DI],#$1A ;store ^Z at the end
  1514. SUB CX,DX ;calc length
  1515. INC CX ;+1
  1516. MOV AH,#$40 ;write byte block
  1517. CALL dos ;do it
  1518. JB kserr ;:error
  1519. CMP AX,CX ;length = expected ?
  1520. JNZ kserr ;:no
  1521. JMP klnoeof ;'close that file
  1522. kserr MOV.B txchg,#$FF ;set changed flag
  1523. CALL klnoeof ;close that file
  1524. MOV AH,#$41 ;erase new file
  1525. MOV DX,#pnbuf
  1526. CALL dos
  1527. ksren MOV AH,#$56 ;rename it back to .PAS
  1528. MOV DX,#scrpn ;.BAK
  1529. MOV DI,#pnbuf ;-> .PAS
  1530. CALL dos ;do it
  1531. CALL xwriteln ;WriteLn
  1532. CALL ksfull ;write message
  1533. JMP kmainlp ;"return to main menu
  1534. ksfull CALL vidattr3 ;File not saved
  1535. CALL prints
  1536. B "Disk full or invalid directory path",$00
  1537. CALL waitesc ;wait for ESC
  1538. JMP knrmvid ;"
  1539. kdir CALL prints ;D:Directory
  1540. B "Dir mask",$00
  1541. CALL kreadln ;enter dir mask
  1542. MOV CX,#$000D ;*, ? allowed
  1543. CALL kparse2 ;parse filename
  1544. CALL krdend ;line end ?
  1545. MOV AH,#$1A ;set DMA transfer addr
  1546. MOV DX,#pnbuf ;buffer
  1547. CALL dos
  1548. MOV SI,#scrpn ;test pathname
  1549. kdtest MOV.B AL,[SI] ;get char
  1550. INC SI ;go to next
  1551. CMP AL,#$2A ;* ?
  1552. JZ kddoit ;:yes
  1553. CMP AL,#$3F ;?
  1554. JZ kddoit ;:yes
  1555. OR.B AL,AL ;end of string ?
  1556. JNZ kdtest ;:no
  1557. MOV.B AL,[SI]-$02 ;get last char
  1558. MOV SI,#fnany ;ptr to *.*
  1559. CMP AL,#$3A ;: ?
  1560. JZ kdwrit ;:yes
  1561. CMP AL,#$5C ;\ ?
  1562. JZ kdwrit ;:yes
  1563. MOV AH,#$4E ;search first dir entry
  1564. MOV CX,#$0010 ;attribute
  1565. MOV DX,#scrpn ;pathname
  1566. CALL dos ;do it
  1567. JB kddoit ;:error
  1568. TEST.B pndiratt,#$10 ;attribute ok ?
  1569. JZ kddoit ;yes, take it
  1570. MOV SI,#fnpath ;ptr to \*.*
  1571. kdwrit CALL kext2
  1572. kddoit CALL prints
  1573. B "Directory of ",$00
  1574. CALL kwscrpn ;write path name
  1575. CALL xwriteln ;WriteLn
  1576. MOV AH,#$4E ;get first entry
  1577. MOV CX,#$0010 ;attribute
  1578. MOV DX,#scrpn ;path name
  1579. CALL dos ;do it
  1580. JB kderr ;:error
  1581. XOR.B DL,DL ;clear flag
  1582. kddis OR.B DL,DL ;test flag
  1583. JNZ kdnocr ;:not first entry in line
  1584. CS:
  1585. MOV AL,txwinx2 ;line length / 16
  1586. XOR.B AH,AH
  1587. MOV DL,#$10
  1588. DIV.B DL
  1589. MOV.B DL,AL
  1590. kdnocr MOV SI,#pndirnm ;ptr to filename
  1591. TEST.B [SI]-$09,#$10 ;test attribute
  1592. JZ kdnodir ;:ok
  1593. CMP.B [SI],#$2E ;directory ?
  1594. JZ kdnext
  1595. CALL klowvid ;LowVideo
  1596. kdnodir CALL printpn ;write name
  1597. CALL knrmvid ;NormVideo
  1598. DEC.B DL ;another one in this line ?
  1599. JZ kdnextln ;:no
  1600. MOV CX,#pndirpad ;end for padding