TPSRC1 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. ;*** TURBO PASCAL version 3.01 A source code
  2. ;***
  3. ;*** commented by Pascal Dornier
  4. ;*** all rights reserved
  5. ;"***
  6. cseg $100 ;"COM file...
  7. ;
  8. ;I/O port equates
  9. ;
  10. timerfrq = $0042 ;timer: frequency
  11. timercmd = $0043 ;timer: command
  12. timerflg = $0061 ;"PPI: sound enable
  13. ;
  14. ;interrupt numbers
  15. ;
  16. bioscrt = $0010 ;BIOS: CRT driver
  17. bioskbd = $0016 ;BIOS: KBD driver
  18. msdos = $0021 ;"MS-DOS entry
  19. ;
  20. ;variable definitions
  21. ;
  22. attnrm = $0000 ;attribute NormVideo
  23. attlow = $0001 ;attribute LowVideo
  24. att2 = $0002 ;attribute #2 (used by editor)
  25. att3 = $0003 ;attribute #3
  26. txwinx1 = $0004 ;upper left edge current window
  27. txwiny1 = $0005
  28. scrmod = $0006 ;video mode
  29. coltxt = $0007 ;color or text ?
  30. attcur = $0008 ;current attribute
  31. grmod = $0009 ;graphics mode
  32. grwinx1 = $000A ;graphics window: upper left edge
  33. grwinx2 = $000C
  34. grwiny1 = $000E ; bottom right edge
  35. grwiny2 = $0010
  36. delaycnt = $0012 ;number of loop's for 1 ms
  37. collin = $0014 ;line color
  38. lnxdir = $0016 ;X direction
  39. lnydir = $0018 ;Y direction
  40. lnxpos = $001A ;X position
  41. lnypos = $001C ;Y position
  42. lndda = $001E ;DDA register
  43. grback = $0020 ;"graphics: background color
  44. ;heap pointer
  45. hpstrt = $0022 ;beginning of heap
  46. hpstrt1 = $0024
  47. hpdstpt = $0026 ;^ destination pointer
  48. hpdstpt1 = $0028
  49. hpesize = $002A ;size of entry to delete
  50. hpesize1 = $002C
  51. hplast = $002E ;^ previous entry
  52. hplast1 = $0030
  53. hpmerg = $0032 ;length of entry to be merged
  54. hpmerg1 = $0034 ;"with next entry
  55. coninbuf = $0036 ;CON input buffer
  56. pnbuf0 = $00B5
  57. pnbuf = $00B6 ;buffer for filename etc.
  58. pnbuf1 = $00B7
  59. pnbuf2 = $00B8
  60. pnbuf3 = $00B9
  61. pndiratt = $00CB ;for Dir: file attribute
  62. pndirnm = $00D4 ;name of file
  63. pndirpad = $00E4 ;^ end for formatting
  64. pnbufend = $0135 ;"end of buffer
  65. ;I/O vectors
  66. vkbdstat = $0136 ;KBD stat (ConStPtr)
  67. vkbdget = $0138 ;KBD get (ConInPtr)
  68. vconput = $013A ;CON put (ConOutPtr)
  69. vprnput = $013C ;PRN put (LstOutPtr)
  70. vauxput = $013E ;AUX put (AuxOutPtr)
  71. vauxget = $0140 ;AUX get (AuxInPtr)
  72. vusrput = $0142 ;USR put (UsrOutPtr)
  73. vusrget = $0144 ;"USR get (UsrInPtr)
  74. ;file entries for std files
  75. filcon = $0146 ;CON, TRM
  76. filkbd = $014A ;KBD
  77. fillst = $014E ;LST
  78. filaux = $0152 ;AUX
  79. filusr = $0156 ;USR
  80. stdin = $015A ;MS-DOS input file
  81. stdinfl = $015C ;flag
  82. stdinof = $015E ;^ buffer
  83. stdinsz = $0160 ;buffer size
  84. stdout = $0166 ;MS-DOS output file
  85. stdoutfl = $0168 ;flag
  86. stdoutof = $016A ;^ buffer
  87. stdoutsz = $016C ;"buffer size
  88. modeflg = $0172 ;option flag - see initmem
  89. spval = $0174 ;SP on initialisation
  90. turbocs = $0176 ;CS for return to Turbo
  91. turbods = $0178 ;DS for return to Turbo
  92. filtabpt = $017A ;^ into list of open files
  93. filemax = $017C ;max number of open files
  94. verror = $017E ;ErrorPtr
  95. errnum = $0180 ;error number
  96. conbufln = $0181 ;BufLen (for ReadLn)
  97. conbufpt = $0182 ;^ into input buffer
  98. conbfend = $0184 ;end of input buffer
  99. errpos = $0186 ;return address ->
  100. errpos2 = $0188 ;position of error
  101. hptop = $018A ;HeapPtr: ^ end of heap
  102. hptop1 = $018C
  103. svintv = $018E ;buffer for vector:
  104. svintv1 = $0190 ;DIV/0 interrupt
  105. lastkey = $0192 ;code of last key pressed
  106. cbreak = $0194 ;CBreak
  107. ovrpnbuf = $0196 ;"buffer for overlay filename
  108. fmtfield = $01E6 ;formatting: field size
  109. fmttype = $01E7 ;type of conversion
  110. fmtsdst = $01E8 ;^ dest string (STR)
  111. fmtsdst1 = $01EA
  112. fmtvdst = $01EC ;^ dest var (VAL)
  113. fmtvdst1 = $01EE
  114. fmtpdst = $01F0 ;^ error var (VAL)
  115. fmtpdst1 = $01F2
  116. recvbuf = $01F4 ;"real buffer: number to convert
  117. errio = $01FA ;flag: return because of error
  118. rndseed = $01FC ;random seed: last random number
  119. rndseed1 = $01FE
  120. strdstln = $0200 ;string operations: max. length of result
  121. strpos = $0202 ;Pos
  122. strnum = $0204 ;Num
  123. strtrgt = $0206 ;^ dest string
  124. strtrgt1 = $0208
  125. strobj = $020A ;^ object string
  126. strobj1 = $020C ;"
  127. remul11 = $020E ;real arithmetics
  128. remul11a = $020F ;first number * /
  129. remul12 = $0210
  130. remul13 = $0212
  131. remul21b = $0213
  132. remul21 = $0214 ;second number * /
  133. remul21a = $0215
  134. remul22 = $0216
  135. remul23 = $0218
  136. retrc1 = $021A ;number for Sqrt, ArcTan, polynomials
  137. retrc2 = $021C
  138. retrc3 = $021E
  139. resign = $0220 ;sign for + -
  140. resave = $0221
  141. remant = $0222 ;mantissa + -
  142. remant1 = $0223 ;"
  143. cvdecexp = $0224 ;real -> ASCII: decimal exponent
  144. cvexpcnt = $0225 ;ASCII -> real: counter for exponent
  145. cvoutbuf = $0226 ;output buffer for result
  146. currfil = $0232 ;^ current file var
  147. currfil1 = $0234
  148. filfunc = $0238 ;function code file operation
  149. filerr = $0239 ;error code, if failure
  150. prnum = $023A ;real: number to print
  151. filetab = $0240 ;"table of open files (file handles)
  152. ;kernel variables
  153. freemem = $0260 ;free memory (paragraphs)
  154. stackseg = $0262 ;stack segment on start
  155. stackpt = $0264 ;stack pointer
  156. destseg = $0266 ;segment of compiled program
  157. codesize = $0268 ;code size (paragraphs)
  158. datasize = $026A ;data size (paragraphs)
  159. minstksz = $026C ;min size stack + heap
  160. mincssz = $026E ;min size CS
  161. mindssz = $0270 ;min size DS
  162. minhpsz = $0272 ;min size free heap
  163. maxhpsz = $0274 ;max size free heap
  164. txbeg = $0276 ;^ beginning of text
  165. txend = $0278 ;^ end of text
  166. txmemend = $027A ;^ end of text memory
  167. txerrpos = $027C ;^ error in text
  168. vfilbig = $027E ;vector: file too big
  169. vnewfil = $0280 ;vector: file not found
  170. txcomp = $0282 ;0 = text not translated
  171. cpmode = $0283 ;(0 memory, 1 find error, 2 COM, 3 CHN)
  172. cperr = $0284 ;compiler's error number
  173. txchg = $0285 ;0 = text not changed
  174. defdrv = $0286 ;number of default drive
  175. scrpn = $0287 ;buffer for filename processing
  176. scrpnend = $02C6 ;end of buffer
  177. workpn = $02C7 ;filename work file
  178. mainpn = $0307 ;filename main file
  179. mainflg = $0347 ;0 = work file used
  180. msgflg = $0348 ;0 = error messages not read
  181. codedest = $0349 ;(1 = memory, 2 = COM, 3 = CHN)
  182. parmlin = $034A ;buffer: input line for program
  183. knumbuf = $0386 ;number output buffer
  184. curatt = $038E ;"number current video attribute
  185. ;editor variables
  186. srend = $0390 ;^ block end for search
  187. srbeg = $0392 ;^ block beg for search
  188. bkbeg = $0394 ;^ block beg
  189. bkend = $0396 ;^ block end
  190. lnupper = $0398 ;^ line above
  191. disbeg = $039A ;^ beginning of text displayed
  192. oldpos = $039C ;old position
  193. eolpos = $039E ;^ end of line
  194. srpos = $03A0 ;current search pos
  195. srcnt = $03A2 ;search counter
  196. horscr = $03A4 ;horizontal scrolling
  197. attflg = $03A5 ;(1 = block beg, 2 = block end in curr line)
  198. phrow = $03A6 ;cursor position
  199. phcol = $03A7
  200. statobs = $03A8 ;0 = invalid status line
  201. edcol = $03A9 ;column
  202. attchg = $03AA ;FF = attribute changes in curr line
  203. sropt = $03AB ;options for search
  204. ; 1=entire words, 2=replace without query
  205. ; 4=upper = lower, 8=global
  206. ;10=backwards 20=L (?)
  207. srmode = $03AC ;0=search, FF=search and replace
  208. editflg = $03AD ;? never referenced !
  209. bkhide = $03AE ;FF = invisible block
  210. scrfl1 = $03AF ;FF = short redisplay
  211. statera = $03B0 ;# chars to delete in status line
  212. oldlen = $03B1 ;old length curr line
  213. dislin = $03B2 ;redisplay from line ...
  214. overflg = $03B3 ;0 = overwrite, FF = insert
  215. indntflg = $03B4 ;0 = normal, FF = indent
  216. disflg = $03B6 ;FF = don't display
  217. scrfl2 = $03B7 ;redisplay: 0 = small displacement
  218. bkbegl = $03BA ;^ block beg in curr line
  219. bkendl = $03BC ;^ block end in curr line
  220. edpos = $03BE ;^ current line
  221. lnpos = $03C0 ;pos in line buffer
  222. posfifo = $03C2 ;old position for ^QP
  223. pfifosrc = $03C5
  224. qppos = $03C6
  225. qppos1 = $03C8
  226. pfifodst = $03C9 ;(for block transfer)
  227. cmdbuf = $03CA ;buffer for command entry
  228. cmdbuf1 = $03CB
  229. srword = $03CE ;max length of search word
  230. srword1 = $03CF ;length
  231. srword2 = $03D0 ;string
  232. srrepl = $03EF ;replace word
  233. srrepl1 = $03F0
  234. srrepl2 = $03F1
  235. stopt = $0410 ;options for search / replace
  236. sropt1 = $0411
  237. fnbuf = $041D ;buffer for filename entry
  238. fnbuf2 = $041F
  239. fnbufend = $0460
  240. nbkbeg = $0461 ;block transfer destination
  241. nbk = $0463 ;block
  242. sepptr = $0465 ;^ word separator table
  243. explen = $0467 ;expected length
  244. curpast = $0469 ;1 = cursor past end of line
  245. line0 = $046B
  246. line = $046C ;buffer: current line
  247. lineend0 = $04E9
  248. lineend1 = $04EA
  249. lineend = $04EB
  250. dmabuf = $04EE ;buffer for redisplay
  251. scrseg = $0590 ;segment of video memory
  252. scrrow = $0592 ;video row
  253. scrbad = $0593 ;"FF = snowy screen
  254. ;compiler variables
  255. spsav = $0594 ;SP at start
  256. symtop = $0596 ;current end of symbol table
  257. symtop2 = $0598 ;end of symbol table
  258. ptcbeg = $059A ;^ beg symbol table, patch list
  259. tyfence = $059C ;limit for undefined pointer types
  260. fence = $059E ;limit for search on new definition
  261. pc = $05A0 ;PC of emitted code
  262. dc = $05A2 ;data offset of emitted code
  263. varspc = $05A4 ;space used on stack
  264. cdptr = $05A6 ;^ into code buffer
  265. cdbufpt = $05A8 ;PC of beg code buffer
  266. cdbegpt = $05AA ;^ code buffer
  267. cdfoff = $05AC ;buffer's offset in file
  268. cdprcoff = $05AD ;offset for overlay
  269. cdfoff1 = $05AE
  270. lincnt = $05B0 ;line counter
  271. cdinval = $05B2 ;<> 0: invalid code
  272. recnum = $05B3 ;number of current record
  273. reccnt = $05B4 ;record counter
  274. scalcnt = $05B5 ;enumeration type counter
  275. srcend = $05B6 ;<> 0: end of source reached
  276. lexnest = $05B7 ;lexical nesting
  277. flgpshax = $05B8 ;<> 0: save AX on stack
  278. flgpshes = $05B9 ;<> 0: save ES on stack
  279. flgpshdi = $05BA ;<> 0: save DI on stack
  280. usrint = $05BB ;<> 0: user interrupt used
  281. ovrcnt = $05BC ;overlay counter
  282. inclflg = $05BD ;FF = include file used
  283. cmaxfil = $05BF ;max number of open files
  284. cinpsize = $05C1 ;size of std input buffer
  285. coutsize = $05C3 ;size of std output buffer
  286. direct = $05C5 ;compiler directives:
  287. ; 1 = I/O check
  288. ; 2 = range check
  289. ; 4 = I/O mode (CON or TRM)
  290. ; 8 = value for CBreak
  291. ;10 = user interrupt
  292. ;20 = stack check
  293. ;40 = type check
  294. ;80 = device check
  295. destpn = $05C7 ;object filename
  296. destpne = $0603
  297. dstfile = $0607 ;object file handle
  298. ptctop = $0609 ;current end of patch list
  299. ptcend = $060B ;limit for patch list
  300. srcptr = $060D ;^ into text
  301. srclnbeg = $060F ;^ beg of source line
  302. chptr = $0611 ;^ into line buffer
  303. ;variable entry 1:
  304. indflg = $0615 ;<> 0: indexed var
  305. indptflg = $0616 ;<> 0: indirect via pointer
  306. varseg = $0617 ;segment (FF=DS, FE=CS, FD=ES, else:
  307. ;lexical nesting
  308. varofs = $0618 ;variable offset
  309. vartp = $061A ;type
  310. varctp = $061C ;element type
  311. varnest = $061D ;<>0: record #, FF: undef pointer
  312. lower = $061E ;lower bound or ^ index type
  313. upper = $0620 ;upper bound or ^ element type
  314. varsize = $0622 ;variable size
  315. parm1end = $0624
  316. parm2 = $0625 ;variable entry 2
  317. var2ctp = $062C ;type
  318. lower2 = $062E ;lower bound
  319. upper2 = $0630 ;upper bound
  320. var2size = $0632 ;size
  321. maxsize = $0634 ;max size for variant records
  322. uncrlink = $0636 ;link for uncrunch list
  323. flgvar = $0638 ;F = VAR parameter
  324. vrecflg = $0639 ;number of record variant
  325. procfnc = $063A ;procedure or function
  326. ovrproc = $063B ;<>0: overlay procedure
  327. absflg = $0647 ;FF = Absolute variable
  328. var3ofs = $0648 ;offset
  329. var3seg = $064A ;segment
  330. ovrlen = $064C ;max length of overlay procedures in a file
  331. creal1 = $064E ;buffer for real constant
  332. creal2 = $0650
  333. creal3 = $0652
  334. cresign = $0653
  335. stklev = $0654 ;stack use (WITH, FOR, display)
  336. casectp = $0655 ;CASE element type
  337. direcsv = $0656 ;directives at beg of statement
  338. brnchop = $0658 ;branch op on comparision
  339. rdlnflg = $0659 ;flag: Read / ReadLn
  340. forptr = $065A ;pointer for FOR: TO / DOWNTO
  341. withnest = $065C ;WITH nesting
  342. inlinflg = $065D ;inline flag
  343. withtab = $065E ;WITH table: record number, segment
  344. withtab1 = $0660 ;offset, FFFF = indexed
  345. functp = $069E ;^ result type
  346. comptp = $06A0 ;^ type for comparison
  347. oldpc = $06A2 ;PC before translation of this atom
  348. negflg = $06A4 ;negation flag
  349. exres = $06A6 ;integer constant
  350. cxbuf = $06A8 ;buffer for CX
  351. direcin = $06AA ;directives before include
  352. semiflg = $06AC ;flag for missing ; error
  353. wordflg = $06AD ;type of word read
  354. typept = $06AE ;^ type
  355. sympos = $06B0 ;^ into symbol table
  356. wrdend = $06B2 ;end of word read
  357. retbuf = $06B4 ;buffer for return address
  358. inclpn = $06B6 ;include filename
  359. incfile = $06F6 ;include file handle
  360. bufpt = $06F8 ;include pointer
  361. bufend = $06FA ;end of include buffer
  362. srclnbg = $06FC ;beg of line in buffer
  363. frelpos = $06FE ;relative position in file
  364. ptcbuf1 = $0700 ;buffer for patch
  365. wordbuf = $0702 ;buffer for word, filename, string...
  366. wrdbuf1 = $0703
  367. inclbuf = $0782 ;include buffer
  368. txstrt = $0802 ;"beg of text space / error messages
  369. JMP start ;"jump to main code
  370. B $90,$90,$CD,$AB
  371. B "Copyright (C) 1985 BORLAND Inc"
  372. B $02,$04,$00
  373. W ecmd1 ;ptrs for TINST.COM
  374. B $00
  375. W errpath
  376. B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  377. B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  378. B $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  379. displstr B $14,"Default display mod"
  380. B $65
  381. txwinx2 B $50 ;lower edge of text window
  382. txwiny2 B $19
  383. B $01,$FF,$FF
  384. attmono B $0F,$07,$07,$70 ;monochrome attributes
  385. attbwgr B $0F,$07,$07,$70 ;mono graphic atts
  386. attcolgr B $0E,$07,$07,$4F ;"color graphic atts
  387. putstr CS: ;put attribute string
  388. MOV.B AH,[BX] ;length
  389. OR.B AH,AH
  390. STC
  391. JZ puts2 ;nothing to put
  392. putstrl INC BX ;next char
  393. CS:
  394. MOV.B AL,[BX] ;get it
  395. PUSH AX ;save cnt
  396. CALL conput ;put CRT
  397. POP AX
  398. DEC.B AH ;another one ?
  399. JNZ putstrl ;:yes
  400. CLC
  401. puts2 RET ;"
  402. meascnt W $0000
  403. measdone B $00
  404. vtimer W $0000 ;"space for timer int vector
  405. vtimer1 W $0000
  406. msspeed MOV delaycnt,#$006E ;measure CPU speed
  407. CS: ;measurement value
  408. MOV.B measdone,#$00 ;flag:not done
  409. MOV SI,#timvec ;ptr to timer INT
  410. ES:
  411. MOV AX,[SI]
  412. CS:
  413. MOV vtimer,AX ;save it
  414. ES:
  415. MOV AX,[SI]$02
  416. CS:
  417. MOV vtimer1,AX
  418. CLI
  419. ES:
  420. MOV [SI],#msint1
  421. ES:
  422. MOV [SI]$02,CS
  423. STI ;INT ok again
  424. JMP.b mssploop ;"measurement loop
  425. msint1 PUSH DS ;first INT entry
  426. PUSH AX
  427. XOR AX,AX
  428. MOV DS,AX
  429. MOV timvec,#msint2 ;set second vector
  430. CS:
  431. MOV meascnt,AX ;clear counter
  432. POP AX
  433. POP DS
  434. CS:
  435. JMPF [vtimer] ;"do timer routine
  436. msint2 CS: ;second INT entry
  437. MOV.B measdone,#$FF ;set flag:done
  438. CS:
  439. JMPF [vtimer] ;"do timer routine
  440. mssploop CALL delay1ms ;wait one step
  441. CS:
  442. INC meascnt ;count those steps
  443. CS:
  444. CMP.B measdone,#$FF ;done ?
  445. JNZ mssploop ;no, continue counting
  446. CS:
  447. MOV AX,vtimer1 ;restore timer INT vec
  448. CLI
  449. ES:
  450. MOV [SI]$02,AX
  451. CS:
  452. MOV AX,vtimer
  453. ES:
  454. MOV [SI],AX
  455. STI ;INT ok again
  456. CS:
  457. MOV AX,meascnt ;number of steps done
  458. ADD AX,AX ;*2
  459. MOV delaycnt,AX ;-> result
  460. RET ;"
  461. delaybx MOV AX,BX ;Delay(BX)
  462. xdelay MOV CX,AX ;DELAY(AX)
  463. JCXZ delay2 ;:no delay
  464. delay1 CALL delay1ms ;delay 1ms
  465. LOOP delay1
  466. delay2 RET ;"
  467. delay1ms PUSH CX ;Delay 1 ms
  468. MOV CX,delaycnt ;get count for 1ms
  469. delay3 LOOP delay3 ;do it
  470. POP CX ;restore cnt
  471. RET ;"
  472. xclrscr PUSH BP ;CLRSCR
  473. MOV AH,#$0F ;get screen stat
  474. INT bioscrt
  475. POP BP
  476. CMP.B AL,scrmod ;= current screen mode ?
  477. JZ clrscr1 ;:ok
  478. MOV AL,scrmod ;no: do set it
  479. JMP xtxtmode ;'
  480. clrscr1 PUSH BP
  481. MOV AX,#$0600 ;scroll window up, 0 lines
  482. MOV.B BH,attcur
  483. MOV CX,txwinx1 ;upper left edge
  484. CS:
  485. MOV DX,txwinx2 ;lower right edge
  486. DEC.B DH
  487. DEC.B DL
  488. INT bioscrt ;clear window
  489. MOV AH,#$02 ;set cursor position
  490. MOV DX,txwinx1 ;upper left edge
  491. XOR.B BH,BH
  492. INT bioscrt ;do it
  493. POP BP
  494. RET ;"
  495. xdelline PUSH BX ;DelLine
  496. PUSH CX
  497. PUSH DX
  498. PUSH BP
  499. CALL getcpos ;get cursor pos
  500. MOV AH,#$06 ;scroll window up
  501. doscroll MOV AL,#$01 ;one line
  502. MOV.B BH,attcur
  503. MOV.B CH,DH
  504. MOV.B CL,txwinx1 ;upper left edge
  505. CS:
  506. MOV DX,txwinx2 ;lower right of window
  507. DEC.B DH
  508. DEC.B DL
  509. CMP.B CH,DH ;same ?
  510. JNZ dellin1 ;:no
  511. XOR.B AL,AL ;no lines
  512. dellin1 INT bioscrt ;do it
  513. POP BP
  514. POP DX
  515. POP CX
  516. POP BX
  517. RET ;"
  518. xinsline PUSH BX ;InsLine
  519. insline2 PUSH CX
  520. PUSH DX
  521. PUSH BP
  522. CALL getcpos ;get cursor pos
  523. MOV AH,#$07 ;scroll window down
  524. JMP doscroll ;"as above
  525. xlowvid PUSH AX ;LowVideo
  526. MOV AL,attlow ;set low attribute
  527. MOV attcur,AL
  528. POP AX
  529. RET ;"
  530. xnormvid PUSH AX ;NormVideo, HighVideo
  531. MOV AL,attnrm ;set normal attribute
  532. MOV attcur,AL
  533. POP AX
  534. RET ;"
  535. getcpos MOV AH,#$03 ;get cursor position
  536. XOR.B BH,BH ;page 0
  537. INT bioscrt ;do it
  538. RET ;"
  539. xclreol PUSH BX ;ClrEol
  540. PUSH CX
  541. PUSH DX
  542. PUSH BP
  543. CALL getcpos ;get cursor pos
  544. MOV AX,#$0600 ;clear window
  545. MOV.B BH,attcur
  546. MOV CX,DX ;pos -> upper left
  547. CS:
  548. MOV.B DL,txwinx2 ;X-position
  549. DEC.B DL ;Y-pos from current pos
  550. INT bioscrt ;do it
  551. POP BP
  552. POP DX
  553. POP CX
  554. POP BX
  555. RET ;"
  556. xcrtinit CALL xnosound ;CrtInit
  557. CS: ;Screen mode
  558. MOV AL,scrmodch ;defined with TINST
  559. CMP AL,#$FF
  560. JNZ xtxtmode ;do change it
  561. PUSH BP
  562. MOV AH,#$0F ;get current screen mode
  563. INT bioscrt
  564. POP BP
  565. xtxtmode MOV.B txwinx1,#$00 ;TextMode
  566. MOV.B txwiny1,#$00 ;set window
  567. MOV.B grmod,#$FF ;no graphics mode
  568. CMP AL,#$07 ;monochrome ?
  569. MOV BH,#$50
  570. MOV BL,#$00
  571. MOV SI,#attmono ;ptr to screen attributes
  572. JZ txtmd3 ;:yes, mono
  573. MOV SI,#attcolgr
  574. CMP AL,#$02 ;BW80 ?
  575. JZ txtmd2 ;:yes
  576. CMP AL,#$04
  577. JB txtmd1 ;:C80, C40, BW40
  578. MOV AL,#$03
  579. txtmd1 MOV BL,#$FF
  580. CMP AL,#$03 ;C80 ?
  581. JZ txtmd3 ;:yes
  582. MOV BH,#$28
  583. CMP AL,#$01 ;C40 ?
  584. JZ txtmd3 ;:yes
  585. XOR.B AL,AL ;monochrome
  586. MOV BL,#$00
  587. txtmd2 MOV SI,#attbwgr
  588. txtmd3 MOV scrmod,AL ;set screen mode
  589. MOV.B coltxt,BL ;color or mono
  590. CS:
  591. MOV.B txwinx2,BH ;set screen size
  592. CS:
  593. MOV AX,[SI] ;get screen attributes
  594. MOV attnrm,AX
  595. CS:
  596. MOV AX,[SI]$02
  597. MOV att2,AX
  598. PUSH BP
  599. MOV AH,#$0F ;get screen status
  600. INT bioscrt
  601. CMP.B AL,scrmod ;correct mode ?
  602. JZ txtmd4 ;:yes
  603. MOV AL,scrmod
  604. XOR.B AH,AH ;set screen mode
  605. INT bioscrt
  606. txtmd4 POP BP
  607. JMP xnormvid ;"
  608. xcrtexit RET ;"CrtExit
  609. setcpos PUSH AX ;Set cursor position
  610. PUSH BX ;DL=row
  611. PUSH CX ;DH=col
  612. PUSH DX ;pos relative to curr window
  613. PUSH SI
  614. PUSH DI
  615. PUSH BP
  616. PUSHF
  617. XCHG.B DL,DH
  618. ADD DX,txwinx1 ;add window pos
  619. CS:
  620. CMP.B DH,txwiny2 ;over edge of screen ?
  621. JNB setcbad ;:yes
  622. CS:
  623. CMP.B DL,txwinx2
  624. JNB setcbad ;:yes
  625. MOV AH,#$02 ;set cursor
  626. XOR.B BH,BH ;page 0
  627. INT bioscrt
  628. setcbad POPF
  629. POP BP
  630. POP DI
  631. POP SI
  632. POP DX
  633. POP CX
  634. POP BX
  635. POP AX
  636. RET ;"
  637. xupcase JMP upcase ;"UpCase
  638. xwherex CALL getcpos ;WhereX
  639. MOV.B AL,DL ;get cursor pos
  640. SUB.B AL,txwinx1 ;col-window col
  641. INC.B AL ;+1
  642. XOR.B AH,AH
  643. RET ;"
  644. xwherey CALL getcpos ;WhereY
  645. MOV.B AL,DH ;get cursor pos
  646. SUB.B AL,txwiny1 ;row-window row
  647. INC.B AL ;+1
  648. XOR.B AH,AH
  649. RET ;"
  650. xwindow POP BX ;Window
  651. CMP AL,#$19 ;Row 2 - limit to 25
  652. JA window1 ;:too much
  653. CS:
  654. MOV txwiny2,AL ;set it
  655. window1 POP AX ;Col 2
  656. CMP AL,#$50 ;limit to 80
  657. JA window2 ;:too much
  658. CS:
  659. MOV txwinx2,AL ;set it
  660. window2 POP AX ;Row 1
  661. CS:
  662. CMP.B AL,txwiny2 ;> row 2 ?
  663. JNB window3 ;: no good
  664. DEC.B AL
  665. MOV txwiny1,AL ;set it
  666. window3 POP AX ;Col 1
  667. CS:
  668. CMP.B AL,txwinx2 ;> col 2
  669. JNB window4 ;:no good
  670. DEC.B AL
  671. MOV txwinx1,AL ;set it
  672. window4 JMP BX ;"return
  673. xtxtcol AND AL,#$1F ;TextColor
  674. TEST AL,#$10 ;Blink ?
  675. JZ txtcol1 ;:no
  676. AND AL,#$0F
  677. OR AL,#$80 ;set blink flag
  678. txtcol1 AND.B attcur,#$70
  679. OR.B attcur,AL ;set new attribute
  680. RET ;"
  681. xtxtbg AND AL,#$07 ;TextBackground
  682. MOV CL,#$04
  683. SHL.B AL,CL
  684. AND.B attcur,#$8F
  685. OR.B attcur,AL ;set attribute
  686. RET ;"
  687. setgmod PUSH BP ;Set graphic mode
  688. MOV grwinx2,AX ;X-size
  689. MOV grwinx1,#$0000 ;clear window
  690. MOV grwiny1,#$0000
  691. MOV grwiny2,#$00C7 ;Y-size = 199
  692. MOV AL,grmod
  693. XOR.B AH,AH
  694. INT bioscrt ;set graph mode
  695. XOR BX,BX
  696. MOV.B grback,BL ;clear background
  697. MOV AH,#$0B ;set palette -> backgrnd
  698. INT bioscrt
  699. INC.B BH ;set foregrnd
  700. MOV AH,#$0B
  701. INT bioscrt ;set palette
  702. POP BP
  703. RET ;"
  704. xgrcolmd MOV.B grmod,#$04 ;GraphColorMode
  705. setgmod2 MOV AX,#$013F ;X-size = 319
  706. JMP setgmod ;'set it
  707. xgrmode MOV.B grmod,#$05 ;GraphMode
  708. JMP setgmod2 ;"set it
  709. xhires MOV.B grmod,#$06 ;Hires
  710. MOV AX,#$027F ;X-size = 639
  711. CALL setgmod ;set it
  712. MOV AX,#$000F ;set background
  713. JMP.b xhirscol ;"
  714. xgrbg AND AL,#$0F ;GraphBackground
  715. MOV.B AH,grback ;get old color
  716. AND.B AH,#$10
  717. OR.B AL,AH
  718. MOV grback,AL ;store it
  719. setbg PUSH BP ;set graph background
  720. XOR.B BH,BH
  721. MOV.B BL,grback
  722. MOV AH,#$0B ;set palette
  723. INT bioscrt ;do it
  724. POP BP
  725. RET ;"
  726. xpalette PUSH BP ;set palette AL
  727. MOV.B BL,grback ;get current color
  728. AND.B BL,#$EF ;clear palette
  729. MOV AH,#$02
  730. CMP.B grmod,#$04 ;color graphics ?
  731. JZ setpal1 ;yes
  732. MOV AH,#$01
  733. setpal1 CMP.B AL,AH
  734. JB setpal2
  735. SUB.B AL,AH ;upper bit: part of backgnd
  736. OR.B BL,#$10
  737. setpal2 MOV.B grback,BL ;set it
  738. MOV BH,#$01 ;set palette
  739. MOV.B BL,AL ;palette number
  740. MOV AH,#$0B
  741. INT bioscrt ;do it
  742. POP BP
  743. JMP setbg ;"set backgnd color
  744. xhirscol PUSH BP ;HiresColor
  745. MOV BX,AX ;as background
  746. MOV AH,#$0B ;set palette
  747. INT bioscrt ;do it
  748. POP BP
  749. RET ;"
  750. xgrwindw POP BX ;GraphWindow
  751. MOV CX,#$027F ;max. X = 639
  752. CMP.B grmod,#$06 ;Hires ?
  753. JZ gwind1 ;:yes
  754. MOV CX,#$013F ;max. X = 319
  755. gwind1 CMP AX,#$00C7 ;Y2 > 199
  756. JA gwind2 ;:no good
  757. MOV grwiny2,AX ;set Y2
  758. gwind2 POP AX ;X2
  759. CMP AX,CX ;> max X ?
  760. JA gwind3 ;:no good
  761. MOV grwinx2,AX ;set X2
  762. gwind3 POP AX ;Y1
  763. CMP AX,grwiny2 ;>= Y2 ?
  764. JNB gwind4 ;:no good
  765. MOV grwiny1,AX ;set Y1
  766. gwind4 POP AX ;X1
  767. CMP AX,grwinx2 ;>= X2 ?
  768. JNB gwind5 ;:no good
  769. MOV grwinx1,AX ;set X1
  770. gwind5 JMP BX ;"return
  771. xplot POP BX ;Plot
  772. POP DX ;Y-pos
  773. POP CX ;X-pos
  774. PUSH BX ;restore return addr
  775. MOV AH,#$0C ;set point, AL is color
  776. doplot OR CX,CX ;test X-pos (do clipping)
  777. JS noplot ;negative: clip it
  778. ADD CX,grwinx1 ;add window offset
  779. CMP CX,grwinx2 ;outside window ?
  780. JA noplot ;yes: clip it
  781. OR DX,DX ;test Y-pos
  782. JS noplot ;negative: clip it
  783. ADD DX,grwiny1 ;add window offset
  784. CMP DX,grwiny2 ;outside window ?
  785. JA noplot ;yes: clip it
  786. PUSH BP
  787. INT bioscrt ;do plot
  788. POP BP
  789. noplot RET ;"
  790. xdraw MOV AH,#$0C ;Line. AL is color
  791. MOV collin,AX ;set color, command:plot
  792. POP DI ;return addr
  793. POP AX ;Y2
  794. POP DX ;X2
  795. POP BX ;Y1
  796. MOV lnypos,BX ;store it
  797. CALL getdelta ;calculate direction
  798. MOV lnydir,CX ;store it
  799. CALL iabs ;ABS(AX)
  800. XCHG AX,DX ;DX:=Y-distance YD
  801. POP BX ;X1
  802. PUSH DI ;restore ret addr
  803. MOV lnxpos,BX ;store X1
  804. CALL getdelta ;calculate direction
  805. MOV lnxdir,CX ;store it
  806. CALL iabs ;ABS(AX)
  807. MOV BX,AX ;BX:=X-distance XD
  808. CMP BX,DX ;XD <= YD ?
  809. JLE lnyline ;yes:Y-oriented line
  810. MOV AX,DX ;X-oriented line
  811. ADD AX,AX
  812. SUB AX,BX
  813. MOV lndda,AX ;DDA:=YD+YD-XD
  814. MOV CX,BX ;XD -> count
  815. INC CX
  816. lnxloop CALL lnplot ;plot point with clipping
  817. MOV AX,lndda ;test DDA
  818. OR AX,AX
  819. JLE lnxnostp ;:no step
  820. ADD AX,DX ;DDA:=DDA+YD+YD-XD-XD
  821. ADD AX,DX
  822. SUB AX,BX
  823. SUB AX,BX
  824. MOV lndda,AX
  825. MOV AX,lnydir ;Ypos:=Ypos+Ydir
  826. ADD lnypos,AX
  827. JMP.b lnxcont ;'
  828. lnxnostp ADD AX,DX ;DDA:=DDA+YD+YD;
  829. ADD AX,DX
  830. MOV lndda,AX
  831. lnxcont MOV AX,lnxdir ;Xpos:=Xpos+Xdir
  832. ADD lnxpos,AX
  833. LOOP lnxloop ;another step
  834. RET ;'
  835. lnyline MOV AX,BX ;Y-oriented line
  836. ADD AX,AX
  837. SUB AX,DX
  838. MOV lndda,AX ;DDA:=XD+XD-YD
  839. MOV CX,DX ;YD -> count
  840. INC CX
  841. lnyloop CALL lnplot ;plot point with clipping
  842. MOV AX,lndda ;test DDA
  843. OR AX,AX
  844. JLE lnynostp ;:no step
  845. ADD AX,BX ;DDA:=DDA+XD+XD-YD-YD
  846. ADD AX,BX
  847. SUB AX,DX
  848. SUB AX,DX
  849. MOV lndda,AX
  850. MOV AX,lnxdir ;Xpos:=Xpos+Xdir
  851. ADD lnxpos,AX
  852. JMP.b lnycont ;'
  853. lnynostp ADD AX,BX ;DDA:=DDA+XD+XD
  854. ADD AX,BX
  855. MOV lndda,AX
  856. lnycont MOV AX,lnydir ;Ypos:=Ypos+Ydir
  857. ADD lnypos,AX
  858. LOOP lnyloop ;:another one
  859. RET ;"
  860. getdelta XOR CX,CX ;calculate direction -> CX
  861. SUB AX,BX ;compare them
  862. JZ deltazer ;equal: CX=0
  863. JS deltaneg ;:negative
  864. INC CX ;positive: CX=1
  865. RET ;'
  866. deltaneg DEC CX ;negative: CX=-1
  867. deltazer RET ;"
  868. lnplot PUSH CX ;Set line point with clipping
  869. PUSH DX ;save count, YD
  870. MOV AX,collin ;color, command
  871. MOV CX,lnxpos ;Xpos
  872. MOV DX,lnypos ;Ypos
  873. CALL doplot ;plot that point
  874. POP DX
  875. POP CX
  876. RET ;"
  877. xsound MOV BX,AX ;Sound
  878. MOV AX,#$34DD ;for frequency calculation
  879. MOV DX,#$0012
  880. CMP DX,BX ;frequency < 12 Hz ?
  881. JNB sounddis ;:might damage speaker
  882. DIV BX ;calculate timer value
  883. MOV BX,AX
  884. IN AL,timerflg ;sound on ?
  885. TEST AL,#$03
  886. JNZ soundon ;:yes
  887. OR AL,#$03 ;switch it on
  888. OUT timerflg,AL
  889. MOV AL,#$B6 ;set frequency
  890. OUT timercmd,AL
  891. soundon MOV.B AL,BL ;set freq lo
  892. OUT timerfrq,AL
  893. MOV.B AL,BH ;set freq hi
  894. OUT timerfrq,AL
  895. sounddis RET ;"
  896. xnosound IN AL,timerflg ;NoSound
  897. AND AL,#$FC ;switch it off
  898. OUT timerflg,AL
  899. RET ;"
  900. xgetmem XCHG AX,CX ;GetMem, AX=length requested
  901. POP BX ;ret addr
  902. POP DI ;dest ptr
  903. JMP.b new1 ;"like New
  904. hpconv PUSH AX ;change representation:
  905. PUSH CX ;AX=ofs 0..15, BX=seg
  906. MOV CL,#$04
  907. SHR AX,CL
  908. ADD BX,AX ;seg:=seg+ofs DIV 16
  909. POP CX
  910. POP AX
  911. AND AX,#$000F ;ofs:=ofs MOD 16
  912. RET ;"
  913. hpcmp CMP BX,DX ;Compare BX:AX with DX:CX
  914. JNZ hpcmp1
  915. CMP AX,CX
  916. hpcmp1 RET ;"
  917. hpadd ADD AX,CX ;BX:AX + DX:CX -> BX:AX
  918. ADD BX,DX
  919. JMP hpconv ;"change representation
  920. hplen ES: ;Get length of entry
  921. MOV AX,[DI]$04
  922. ES:
  923. MOV BX,[DI]$06
  924. PUSH AX
  925. OR AX,BX ;test if end of heap = 0
  926. POP AX
  927. RET ;"
  928. xnew POP BX ;New
  929. new1 POP ES ;dest ptr
  930. PUSH BX ;restore ret
  931. MOV hpdstpt,DI ;save addr dest ptr
  932. MOV hpdstpt1,ES
  933. MOV AX,CX ;number of bytes wanted
  934. ADD AX,#$0007 ;+7
  935. MOV BX,#$1000 ;carry ?
  936. JB new2 ;:yes
  937. XOR BX,BX ;no carry
  938. new2 AND AL,#$F8 ;space allocated is n*8
  939. CALL hpconv ;convert to seg,ofs
  940. MOV CX,AX ;needed size
  941. MOV DX,BX
  942. MOV hplast,#$0022 ;last entry
  943. MOV hplast1,DS
  944. LES DI,hpstrt ;get start of heap
  945. newseek CALL hplen ;get len of entry
  946. JZ newend ;:end of heap
  947. CALL hpcmp ;sufficient size ?
  948. JNB newfnd ;:large enough
  949. MOV hplast,DI ;remember last entry
  950. MOV hplast1,ES
  951. ES: ;get next entry
  952. LES DI,[DI]
  953. JMP newseek ;'continue searching
  954. newfnd CALL newdest ;store ES:DI to dest ptr
  955. JZ newfits ;equal - nothing to crunch
  956. SUB AX,CX ;calculate superfluous mem
  957. SBB BX,DX
  958. AND AX,#$000F
  959. JMP.b newrem ;'mark the remainder as free
  960. newfits ES: ;get next entry
  961. LES DI,[DI]
  962. JMP.b newlink ;'set link to it
  963. newend CALL newdest
  964. MOV AX,DI
  965. MOV BX,ES
  966. CALL hpadd ;sum up sizes
  967. MOV hptop,AX ;new heap top
  968. MOV hptop1,BX
  969. PUSH CX ;save size of entry
  970. PUSH DX
  971. MOV CX,AX ;test if heap overflow
  972. MOV DX,BX
  973. MOV AX,SP ;heap top - stack top
  974. MOV BX,SS
  975. SUB BX,#$0E
  976. CALL hpconv ;convert sp
  977. XOR AX,AX
  978. CALL hpcmp ;compare them
  979. POP DX
  980. POP CX
  981. JA newmemok ;:ok
  982. JMP chkstk1 ;'Error FF - memory overflow
  983. newmemok XOR AX,AX ;mark next entry
  984. XOR BX,BX ;as end of heap
  985. newrem PUSH BX ;save length
  986. PUSH AX
  987. ES: ;save ptr to next entry
  988. PUSH [DI]$02
  989. ES:
  990. PUSH [DI]
  991. MOV AX,DI ;try to put together with
  992. MOV BX,ES ;next entry
  993. CALL hpadd ;calc end of this entry
  994. MOV DI,AX ;new top
  995. MOV ES,BX
  996. ES: ;now produce that entry
  997. POP [DI] ;link
  998. ES:
  999. POP [DI]$02
  1000. ES:
  1001. POP [DI]$04 ;length
  1002. ES:
  1003. POP [DI]$06
  1004. newlink PUSH ES ;save ES
  1005. PUSH ES
  1006. LES SI,hplast ;store ES:DI in last
  1007. ES: ;entry as link to next entry
  1008. MOV [SI],DI
  1009. ES:
  1010. POP [SI]$02
  1011. POP ES ;restore ES
  1012. RET ;"
  1013. newdest PUSH ES ;store ES:DI in dest ptr
  1014. PUSH ES
  1015. LES SI,hpdstpt
  1016. ES:
  1017. MOV [SI],DI
  1018. ES:
  1019. POP [SI]$02
  1020. POP ES
  1021. RET ;"
  1022. xfreemem XCHG AX,CX ;FreeMem
  1023. POP BX ;ret addr
  1024. POP DI ;get ptr
  1025. JMP.b disp1 ;'like Dispose
  1026. xdispose POP BX ;Dispose
  1027. disp1 POP ES ;get dest ptr
  1028. PUSH BX ;restore ret
  1029. MOV AX,CX ;number of bytes
  1030. ES:
  1031. MOV CX,[DI] ;get value of ptr
  1032. ES:
  1033. MOV DX,[DI]$02
  1034. ADD AX,#$0007 ;size+7
  1035. MOV BX,#$1000 ;carry ?
  1036. JB disp2 ;:yes
  1037. XOR BX,BX ;no carry
  1038. disp2 AND AL,#$F8
  1039. CALL hpconv
  1040. MOV hpesize,AX ;save size of
  1041. MOV hpesize1,BX ;entry to erase
  1042. LES DI,hpstrt ;start at the beginning
  1043. MOV AX,DI
  1044. MOV BX,ES
  1045. CALL hpcmp ;= entry to erase ?
  1046. JNB dispdel ;:no free space before
  1047. dispseek ES: ;get link
  1048. MOV AX,[DI]
  1049. ES:
  1050. MOV BX,[DI]$02
  1051. CALL hpcmp ;compare with our entry
  1052. JNB dispfnd
  1053. MOV DI,AX ;go to next entry
  1054. MOV ES,BX
  1055. JMP dispseek ;'continue
  1056. dispfnd PUSH ES ;ES:DI last entry
  1057. MOV SI,CX ;DX:CX searched one
  1058. MOV ES,DX ;AX:BX current entry
  1059. PUSH hpesize1
  1060. PUSH hpesize
  1061. ES: ;store link in disposed entry
  1062. MOV [SI],AX
  1063. ES:
  1064. MOV [SI]$02,BX
  1065. ES: ;store length
  1066. POP [SI]$04
  1067. ES:
  1068. POP [SI]$06
  1069. POP ES ;restore ES
  1070. ES:
  1071. MOV [DI],CX ;store addr in last entry
  1072. ES:
  1073. MOV [DI]$02,DX
  1074. ES:
  1075. MOV AX,[DI]$04 ;get length of this entry
  1076. ES:
  1077. MOV BX,[DI]$06
  1078. CALL dispmerg ;try to put them together
  1079. JZ dispdone ;:end of heap
  1080. ES: ;get addr of next one
  1081. LES DI,[DI]
  1082. dispdone ES: ;get length of this entry
  1083. MOV AX,[DI]$04
  1084. ES:
  1085. MOV BX,[DI]$06
  1086. ES: ;get link of this entry
  1087. MOV CX,[DI]
  1088. ES:
  1089. MOV DX,[DI]$02
  1090. JMP.b dispmerg ;'try to put them together
  1091. dispdel MOV hpstrt,CX ;link to next entry
  1092. MOV hpstrt1,DX
  1093. MOV DI,CX ;ptr to this entry
  1094. MOV ES,DX
  1095. ES: ;store link to next one
  1096. MOV [DI],AX
  1097. ES:
  1098. MOV [DI]$02,BX
  1099. MOV CX,AX ;link for collect
  1100. MOV DX,BX
  1101. MOV AX,hpesize ;store its len
  1102. MOV BX,hpesize1
  1103. ES:
  1104. MOV [DI]$04,AX
  1105. ES:
  1106. MOV [DI]$06,BX
  1107. ;try to merge contiguous entries - thus reducing
  1108. ;fragmentation of the heap.
  1109. dispmerg MOV hpmerg,AX ;length of this entry
  1110. MOV hpmerg1,BX
  1111. ADD AX,DI ;+ its address
  1112. MOV BX,ES
  1113. ADD BX,hpmerg1
  1114. CALL hpconv ;convert
  1115. CALL hpcmp ;= next entry ?
  1116. JNZ disprt ;no:cannot put them together
  1117. MOV AX,hptop ;= heap top ?
  1118. MOV BX,hptop1
  1119. CALL hpcmp
  1120. JZ disptop ;yes:set new, lower heap top
  1121. PUSH ES ;save ES
  1122. MOV SI,CX ;addr of next entry
  1123. MOV ES,DX
  1124. ES: ;get link to next entry
  1125. MOV AX,[SI]
  1126. ES:
  1127. MOV BX,[SI]$02
  1128. ES: ;get length
  1129. MOV CX,[SI]$04
  1130. ES:
  1131. MOV DX,[SI]$06
  1132. POP ES ;restore ES
  1133. ES: ;store link
  1134. MOV [DI],AX
  1135. ES:
  1136. MOV [DI]$02,BX
  1137. MOV AX,hpmerg ;get length
  1138. MOV BX,hpmerg1
  1139. CALL hpadd ;add them
  1140. ES: ;store new length
  1141. MOV [DI]$04,AX
  1142. ES:
  1143. MOV [DI]$06,BX
  1144. XOR AX,AX
  1145. RET ;'
  1146. disptop MOV hptop,DI ;set new heap top
  1147. MOV hptop1,ES
  1148. PUSH DI ;clear 8 bytes
  1149. XOR AX,AX ;= marker for end of heap
  1150. CLD
  1151. MOV CX,#$0004
  1152. REPZ
  1153. STOS
  1154. POP DI ;restore
  1155. XOR AX,AX
  1156. disprt RET ;"
  1157. xmemavl XOR CX,CX ;MemAvail
  1158. XOR DX,DX ;clear sum
  1159. XOR SI,SI
  1160. LES DI,hpstrt ;get heap start
  1161. memav1 CALL hplen ;get length
  1162. JZ memav2 ;:end of heap
  1163. CALL hpaddcmp ;sum it up, test size
  1164. ES: ;get next entry
  1165. LES DI,[DI]
  1166. JMP memav1 ;'continue
  1167. memav2 MOV AX,SP ;last entry: free space
  1168. MOV BX,SS ;between stack and heap
  1169. SUB BX,#$10 ;leave some space
  1170. CALL hpconv ;convert
  1171. XOR AX,AX ;clear offset
  1172. SUB BX,hptop1 ;subtract heap top
  1173. JB memav3 ;:nothing left
  1174. CALL hpaddcmp ;sum it up
  1175. memav3 MOV AX,DX ;space left (paragraphs)
  1176. RET ;"
  1177. hpaddcmp CMP SI,BX ;is it the largest one ?
  1178. JNB hpac2 ;:no
  1179. MOV SI,BX ;yes, remember its size
  1180. hpac2 CALL hpadd ;sum it up
  1181. MOV CX,AX ;remember sum
  1182. MOV DX,BX
  1183. RET ;"
  1184. xmaxavl CALL xmemavl ;MaxAvail: do MemAvail
  1185. MOV AX,SI ;get largest size
  1186. RET ;"
  1187. xmark POP BX ;Mark
  1188. POP ES ;get ptr
  1189. MOV AX,hptop ;Heap top -> ptr
  1190. ES:
  1191. MOV [DI],AX
  1192. MOV DX,hptop1
  1193. ES:
  1194. MOV [DI]$02,DX
  1195. JMP BX ;"return
  1196. xrelease POP BX ;Release
  1197. POP ES ;ptr addr
  1198. ES: ;get pointer
  1199. LES DI,[DI]
  1200. MOV hptop,DI ;-> heap top
  1201. MOV hpstrt,DI ;-> heap start
  1202. MOV hptop1,ES
  1203. MOV hpstrt1,ES
  1204. XOR AX,AX ;clear 8 bytes in entry
  1205. LES DI,hpstrt ;= marker for end of heap
  1206. MOV CX,#$0004
  1207. CLD
  1208. REPZ
  1209. STOS
  1210. JMP BX ;"return
  1211. kbdstat CMP.B lastkey,#$00 ;Get key stat
  1212. MOV AL,#$FF ;something there ?
  1213. JNZ kbdst2 ;:true
  1214. MOV AH,#$01 ;test kbd stat
  1215. INT bioskbd
  1216. MOV AL,#$00 ;false
  1217. JZ kbdst2 ;:nothing available
  1218. DEC.B AL ;true
  1219. kbdst2 AND AX,#$0001
  1220. RET $0001 ;"
  1221. kbdget MOV AL,lastkey ;Get KBD char
  1222. MOV.B lastkey,#$00 ;clear last key code
  1223. OR.B AL,AL
  1224. JNZ kbdg3 ;:was full - take it
  1225. XOR.B AH,AH ;get key
  1226. INT bioskbd
  1227. OR.B AL,AL ;test it
  1228. JNZ kbdg2 ;:normal char
  1229. MOV.B lastkey,AH ;store scan code
  1230. MOV AL,#$1B ;return ESC
  1231. OR.B AH,AH
  1232. JNZ kbdg3
  1233. MOV AL,#$03 ;Break !
  1234. kbdg2 CMP.B cbreak,#$01 ;Break allowed ?
  1235. JNZ kbdg3 ;:no
  1236. CMP AL,#$03 ;Break ?
  1237. JNZ kbdg3 ;:no
  1238. JMP brkmsg ;'
  1239. kbdg3 XOR.B AH,AH ;clear hi byte
  1240. RET $0001 ;"
  1241. crtput POP AX ;Print char to screen
  1242. POP DX ;char to be printed
  1243. PUSH AX ;restore ret
  1244. PUSH DX ;save regs
  1245. PUSH BP
  1246. PUSH DX
  1247. CALL getcpos ;get cursor pos
  1248. POP AX ;char to be printed
  1249. CMP AL,#$0D ;Carriage Return ?
  1250. JNZ crtlf ;:no
  1251. MOV.B DL,txwinx1 ;go to left margin
  1252. JMP.b crtsetps ;'set new pos
  1253. crtlf CMP AL,#$0A ;Line Feed ?
  1254. JNZ crtbs ;:no
  1255. INC.B DH ;add 1 to line
  1256. CS:
  1257. CMP.B DH,txwiny2 ;>= bottom ?
  1258. JB crtsetps ;:no, set pos
  1259. JMP.b crtscrol ;'scroll up
  1260. crtbs CMP AL,#$08 ;Backspace ?
  1261. JNZ crtbell ;:no
  1262. CMP.B DL,txwinx1 ;at the left ?
  1263. JZ crtsetps ;yes, no change
  1264. DEC.B DL ;go back
  1265. JMP.b crtsetps ;'set cursor pos
  1266. crtbell CMP AL,#$07 ;Bell ?
  1267. JNZ crtchar ;:no
  1268. MOV AH,#$0E ;write char
  1269. XOR.B BH,BH
  1270. INT bioscrt
  1271. JMP.b crttest ;'no pos change
  1272. crtchar PUSH DX ;remember position - put char
  1273. MOV AH,#$09 ;write char
  1274. XOR.B BH,BH ;screen page 0
  1275. MOV CX,#$0001 ;1 char
  1276. MOV.B BL,attcur ;current attribute
  1277. INT bioscrt ;do it
  1278. POP DX ;restore pos
  1279. INC.B DL ;go right one char
  1280. CS:
  1281. CMP.B DL,txwinx2 ;= right margin ?
  1282. JB crtsetps ;:no, set new pos
  1283. MOV.B DL,txwinx1 ;go to the left
  1284. INC.B DH ;next line
  1285. CS:
  1286. CMP.B DH,txwiny2 ;= bottom ?
  1287. JB crtsetps ;no: set pos
  1288. crtscrol DEC.B DH ;scroll up
  1289. PUSH DX ;save pos
  1290. MOV AX,#$0601 ;scroll up one line
  1291. MOV.B BH,attcur ;att for empty line
  1292. MOV CX,txwinx1 ;position upper left
  1293. CS:
  1294. MOV DX,txwinx2 ;position lower right
  1295. DEC.B DH
  1296. DEC.B DL
  1297. INT bioscrt ;do it
  1298. POP DX
  1299. crtsetps MOV AH,#$02 ;set cursor pos
  1300. XOR.B BH,BH ;screen 0
  1301. INT bioscrt ;do it
  1302. crttest POP BP
  1303. CMP.B cbreak,#$01 ;test for break ?
  1304. JNZ crtnobrk ;:no
  1305. DEC SP
  1306. CALL kbdstat ;get key stat
  1307. JZ crtnobrk ;:nothing
  1308. DEC SP
  1309. CALL kbdget ;get key
  1310. CMP AL,#$13 ;^S ?
  1311. JNZ crtnobrk ;:no
  1312. DEC SP
  1313. CALL kbdget ;get key
  1314. crtnobrk POP AX ;restore char
  1315. RET ;"
  1316. lstput POP AX ;put to LST
  1317. POP DX ;get char
  1318. PUSH AX ;restore ret
  1319. MOV AH,#$05 ;operation
  1320. JMP.b dos ;'do MS-DOS
  1321. NOP ;Courtesy of LINK
  1322. auxput POP AX ;put to AUX
  1323. POP DX ;get char
  1324. PUSH AX ;restore ret
  1325. MOV AH,#$04 ;operation
  1326. JMP.b dos ;'do MS-DOS
  1327. NOP
  1328. auxget MOV AH,#$03 ;Get from AUX
  1329. CALL dos ;do MS-DOS
  1330. XOR.B AH,AH ;clear hi byte
  1331. RET $0001 ;'
  1332. dos CMP.B AH,#$3D ;do MS-DOS-operation
  1333. JZ openfil ;:Open file
  1334. CMP.B AH,#$3C
  1335. JZ openfil ;:Create file
  1336. CMP.B AH,#$3E
  1337. JZ closfil ;:Close file
  1338. CMP.B AH,#$80
  1339. JZ closeall ;:Close all files
  1340. dodos PUSH BP ;save this
  1341. INT msdos
  1342. POP BP ;restore it
  1343. RET ;'
  1344. openfil PUSH SI ;put file into table of
  1345. PUSH CX ;open files, open/create it
  1346. MOV SI,filtabpt ;start of file table
  1347. MOV CX,filemax
  1348. openlp CMP [SI],#$00 ;empty ?
  1349. JZ opendoit ;:yes
  1350. INC SI
  1351. INC SI
  1352. LOOP openlp ;another one
  1353. POP CX ;restore regs
  1354. POP SI
  1355. MOV AX,#$0004 ;Error: file not open
  1356. STC
  1357. RET ;'
  1358. opendoit POP CX ;get offset to filename
  1359. PUSH DS ;save DS
  1360. PUSH ES ;ES -> DS
  1361. POP DS
  1362. CALL dodos ;open file
  1363. POP DS ;restore DS
  1364. JB openerr ;:error
  1365. MOV [SI],AX ;file handle -> file list
  1366. openerr POP SI ;restore
  1367. RET ;"
  1368. closfil PUSH CX ;Close file
  1369. PUSH SI
  1370. MOV SI,filtabpt ;start of file table
  1371. MOV CX,filemax
  1372. closlp CMP [SI],BX ;is it this file ?
  1373. JNZ clsother ;:no
  1374. MOV [SI],#$0000 ;clear its entry
  1375. clsother INC SI ;next one
  1376. INC SI
  1377. LOOP closlp ;:not yet done
  1378. POP SI ;restore regs
  1379. POP CX
  1380. JMP dodos ;'do it
  1381. closeall MOV SI,filtabpt ;Close all files
  1382. MOV CX,filemax
  1383. clall1 MOV BX,[SI] ;test all file handles
  1384. OR BX,BX
  1385. JZ clall2 ;:not open
  1386. MOV AH,#$3E ;close file
  1387. CALL dodos ;do it
  1388. MOV [SI],#$0000 ;store a 0: closed
  1389. clall2 INC SI ;next one
  1390. INC SI
  1391. LOOP clall1 ;:continue
  1392. RET ;"
  1393. initio XOR AX,AX ;Init files, I/O
  1394. initiofl MOV modeflg,AX ;clear flag
  1395. MOV DI,#filetab ;set pt to file tab
  1396. MOV filtabpt,DI
  1397. MOV filemax,CX ;CX=max number of open files
  1398. XOR AX,AX ;clear file list
  1399. PUSH DS ;DS -> ES
  1400. POP ES
  1401. CLD
  1402. REPZ
  1403. STOS
  1404. MOV ES,AX ;segment 0:
  1405. ES:
  1406. MOV verrhnd,#errhndl ;set vector:
  1407. ES: ;error handler
  1408. MOV verrhnd1,CS
  1409. CALL msspeed ;measure CPU speed
  1410. reinit1 MOV.B cbreak,#$00 ;no test for break
  1411. reinit2 MOV SI,#inittab ;transfer vectors into table
  1412. MOV DI,#vkbdstat
  1413. PUSH DS ;DS -> ES
  1414. POP ES
  1415. PUSH CS ;CS -> DS
  1416. POP DS
  1417. MOV CX,#$001E ;count
  1418. CLD
  1419. REPZ ;move it
  1420. MOVS
  1421. PUSH ES ;restore DS
  1422. POP DS
  1423. XOR AX,AX ;clear vars
  1424. MOV lastkey,AX ;no key stored
  1425. MOV errnum,AL ;no error
  1426. MOV conbufpt,AX ;no con buf
  1427. MOV conbfend,AX
  1428. MOV.B conbufln,#$7E
  1429. MOV.B coninbuf,#$0D ;mark end of buffer
  1430. RET ;"
  1431. inittab W kbdstat,kbdget,crtput,lstput,auxput,auxget,crtput,kbdget
  1432. W $FFFF,$00C1,$FFFF,$0082,$FFFF,$0043,$FFFF,$00C4,$FFFF
  1433. W $00C5,$FFFF,$00C1,$0000,$0000,$0000,$0000,$FFFF,$00C1
  1434. W $0000,$0000,$0000,$0000 ;"
  1435. errhndl IRET ;"Error handler
  1436. conput PUSH BX ;put to CON
  1437. PUSH CX ;save registers
  1438. PUSH DX
  1439. PUSH DI
  1440. PUSH SI
  1441. XOR.B AH,AH
  1442. PUSH AX ;char to put
  1443. CALL [vconput] ;put it
  1444. conret POP SI ;restore regs
  1445. POP DI
  1446. POP DX
  1447. POP CX
  1448. POP BX
  1449. RET ;"
  1450. keyget PUSH BX ;Get from KBD
  1451. PUSH CX ;save regs
  1452. PUSH DX
  1453. PUSH DI
  1454. PUSH SI
  1455. DEC SP
  1456. CALL [vkbdget] ;do it
  1457. JMP conret ;"restore
  1458. prints PUSH BP ;Print inline string
  1459. MOV BP,SP
  1460. XCHG BX,[BP]$02 ;return addr -> BX
  1461. prsl CS:
  1462. MOV.B AL,[BX] ;get char
  1463. INC BX ;go to next one
  1464. OR.B AL,AL ;test it
  1465. JZ prsend ;0:end
  1466. CALL conput ;put to CRT
  1467. JMP prsl ;'continue
  1468. prsend XCHG BX,[BP]$02 ;restore ret to pos after text
  1469. POP BP
  1470. RET ;"
  1471. xwriteln CALL prints ;Writeln CRT
  1472. B $0D,$0A,$00 ;print string: CR,LF
  1473. RET ;"
  1474. upcase CMP AL,#$61 ;UpCase. < a ?
  1475. JB upcas1 ;:not lower case
  1476. CMP AL,#$7A ;> z ?
  1477. JA upcas1 ;yes:not lower case
  1478. SUB AL,#$20 ;change to upper
  1479. upcas1 RET ;"
  1480. whexword PUSH AX ;Write Hex number: save it
  1481. MOV.B AL,AH ;do hi byte
  1482. CALL whexbyte ;do it
  1483. POP AX ;restore lo byte
  1484. whexbyte PUSH AX ;write hex byte: save low nibble
  1485. ROR.B AL,1 ;get hi nibble
  1486. ROR.B AL,1
  1487. ROR.B AL,1
  1488. ROR.B AL,1
  1489. CALL whexnib ;do digit
  1490. POP AX ;get lo nibble
  1491. whexnib AND AL,#$0F ;mask it
  1492. ADD AL,#$90 ;convert to hex - tricky
  1493. DAA
  1494. ADC AL,#$40
  1495. DAA
  1496. JMP conput ;"now print it
  1497. limstind OR.B AH,AH ;limit string index
  1498. JZ limst1 ;:ok
  1499. STC ;hi <> 0: error
  1500. MOV AX,#$0000 ;clear it
  1501. JS limst1 ;negative:0
  1502. DEC.B AL ;+:255
  1503. limst1 RET ;"
  1504. ;Init Memory - with inline parms:
  1505. ;+ 0:mode flag
  1506. ; 1=direct mode; 2=no device checking;
  1507. ; 4=test for break; 8=set breakpoint interrupt
  1508. ;+ 2:CS for returning to Turbo
  1509. ;+ 4:DS for returning to Turbo
  1510. ;+ 6:CS size
  1511. ;+ 8:DS size
  1512. ;+ A:heap, stack size
  1513. ;+ C:max. heap, stack size
  1514. ;+ E:max. number of open files
  1515. ;+10:size of std input buffer
  1516. ;+12:size of std output buffer
  1517. initmem CALL readvers ;Init memory - with inline parms
  1518. POP SI ;ret addr
  1519. MOV AX,CS ;calculate segments
  1520. CS:
  1521. ADD AX,[SI]$06 ;+CS size
  1522. CS:
  1523. ADD AX,[SI]$08 ;+DS size
  1524. CS:
  1525. ADD AX,[SI]$0A ;+heap, stack size
  1526. CS:
  1527. CMP AX,availmem ;> available memory ?
  1528. JBE memin1 ;:no
  1529. JMP memerr ;'Not enough memory
  1530. memin1 MOV BX,CS ;CS + CS size -> DS
  1531. CS:
  1532. ADD BX,[SI]$06
  1533. MOV DS,BX
  1534. CS: ;DS + DS size -> beg of free mem
  1535. ADD BX,[SI]$08
  1536. CS:
  1537. MOV DX,availmem
  1538. SUB DX,BX ;how much is left ?
  1539. CS:
  1540. CMP DX,[SI]$0C ;> max size ?
  1541. JB memin2 ;:no
  1542. CS:
  1543. MOV DX,[SI]$0C ;limit to max size
  1544. memin2 MOV DI,DX ;DI: heap size
  1545. MOV AX,#$FFFE ;value for full stack
  1546. SUB DX,#$1000 ;64 K free ?
  1547. JNB memin3 ;:yes
  1548. MOV AX,DX ;calculate stack size -> AX
  1549. ADD AX,#$1000
  1550. MOV CL,#$04
  1551. SHL AX,CL
  1552. XOR DX,DX ;at beg of heap segment
  1553. memin3 ADD DX,BX ;+ heap segment
  1554. MOV SS,DX ;-> SS
  1555. MOV SP,AX ;set SP
  1556. MOV spval,AX ;remember SP
  1557. XOR AX,AX ;clear heap:
  1558. MOV hptop,AX ;ptrs to beg of free memory
  1559. MOV hptop1,BX
  1560. MOV hpstrt,AX
  1561. MOV hpstrt1,BX
  1562. PUSH DI ;save heap size
  1563. LES DI,hpstrt ;init heap:
  1564. MOV CX,#$0004 ;mark heap top
  1565. CLD
  1566. REPZ
  1567. STOS
  1568. POP DI ;restore heap size
  1569. CS: ;return excess memory ?
  1570. TEST [SI],#$0001
  1571. JNZ memin4 ;direct mode:no
  1572. MOV AX,CS ;CS -> ES
  1573. MOV ES,AX
  1574. ADD BX,DI ;Heap pos + Heap size
  1575. SUB BX,AX ;-> top of used memory
  1576. MOV AH,#$4A ;change memory blocks
  1577. CALL dos ;do MS-DOS
  1578. memin4 CS: ;set variables
  1579. MOV AX,[SI]$02 ;CS for return
  1580. MOV turbocs,AX
  1581. CS:
  1582. MOV AX,[SI]$04 ;DS for return
  1583. MOV turbods,AX
  1584. CS:
  1585. MOV AX,[SI] ;main flag
  1586. CS:
  1587. MOV CX,[SI]$0E ;max file count
  1588. PUSH CX
  1589. PUSH SI
  1590. CALL initiofl ;init files, I/O
  1591. POP SI
  1592. POP CX
  1593. MOV DI,#filetab ;get end addr
  1594. ADD DI,CX ;of file tab
  1595. ADD DI,CX
  1596. MOV stdinof,DI ;buffer addr std input
  1597. CS:
  1598. MOV AX,[SI]$10 ;set std in buffer
  1599. MOV stdinsz,AX
  1600. ADD DI,AX