Subversion Repositories NedoOS

Rev

Rev 632 | Rev 728 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1.         DEVICE ZXSPECTRUM128
  2.         include "../_sdk/sys_h.asm"
  3.  
  4.         ;title  TURBO PASCAL Compiler for CP/M 80
  5.         ;name   ('TURBO')
  6.  
  7. ; DASMed version of TURBO.COM, v3.0
  8. ; By W. Cirsovius
  9.  
  10. ;;      +++l6f66        l446c   l7124   l2da4   l3135   l2df8
  11.  
  12. ; l731f -> $STR$ in Teil 6
  13.  
  14. ;;; RTL         l0af5
  15. ;;; MENUE       -----
  16. ;;; EDITOR      l42a1           l3918   l2fc1   l324b   l32f5 (SEARCH)
  17. ;;; COMPILER    l5039
  18.  
  19.         ;.z80
  20.         ;aseg
  21.         ;org    0100h
  22.         org PROGSTART
  23. begin
  24.  
  25. FALSE   equ     0
  26. _TRUE   equ     1
  27.  
  28. OS      equ     0000h
  29. DU      equ     0004h ;TODO change to GETPATH and subdirs
  30. BDOS    equ     0005h
  31. ;TPAtop equ     BDOS+1
  32. NEDOOSMEMTOP=0xff00;0xdc06 ;TODO 0x0000?
  33. Number  equ     005dh
  34.  
  35. ;TPA    equ     0100h
  36.  
  37. ;CP/M function codes:
  38. ;_resdsk        equ     13 ;TODO
  39. ;_seldsk        equ     14 ;
  40. _open   equ     15 ;
  41. _close  equ     16 ;
  42. _srcfrs equ     17 ;
  43. _srcnxt equ     18 ;
  44. _delete equ     19 ;
  45. _rdseq  equ     20 ;
  46. _wrseq  equ     21 ;
  47. _make   equ     22 ;
  48. _rename equ     23 ;TODO
  49. _retdsk equ     25 ;TODO (return A=current drive)
  50. _setdma equ     26 ;
  51. _getalv equ     27 ;TODO
  52. _getdpb equ     31 ;TODO
  53. _rndrd  equ     33 ;
  54. _rndwr  equ     34 ;
  55. _filsiz equ     35 ;TODO (lib?)
  56.  
  57. RecLng          equ     128     ; Standard record length
  58. Dirlng          equ     15
  59.  
  60. MaxParams       equ     31
  61.  
  62. a_const         equ      2
  63. a_conin         equ      3
  64. a_conout        equ      4
  65. a_list          equ      5
  66. a_auxout        equ      6
  67. a_auxin         equ      7
  68.  
  69. _.const         equ     (a_const-1)*3
  70. _.conin         equ     (a_conin-1)*3
  71. _.conout        equ     (a_conout-1)*3
  72. _.list          equ     (a_list-1)*3
  73. _.auxout        equ     (a_auxout-1)*3
  74. _.auxin         equ     (a_auxin-1)*3
  75.  
  76. Fdrv            equ      1
  77. Fname           equ      8
  78. Fext            equ      3
  79. _SYS            equ     10
  80. _ex             equ     12
  81. DIRlen          equ     16
  82. _rrn            equ     33 ;shift to random record number in FCB
  83. FCBlen          equ     36
  84.  
  85. FIB.rec         equ     4               ; Pointer #records
  86. FIB.reclen      equ     6               ; Pointer record length
  87. FIB.cur         equ     8               ; Pointer to current record
  88. FIB.FCB         equ     12              ; Pointer to FCB
  89. FIBlen          equ     FIB.FCB+FCBlen  ; FIB length less buffer
  90. FIB.buff        equ     FIBlen          ; Pointer to buffer
  91.  
  92. FIBtype         equ     00001111b
  93.  
  94. rd.bit          equ     4
  95. wr.bit          equ     5
  96. out.bit         equ     6
  97. in.bit          equ     7
  98.  
  99. _.in            equ     10000000b
  100. _.out           equ     01000000b
  101. _.read          equ     00010000b
  102.  
  103. FixRecLen       equ     4       ; Fixed record length
  104. Rec.Wr.bit      equ     0
  105. Rec.New.bit     equ     1
  106. Rec.Wr          equ     01b
  107. Rec.New         equ     10b
  108.  
  109. RAMdevice       equ     6
  110.  
  111. HeapLen         equ     4       ; Heap administration
  112. HeapLOadr       equ     0       ; Address location
  113. HeapHIadr       equ     1
  114. HeapLOlen       equ     2       ; Length location
  115. HeapHIlen       equ     3
  116.  
  117. null    equ     00h
  118. bs      equ     08h
  119. tab     equ     09h
  120. lf      equ     0ah
  121. cr      equ     0dh
  122. eof     equ     1ah
  123. esc     equ     1bh
  124. CtrlC   equ     'C'-'@'
  125. Xoff    equ     'S'-'@'
  126. a_CAN   equ     'U'-'@'
  127. CtrlX   equ     'X'-'@'
  128. ;DEL    equ     7fh
  129.  
  130. LoMask  equ     00001111b
  131. DPBMASK equ     00011111b
  132. NOMSB   equ     01111111b
  133. MSB     equ     10000000b
  134. LSB     equ     00000001b
  135. MMSB    equ     1000000000000000b
  136.  
  137. MINWID  equ     56                      ; Min width for filename
  138.  
  139. MAXINT  equ     32767
  140. DefSTR  equ     8
  141.  
  142. _LB     equ     0
  143. _MB     equ     7
  144.  
  145. sgn.bit         equ     7
  146. sign.bit        equ     10000000b
  147.  
  148. mant.len        equ     5               ; Byte length  of mantissa
  149. Real.Len        equ     6               ; Length of real
  150. bit.len         equ     8               ; Bits in a byte
  151. exp.offset      equ     080h            ; Offset in exponent
  152. Exp.One         equ     exp.offset+1    ; Exponent for >=1.0
  153. int.max         equ     exp.offset+15   ; Max exponent for an integer
  154. mant.bits       equ     mant.len*bit.len
  155. real.dig        equ     24              ; Length of mantissa
  156. real.field      equ     7               ; Real field size
  157. real.ASCII      equ     12              ; Decimal places
  158. ExpFix          equ     77              ; Exponent fix for real to ASCII
  159. ExpRange        equ     0d9h            ; Exponent range
  160. sqr.exp         equ     014h            ; SQRT exponent fix
  161. sin.min         equ     06ch            ; SIN/COS minimum exponent
  162. ln.min          equ     067h            ; LN  minimum exponent
  163. exp.max         equ     088h            ; EXP maximum exponent
  164.  
  165. dot.bit         equ     6               ; Status of dot in real
  166. exps.bit        equ     5               ; Sign of exponent
  167. exp.bit         equ     4               ; Exponent
  168.  
  169. l00fe   equ     254             ; Mystery editor size
  170.  
  171. MEMGAP  equ      708            ; Memory gap at top of memory
  172. StkSpc  equ     1024            ; Stack space
  173. _SavLen equ     8192
  174.  
  175. _RST    equ     7               ; ** CAUTION **
  176. RSTADDR equ     _RST*8 ;SHL 3   ; RST address     (0x0038H)
  177. RST     equ     11000111b + RSTADDR; RST instruction (0xFFH)
  178.  
  179. a_OVLADR        equ     9000h           ; Overlay load address
  180.  
  181. _LD.A           equ     03eh    ; LD A,xx
  182. _LD.BC          equ     001h    ; LD BC,xxxx
  183. _LD.DE          equ     011h    ; LD DE,xxxx
  184. _LD.HL          equ     021h    ; LD HL,xxxx
  185. _LD.SP          equ     031h    ; LD SP,xxxx
  186. _LD_a_DE                equ     5bedh   ; LD DE,(xxxx)
  187. _LD_a_HL                equ     02ah    ; LD HL,(xxxx)
  188. _LDHL_a         equ     022h    ; LD (xxxx),HL
  189. _LDA_a          equ     032h    ; LD (xxxx),A
  190. _JP             equ     0c3h    ; JP xxxx
  191. _CALL           equ     0cdh    ; CALL addr
  192. _JPZ            equ     0cah    ; JP Z,xxxx
  193. _EXX            equ     0d9h    ; EXX
  194. _POP.HL         equ     0e1h    ; POP HL
  195. _PUSH.HL        equ     0e5h    ; PUSH HL
  196. _INC.HL         equ     023h    ; PUSH HL
  197. _DEC.HL         equ     02bh    ; PUSH HL
  198. ;
  199. skip            equ     03eh    ; LD A,xx
  200. skip.2          equ     001h    ; LD BC,xx
  201. skip.3          equ     011h    ; LD DE,xx
  202.  
  203. _LinLen         equ     127
  204.  
  205. _MaxBuf         equ     126     ; Max line input
  206. _MaxSamp        equ      30     ; Max sample input
  207.  
  208. _Ahead          equ     20      ; Size of ahead buffer
  209.  
  210. set.len         equ     32
  211.  
  212. DefWITH         equ     2
  213.  
  214. _Byte           equ     1
  215. _Addr           equ     2
  216.  
  217. _Array          equ      1
  218. _Record         equ      2
  219. _Set            equ      3
  220. _Ptr            equ      4
  221. _RecF           equ      5
  222. _TxtF           equ      6
  223. _UntF           equ      7
  224. _String         equ      8
  225. _Real           equ      9
  226. _Integ          equ     10
  227. _Bool           equ     11
  228. _Char           equ     12
  229. ;13=element of a set?
  230.  
  231. _Label          equ     1
  232. _Const          equ     2
  233. _Type           equ     3
  234. _Var            equ     4
  235. _Proc           equ     5
  236. _Overly         equ     7
  237. _Begin          equ     8
  238. ;
  239. ; Option selection bits
  240. ;
  241. __Ropt          equ     00000010b
  242. __Uopt          equ     00001000b
  243. ;
  244. _Iopt           equ     0
  245. _Ropt           equ     1
  246. _Aopt           equ     2
  247. _Uopt           equ     3
  248. _Xopt           equ     4
  249. _Vopt           equ     5
  250. _Bopt           equ     6
  251. _Copt           equ     7
  252. ;
  253. ; Search option list
  254. ;
  255. _W              equ     0
  256. _N              equ     1
  257. _U              equ     2
  258. _G              equ     3
  259. _B              equ     4
  260. ;
  261. ; Error levels
  262. ;
  263. _BRK            equ     0       ; User break
  264. _IO             equ     1       ; I/O error
  265. _RT             equ     2       ; Run time error
  266. ;
  267. ; BREAK error
  268. ;
  269. _CBRK           equ     1
  270. ;
  271. ; Compiler errors
  272. ;
  273. _ColExp         equ       1
  274. _SemiExp        equ       2
  275. _CommaExp       equ       3
  276. _LftPar         equ       4
  277. _RgtPar         equ       5
  278. _EquExp         equ       6
  279. _AssigExp       equ       7
  280. _LftBrExp       equ       8
  281. _RgtBrExp       equ       9
  282. _DotExp         equ      10
  283. _TwoDots        equ      11
  284. _BEGINexp       equ      12
  285. _NoDO           equ      13
  286. _End            equ      14
  287. _NoOF           equ      15
  288. _SUBexp         equ      16
  289. _StrIdx         equ      17
  290. _NoDOWN_TO      equ      18
  291. _BoolExp        equ      20
  292. _FileVarExp     equ      21
  293. _IntConst       equ      22
  294. _IntExpr        equ      23
  295. _IntVarExp      equ      24
  296. _IntRealCexp    equ      25
  297. _NumExprExp     equ      26
  298. _NumVarExp      equ      27
  299. _PtrVarExp      equ      28
  300. _RecVarExp      equ      29
  301. _SimTyp         equ      30
  302. _SimpExpr       equ      31
  303. _StrgConExp     equ      32
  304. _StrgExpExp     equ      33
  305. _StrgVarExp     equ      34
  306. _MustTextFile   equ      35
  307. _TypeExp        equ      36
  308. _UntFileExp     equ      37
  309. _UnkLabel       equ      40
  310. _Undef          equ      41
  311. _InkPointer     equ      42
  312. _DoubleLab      equ      43
  313. _InvType        equ      44
  314. _ConstRange     equ      45
  315. _IllCASE        equ      46
  316. _IllOps         equ      47
  317. _InvResult      equ      48
  318. _IllStrgLen     equ      49
  319. _StrConst       equ      50
  320. _IllSkalar      equ      51
  321. _IllLimit       equ      52
  322. _ResWord        equ      53
  323. _IllAss         equ      54
  324. _StrConLong     equ      55
  325. _IntegErr       equ      56
  326. _RealErr        equ      57
  327. _IllChar        equ      58
  328. _IllConst       equ      60
  329. _InvFilPtr      equ      61
  330. _NoStruktVar    equ      62
  331. _IllTxtFile     equ      63
  332. _IllFileType    equ      64
  333. _NoUntypeFile   equ      65
  334. _InvIO          equ      66
  335. _VarFile        equ      67
  336. _FileF          equ      68
  337. _InvSetOrder    equ      69
  338. _IllSetRange    equ      70
  339. _IllGOTO        equ      71
  340. _IllLabel       equ      72
  341. _UndefFORW      equ      73
  342. _IllINLINE      equ      74
  343. _InvalABS       equ      75
  344. _OvlFORW        equ      76
  345. _OvlDirErr      equ      77
  346. _NoFileErr      equ      90
  347. _IllSrcEnd      equ      91
  348. _NoOvl          equ      92
  349. _CompDirec      equ      93
  350. _INCLerr        equ      96
  351. _TooManyWITH    equ      97
  352. _MemOvfl        equ      98
  353. _CompOvfl       equ      99
  354. _IndxErr        equ     144
  355. _RngErr         equ     145
  356. _ABORT          equ     202
  357. _FndRTerr       equ     200
  358. _DskFull        equ     250
  359. ;
  360. ; Run-Time errors
  361. ;
  362. _FLPovfl        equ       1     ; 0x01
  363. _DivZero        equ       2     ; 0x02
  364. _NegSqrt        equ       3     ; 0x03
  365. _LNerr          equ       4     ; 0x04
  366. _StrLenErr      equ      16     ; 0x10
  367. _TruncOvl       equ     146     ; 0x92
  368. _OVLerr         equ     240     ; 0xf0
  369. _HeapErr        equ     255     ; 0xff
  370. ;
  371. ; Run-Time I/O errors
  372. ;
  373. _NoFile         equ       1     ; 0x01
  374. _NoRead         equ       2     ; 0x02
  375. _NoWrite        equ       3     ; 0x03
  376. _BlkErr         equ       4     ; 0x04
  377. _IllNum         equ      16     ; 0x10
  378. _IllIO          equ      32     ; 0x20
  379. _DirErr         equ      33     ; 0x21
  380. _StdAssErr      equ      34     ; 0x22
  381. _InvRec         equ     144     ; 0x90
  382. _SeekEOF        equ     145     ; 0x91
  383. _IllEOF         equ     153     ; 0x99
  384. _WrErr          equ     240     ; 0xF0
  385. _DirFull        equ     241     ; 0xF1
  386. _OvflErr        equ     242     ; 0xF2
  387. _NoClose        equ     255     ; 0xFF
  388.  
  389. TPhead          equ     21      ; Header code length for ERROR
  390.  
  391. _Video          equ     7       ; Status
  392.  
  393. a_DUMMY equ     04d2h
  394.  
  395. ;l0300  equ     0300h
  396. ;l0800  equ     0800h
  397. l07d0   equ     07d0h
  398.  
  399. l00a0   equ     00a0h           ; Keypressed
  400. l00a3   equ     00a3h           ; Read KBD
  401. l00a6   equ     00a6h           ; Console output
  402. l00a9   equ     00a9h           ; List output
  403. l00ac   equ     00ach           ; Auxiliary output
  404. l00af   equ     00afh           ; Auxiliary input
  405. l00b2   equ     00b2h           ; Console output
  406. l00b5   equ     00b5h           ; Read USR
  407.  
  408. l00b8   equ     00b8h           ; Base FIB
  409. l00ba   equ     00bah           ; ConinFIB
  410. l00bc   equ     00bch           ; LstFIB
  411. l00be   equ     00beh           ; AuxFIB
  412. l00c0   equ     00c0h           ; UsrFIB
  413. l00c2   equ     00c2h           ; StdIOdev
  414. l00c4   equ     00c4h           ; Heap pointer
  415. l00c6   equ     00c6h           ; Recursion pointer
  416. l00c8   equ     00c8h           ; Four byte random value
  417. l00cc   equ     00cch           ; Base PC
  418. l00ce   equ     00ceh           ; Current PC
  419. l00d0   equ     00d0h           ; I/O result
  420. l00d1   equ     00d1h           ; Buffer length
  421. l00d2   equ     00d2h           ; RTL top of memory
  422. l00d4   equ     00d4h           ; Current pointer
  423. l00d6   equ     00d6h           ; Top pointer
  424. l00d8   equ     00d8h           ; Run mode
  425. l00d9   equ     00d9h           ; + JP xxxx
  426. l00da   equ     00dah           ; + Restart vector
  427. l00dc   equ     00dch           ; Overlay drive
  428. l00dd   equ     00ddh           ; $C mode
  429. l00e0   equ     00e0h           ; Video mode
  430. l00e8   equ     00e8h           ; Pointer ????
  431. l00f4   equ     00f4h           ; Available memory
  432.  
  433. l0000   equ     00h
  434. l0001   equ     01h
  435. l0002   equ     02h
  436. l0005   equ     05h
  437. l0008   equ     08h
  438. l000c   equ     0ch
  439. l000d   equ     0dh ;for save environment
  440. l0015   equ     15h
  441. ;l0019  equ     19h
  442. l0024   equ     24h
  443. l0030   equ     30h
  444. l005c   equ     5ch
  445. l0080   equ     80h
  446. l0081   equ     81h
  447.  
  448. l00b0   equ     00b0h
  449. l00de   equ     0deh
  450. l00e2   equ     0e2h
  451. l00e4   equ     0e4h
  452. l00e6   equ     0e6h
  453. l00e9   equ     0e9h
  454. l00ea   equ     0eah
  455. l00ec   equ     0ech
  456. l00ed   equ     0edh
  457. l00f0   equ     0f0h
  458. l00f2   equ     0f2h
  459. l00f6   equ     0f6h
  460. l00f8   equ     0f8h
  461.  
  462. lfff3   equ     0fff3h
  463. lfffc   equ     0fffch
  464. lffff   equ     0ffffh
  465.  
  466. l0100:
  467.         OS_HIDEFROMPARENT
  468.         ld e,6 ;textmode
  469.         OS_SETGFX
  470. progstartaddr=$+1
  471.         jp      l20e2           ; Jump over Run Time Library
  472. ;
  473. ; %%%%%%%%%%%%%%%%%%%%%%%%%
  474. ; %%% RUN TIME ROUTINES %%%
  475. ; %%%%%%%%%%%%%%%%%%%%%%%%%
  476. ;
  477.         db      0cdh,0abh
  478.         db      'Copyright (C) 1985 BORLAND Inc',null
  479. l0124:
  480.         db      4               ; CPU speed
  481.         db      0,0a1h,'B'
  482. ;
  483. ; &&&&&&&&&&&&&&&&&&
  484. ; &&& PATCH AREA &&&
  485. ; &&&&&&&&&&&&&&&&&&
  486. ;
  487. l0128:
  488.         cp      0fch            ; Test special key
  489.         jp      z,l2e8f
  490.         cp      esc             ; Test ESCape
  491.         jp      z,l2e8f
  492.         jp      l2e88
  493. ;
  494.         ds      30
  495. ;
  496. l0153:
  497.         db      TermLen
  498.         db      'NedoOS BDOS';'Schneider Joyce'
  499. TermLen equ     $-l0153-1
  500.         db      '12864'
  501. l0168:
  502.         db      80;90           ; Screen columns
  503. l0169:
  504.         dw      25;31           ; Screen lines
  505. ;
  506. ; Lead in sequence: Leave 24x80 mode
  507. ;
  508. l016b:
  509.         db 0;db 2,esc,'y'
  510. ;
  511.         db      1bh,'Y  ',1,1,1dh
  512.         db      3,3,1bh,1bh,1bh,0d5h
  513. ;
  514. ; Lead out sequence: Enter 24x80 mode
  515. ;
  516. l017b:
  517.         db 0;db 2,esc,'x'
  518. ;
  519.         db      0,0,1ch,0,17h,17h
  520.         db      1dh,17h,17h,0efh,9eh,0cdh,0bdh
  521. ;
  522. ;setxy sequence
  523. ;not used in NedoOS
  524. l018b:
  525.         db      4,esc,'Y',0,0
  526.         ds      11
  527. ll018b  equ     $-l018b
  528.  
  529. l019b:
  530.         db      1               ; Binary indicator (1 is binary)
  531. l019c:
  532.         db      ' '             ; Offset for column
  533. l019d:
  534.         db      ' '             ; Offset for row
  535. l019e:
  536.         db      4               ; Position of column
  537. l019f:
  538.         db      3               ; Position of row
  539. l01a0:
  540.         dw      0
  541. ;
  542. ; Clear display
  543. ;not used in NedoOS
  544. l01a2:
  545.         db      2,esc,'E'
  546.         ds      3
  547. ;
  548. ; Home cursor
  549. ;not used in NedoOS
  550. l01a8:
  551.         db      2,esc,'H'
  552.         ds      3
  553. ;
  554. ; Insert line
  555. ;if zero in first byte, function not implemented in this terminal
  556. l01ae:
  557.         db 0;db 2,esc,'L'
  558.         ds      3
  559. ;
  560. ; Delete line
  561. ;if zero in first byte, function not implemented in this terminal
  562. l01b4:
  563.         db 0;db 2,esc,'M'
  564.         ds      3
  565. l01ba:
  566.         dw      0
  567. ;
  568. ; Clear to end of line
  569. ;if zero in first byte, function not implemented in this terminal
  570. l01bc:
  571.         db 0;db 2,esc,'K'
  572.         ds      3
  573. ;
  574. ; Turn off inverse
  575. ;
  576. l01c2:
  577.         db      2,esc,'q'
  578.         ds      3
  579. ;
  580. ; Turn on inverse
  581. ;
  582. l01c8:
  583.         db      2,esc,'p'
  584.         ds      3
  585. l01ce:
  586.         dw      0
  587. ;
  588. ; Print control string ^HL on console
  589. ; C set if control not defined
  590. ;
  591. l01d0:
  592.         ld      a,(hl)          ; Get character
  593.         or      a               ; Test defined
  594.         scf
  595.         ret     z               ; Nope as C set says
  596. l01d4:
  597.         inc     hl
  598.         push    af
  599.         push    hl
  600.         push ix ;TODO remove?
  601.         push iy
  602.         ld      a,(hl)          ; Get character
  603.         PRCHAR ;call    l01e8           ; Put to console
  604.         pop iy
  605.         pop ix ;TODO remove?
  606.         pop     hl
  607.         pop     af
  608.         dec     a
  609.         ret     z
  610.         jr      l01d4
  611. ;
  612. ; Give new line on console
  613. ;
  614. l01e1:
  615.         call    l0200
  616.         db      cr,lf,null
  617.         ret
  618. ;
  619. ; Put character on console
  620. ;
  621. l01e8:
  622.         push ix ;TODO remove?
  623.         push iy
  624.         ;ld     l,a
  625.         ;push   hl              ; Push onto stack
  626.         PRCHAR ;call    l00a6           ; Put to console
  627.         pop iy
  628.         pop ix ;TODO remove?
  629.         ret
  630.  
  631. ;
  632. ; Check character for attribute
  633. ; MSB set for normal output
  634. ;
  635. l01ee:
  636.         cp      MSB             ; Test attribute set
  637.         call    c,setlowvideo           ; Nope, set invers video
  638.         call    nc,setnormvideo ; Yeap, set normal video
  639.         and     NOMSB           ; Strip off attribute
  640.         jr      l01e8
  641. ;
  642. ; Print immediate control string on console
  643. ;
  644. l01fa:
  645.         push    hl
  646.         ld      hl,l01ee        ; Get new output routine
  647.         jr      l0204
  648. ;
  649. ; Print immediate string on console
  650. ;
  651. l0200:
  652.         push    hl
  653.         ld      hl,l01e8        ; Get new output routine
  654. l0204:
  655.         ld      (l0213),hl      ; Change output vector
  656.         pop     hl
  657.         ex      (sp),hl         ; Get pointer to string
  658.         push    af
  659.         push    bc
  660.         push    de
  661. l020c:
  662.         ld      a,(hl)          ; Get character
  663.         inc     hl
  664.         or      a               ; Test end
  665.         jr      z,l0218         ; Yeap
  666.         push    hl
  667. l0213   equ     $+1
  668.         call    a_DUMMY         ; Process output
  669.         pop     hl
  670.         jr      l020c
  671. l0218:
  672.         pop     de
  673.         pop     bc
  674.         pop     af
  675.         ex      (sp),hl
  676.         ret
  677. ;
  678. ; Delay by value in reg HL
  679. ;
  680. l021d:
  681.         ld      a,l
  682.         or      h               ; Test any value given
  683.         ret     z               ; Nope
  684.         ld      a,(l0124)       ; Get CPU speed
  685.         add     a,a
  686.         add     a,a
  687.         add     a,a             ; Build delay value
  688. l0226:
  689.         ex      (sp),hl         ;  5 cycles
  690.         ex      (sp),hl         ; 10 cycles
  691.         ex      (sp),hl         ; 15 cycles
  692.         ex      (sp),hl         ; 20 cycles
  693.         push    bc              ; 23 cycles
  694.         ld      bc,1234         ; 26 cycles
  695.         pop     bc              ; 29 cycles
  696.         dec     a               ; 30 cycles
  697.         jr      nz,l0226
  698.         dec     hl
  699.         jr      l021d
  700. ;
  701. ; Give control and delay if control defined
  702. ;
  703. l0235:
  704.         call    l01d0           ; Give control
  705.         ret     c               ; Not defined
  706.         ld      hl,(l01ce)      ; Get value
  707.         jr      l021d           ; Delay
  708. ;
  709. ; Clear screen
  710. ;
  711. l023e:
  712.         push    af
  713.         push    bc
  714.         push    de
  715.         push    hl
  716.        if 1==1
  717.         push ix ;TODO remove?
  718.         push iy ;needed!!!
  719.         ld e,0
  720.         OS_CLS
  721.         pop iy
  722.         pop ix ;TODO remove?
  723.        else
  724.         ld      hl,l01a8
  725.         call    l0235           ; Home cursor
  726.         ld      hl,l01a2
  727. l024b:
  728.         call    l01d0           ; Clear display
  729.        endif
  730.         ld      hl,(l01ba)
  731.         call    nc,l021d        ; Delay if defined
  732.         pop     hl
  733.         pop     de
  734.         pop     bc
  735.         pop     af
  736.         ret
  737. ;
  738. ; Delete line
  739. ;
  740. l0259:
  741.         if 1==1
  742.         ;jr $ ;TODO
  743.         else
  744.         push    af
  745.         push    bc
  746.         push    de
  747.         push    hl
  748.         ld      hl,l01b4
  749.         jr      l024b           ; Delete line
  750.         endif
  751. ;
  752. ; Insert line
  753. ;
  754. l0262:
  755.         if 1==1
  756.         ;jr $ ;TODO
  757.         else
  758.         push    af
  759.         push    bc
  760.         push    de
  761.         push    hl
  762.         ld      hl,l01ae
  763.         jr      l024b           ; Insert line
  764.         endif
  765. ;
  766. ; Set low video
  767. ;
  768. setlowvideo:
  769.         push    af
  770.         ld      a,(l00e0)       ; Get video mode
  771.         or      a               ; Test low mode already set
  772.         jr      z,l0282         ; Yeap, skip
  773.         if 1==1
  774.         push bc
  775.         push de
  776.         push hl
  777.         push ix
  778.         push iy
  779.         xor     a
  780.         ld      (l00e0),a       ; Set video mode       
  781.         ld e,0x07;0x38
  782. l027c:
  783.         OS_SETCOLOR
  784.         pop iy
  785.         pop ix
  786.         pop hl
  787.         pop de
  788.         pop bc
  789.         else
  790.         push    bc
  791.         push    de
  792.         push    hl
  793.         xor     a
  794.         ld      (l00e0),a       ; Set video mode       
  795.         ld      hl,l01c8        ; Set attribute
  796. l027c:
  797.         call    l0235           ; Give control
  798.         pop     hl
  799.         pop     de
  800.         pop     bc
  801.         endif
  802. l0282:
  803.         pop     af
  804.         ret
  805. ;
  806. ; Set normal video
  807. ;
  808. setnormvideo:
  809.         push    af
  810.         ld      a,(l00e0)       ; Get video mode
  811.         cp      -1              ; Test normal mode already set
  812.         jr      z,l0282         ; Yeap, skip
  813.         if 1==1
  814.         push bc
  815.         push de
  816.         push hl
  817.         push ix
  818.         push iy
  819.         ld a,-1
  820.         ld (l00e0),a    ; Set video mode       
  821.         ld e,0x47;0x07
  822.         jr l027c
  823.         else
  824.         push    bc
  825.         push    de
  826.         push    hl
  827.         ld      a,-1
  828.         ld      (l00e0),a       ; Set video mode
  829.         ld      hl,l01c2        ; Reset attribute
  830.         jr      l027c
  831.         endif
  832. ;
  833. ; Erase to end of line
  834. ;
  835. l0299:
  836.         if 1==1
  837.         push af
  838.         push bc
  839.         push de
  840.         push hl
  841. ;TODO
  842.         pop hl
  843.         pop de
  844.         pop bc
  845.         pop af
  846.         ret
  847.         else
  848.         push    af
  849.         push    bc
  850.         push    de
  851.         push    hl
  852.         ld      hl,l01bc        ; Clear to end of line
  853.         jr      l027c
  854.         endif
  855. ;
  856. ; Position cursor with X (column) in reg H and y (row) in reg L
  857. ;
  858. l02a2:
  859.         if 1==1
  860.         push af
  861.         push bc
  862.         push de
  863.         push hl
  864.         push ix
  865.         push iy
  866.         ld d,l
  867.         ld e,h
  868.         ;dec d
  869.         ;dec e
  870.         OS_SETXY
  871.         pop iy
  872.         pop ix
  873.         pop hl
  874.         pop de
  875.         pop bc
  876.         pop af
  877.         ret
  878.         else
  879.         push    af
  880.         push    bc
  881.         push    de
  882.         push    hl
  883.         push    hl
  884.         ld      de,l00f0
  885.         ld      hl,l018b
  886.         ld      bc,ll018b
  887.         ldir                    ; Unpack control string
  888.         pop     de              ; Get back coordinates
  889.         ld      a,(l019e)       ; Get position of column
  890.         ld      c,a
  891.         ld      a,(l019c)       ; Get offset for column
  892.         add     a,d             ; Build real value
  893.         push    de
  894.         call    l02dc           ; Store it
  895.         pop     de
  896.         ld      a,(l019f)       ; Get position of row
  897.         ld      c,a
  898.         ld      a,(l019d)       ; Get offset for row
  899.         add     a,e             ; Build real value
  900.         call    l02dc           ; Store it
  901.         ld      hl,l00f0
  902.         call    l01d0           ; Give control
  903.         ld      hl,(l01a0)      ; Get delay value
  904.         call    l021d           ; Delay a bit
  905.         pop     hl
  906.         pop     de
  907.         pop     bc
  908.         pop     af
  909.         ret
  910.         endif
  911. ;
  912. ; Store Accu in position in reg C
  913. ;
  914. l02dc:
  915.         ld      hl,l00f0
  916.         ld      b,0
  917.         add     hl,bc           ; Position in string
  918.         ex      de,hl
  919.         ld      hl,l019b
  920.         inc     (hl)            ; Test binary
  921.         dec     (hl)
  922.         jr      z,l02ec         ; Nope, build ASCII
  923.         ld      (de),a          ; Store value
  924.         ret
  925. l02ec:
  926.         dec     de              ; Fix for hi ASCII
  927.         dec     de
  928.         ld      hl,l0307+3      ; Point to divisor
  929.         ld      b,3             ; Set length
  930. l02f3:
  931.         dec     hl
  932.         ld      c,'0'-1         ; Init ASCII
  933. l02f6:
  934.         inc     c               ; Fix quotient
  935.         sub     (hl)            ; Divide
  936.         jr      nc,l02f6
  937.         add     a,(hl)          ; Build last value
  938.         push    af
  939.         ld      a,c
  940.         cp      '0'             ; Test zero
  941.         jr      z,l0302         ; Skip if so
  942.         ld      (de),a          ; Store ASCII
  943. l0302:
  944.         inc     de
  945.         pop     af
  946.         djnz    l02f3
  947.         ret
  948. ;
  949. l0307:
  950.         db      1,10,100
  951. ;
  952. ; Set lead in
  953. ;
  954. l030a:
  955.         ld      hl,l016b                ; Give lead in
  956.         jp      l0235
  957. ;
  958. ; Set lead out
  959. ;
  960. l0310:
  961.         ld      hl,l017b                ; Give lead out
  962.         jp      l0235
  963. ;
  964. ; Test key pressed
  965. ; EXIT  Reg HL holds 1 if key pressed
  966. ;
  967. l0316:
  968.         ;ld     de,_.const
  969.         ;call   l035f           ; Get state
  970.         ;and    1               ; Extract the bit
  971.         xor a ;TODO
  972.         jr      l0326 ; Expand result to 16 bit
  973. ;
  974. ; Read character from console
  975. ; EXIT  Reg HL holds character
  976. ;
  977. l0320:
  978.         ld      de,_.conin
  979. l0323:
  980.         ;call   l035f           ; Get input
  981.         push ix ;TODO remove?
  982.         push iy
  983.         GET_KEY
  984.         pop iy
  985.         pop ix ;TODO remove?
  986. l0326:
  987.         ld      l,a             ; Expand result to 16 bit
  988.         ld      h,0
  989.         ret
  990. ;
  991. ; Read character from auxiliary device
  992. ; EXIT  Reg HL holds character
  993. ;
  994. l032a:
  995.          jr l0320 ;??? from console
  996.         ;ld     de,_.auxin      ; Set function
  997.         ;jr     l0323           ; Do thru BIOS
  998. ;
  999. ; Write character to list device
  1000. ; ENTRY Character on stack
  1001. ;
  1002. l032f:
  1003.          jr l0339 ;??? to screen
  1004.         ;ld     de,_.list       ; Set function
  1005.         ;jr     l033c           ; Do thru BIOS
  1006. ;
  1007. ; Write character to auxiliary device
  1008. ; ENTRY Character on stack
  1009. ;
  1010. l0334:
  1011.          jr l0339 ;??? to screen
  1012.         ;ld     de,_.auxout     ; Set function
  1013.         ;jr     l033c           ; Do thru BIOS
  1014. ;
  1015. ; Write character to console
  1016. ; ENTRY Character on stack
  1017. ;
  1018. l0339:
  1019.         pop     hl
  1020.         pop     bc              ; Get character
  1021.         push    hl
  1022.         ld a,c
  1023.         push af
  1024.         push bc
  1025.         push de
  1026.         push hl
  1027.         push ix
  1028.         push iy
  1029.         PRCHAR
  1030.         pop iy
  1031.         pop ix
  1032.         pop hl
  1033.         pop de
  1034.         pop bc
  1035.         pop af
  1036.         ret
  1037.  
  1038.         if 1==0
  1039.         ;ld     de,_.conout     ; Set function
  1040. l033c:
  1041.         pop     hl
  1042.         pop     bc              ; Get character
  1043.         push    hl
  1044.         ld      a,(l00dd)       ; Get $C mode
  1045.         or      a
  1046.         jr      z,l035f         ; $C-, so skip testing
  1047.         push    de
  1048.         push    bc
  1049.         call    l00a0           ; Test key pressed
  1050.         ld      a,h
  1051.         or      l               ; Nope
  1052.         jr      z,l035d
  1053.         call    readfromkbd             ; Read character
  1054.         cp      Xoff            ; Test XOFF
  1055.         jr      nz,l035d
  1056.         call    readfromkbd
  1057.         cp      CtrlC           ; Test abort
  1058.         jp      z,l20d4         ; Halt if so
  1059. l035d:
  1060.         pop     bc
  1061.         pop     de
  1062. ;
  1063. ; Do BIOS internal call
  1064. ;de=jp addr
  1065. l035f:
  1066.         ret
  1067.         ;ld     hl,(OS+1)       ; Fetch base vector
  1068.         ;add    hl,de           ; Add osffset
  1069.         ;jp     (hl)            ; Go
  1070.         endif
  1071. ;
  1072. ; Init TURBO program
  1073. ; ENTRY Reg HL holds top of RAM
  1074. ;       Reg B holds break mode
  1075. ;               ($C- B=00)
  1076. ;               ($C+ B=FF)
  1077. ;       Reg C holds interrupt mode
  1078. ;               ($U- C=00)
  1079. ;               ($U+ C=rst)
  1080. ;       [rst may be the opcode for the requested
  1081. ;        RST opcode, typically F7 or EF]
  1082. ;
  1083. l0364:
  1084.         ld      (l00d2),hl      ; Save address
  1085.         ld      a,b
  1086.         ld      (l00dd),a       ; Set $C mode
  1087.         ld      a,c             ; Get $U
  1088.         or      a
  1089.         jr      z,l037a         ; No interrupt
  1090.         ;ld     a,_JP           ; Set JP to interrupt
  1091.         ;ld     (RSTADDR),a
  1092.         ;ld     hl,l1ffb
  1093.         ;ld     (RSTADDR+1),hl  ; Change vector ;???
  1094. l037a:
  1095.         ld      hl,l03a5
  1096.         ld      de,l00a0
  1097.         ld      bc,ll0018
  1098.         ldir                    ; Unpack I/O
  1099.         ld      hl,l03bd
  1100.         ld      de,l00b8
  1101.         ld      bc,ll000c
  1102.         ldir                    ; Init FIB
  1103.         xor     a
  1104.         ld      l,a
  1105.         ld      h,a
  1106.         ld      (l00d0),a       ; Clear I/O error
  1107.         ld      (l00d4),hl      ; Clear some pointers
  1108.         ld      (l00d6),hl
  1109.         ld      a,_MaxBuf
  1110.         ld      (l00d1),a       ; Set buffer length
  1111.         ld      (l00e0),a       ; Set video mode
  1112.         ret
  1113. ;
  1114. ; Character I/O table moved into 0x00A0
  1115. ;
  1116. l03a5:
  1117.         jp      l0316           ; 0x00A0 : Keypressed
  1118.         jp      l0320           ; 0x00A3 : Read KBD
  1119.         jp      l0339           ; 0x00A6 : Console output
  1120.         jp      l032f           ; 0x00A9 : List output
  1121.         jp      l0334           ; 0x00AC : Auxiliary output
  1122.         jp      l032a           ; 0x00AF : Auxiliary input
  1123.         jp      l0339           ; 0x00B2 : Console output
  1124.         jp      l0320           ; 0x00B5 : Read KBD
  1125. ll0018  equ     $-l03a5
  1126. ;
  1127. ; Standard IO control table
  1128. ;
  1129. l03bd:
  1130.         db      11000001b       ; 0x00B8 : Input Output for CON
  1131.         db      0
  1132.         db      10000010b       ; 0x00BA : Input for KBD
  1133.         db      0
  1134.         db      01000011b       ; 0x00BC : Output for LST
  1135.         db      0
  1136.         db      11000100b       ; 0x00BE : Input Output for AUX
  1137.         db      0
  1138.         db      11000101b       ; 0x00C0 : Input Output for USR
  1139.         db      0
  1140.         db      11000001b       ; 0x00C2 : Input Output for CON
  1141.         db      0
  1142. ll000c  equ     $-l03bd
  1143. ;
  1144. ; Put character to console
  1145. ;
  1146. puttoconsole_a:
  1147.         push    bc
  1148.         push    de
  1149.         push    hl
  1150.         push    ix
  1151.         push    iy
  1152.        
  1153.         push    af
  1154.         PRCHAR
  1155.         ;ld     l,a
  1156.         ;ld     h,0
  1157.         ;push   hl
  1158.         ;call   l00a6           ; Put to console
  1159.         pop     af
  1160.        
  1161. l03d9:
  1162.         pop     iy
  1163.         pop     ix
  1164.         pop     hl
  1165.         pop     de
  1166.         pop     bc
  1167.         ret
  1168. ;
  1169. ; Read character from keyboard
  1170. ;
  1171. readfromkbd:
  1172.         push    bc
  1173.         push    de
  1174.         push    hl
  1175.         push    ix
  1176.         push    iy
  1177.          ld e,0x78
  1178.          OS_PRATTR
  1179.         YIELDGETKEYLOOP
  1180.          push af
  1181.          ld e,0x47
  1182.          OS_PRATTR
  1183.          pop af
  1184.         ;call   l00a3           ; Read KBD
  1185.         ;ld     a,l
  1186.         jr      l03d9
  1187. ;
  1188. ; Parse file, allow wildcards
  1189. ;
  1190. l03ee:
  1191.         ld      c,0xff-FALSE    ; Set flag
  1192.         jr      l03fe
  1193. ;
  1194. ; Parse file, wildcards not allowed
  1195. ;
  1196. l03f2:
  1197.         ld      c,FALSE
  1198.         ld      de,(l00d2)      ; Get top of memory for input
  1199. l03f8:
  1200.         inc     de
  1201.         ld      a,(de)
  1202.         cp      ' '             ; Skip blanks
  1203.         jr      z,l03f8
  1204. l03fe:
  1205.         ld      hl,l005c+Fdrv+Fname
  1206.         ld      b,Fext
  1207.         call    l047b           ; Blank extension
  1208. l0406:
  1209.         ld      a,(de)          ; Get character
  1210.         call    l04a6           ; Convert to upper case
  1211.         cp      'A'             ; Test posible drive
  1212.         jr      c,l0420
  1213.         cp      'P'+1
  1214.         jr      nc,l0420
  1215.         ld      b,a             ; Save drive
  1216.         inc     de
  1217.         ld      a,(de)
  1218.         cp      ':'             ; Verify drive
  1219.         jr      nz,l041f
  1220.         ld      a,b
  1221.         sub     'A'-1           ; Make binary
  1222.         inc     de
  1223.         jr      l0421
  1224. l041f:
  1225.         dec     de
  1226. l0420:
  1227.         xor     a               ; Set default drive
  1228. l0421:
  1229.         ld      hl,l005c
  1230.         ld      (hl),a          ; Save drive
  1231.         inc     hl
  1232.         inc     c               ; Test wildcards allowed
  1233.         dec     c
  1234.         jr      z,l0443         ; Nope
  1235.         ld      a,(de)          ; Get character
  1236.         call    l0482           ; Test delimiter
  1237.         jr      nz,l0443        ; Nope
  1238.         cp      '?'             ; Test single wildcard
  1239.         jr      z,l0443         ; Yeap
  1240.         cp      '*'             ; Test wildcard
  1241.         jr      z,l0443         ; Yeap
  1242.         cp      '.'             ; Test dot
  1243.         jr      z,l0443         ; Yeap
  1244.         ld      b,Fname+Fext
  1245.         call    l0477           ; Set wildcard
  1246.         jr      l0453           ; Go init remainder
  1247. l0443:
  1248.         ld      b,Fname
  1249.         call    l045e           ; Parse name
  1250.         ld      a,(de)
  1251.         cp      '.'             ; Test extension delimiter
  1252.         jr      nz,l0453        ; Nope
  1253.         inc     de
  1254.         ld      b,Fext
  1255.         call    l045e           ; Parse extension
  1256. l0453:
  1257.         ld      hl,l005c+_ex
  1258.         ld      b,FCBlen-_ex
  1259. l0458:
  1260.         ld      (hl),0          ; Clear remainder of FCB
  1261.         inc     hl
  1262.         djnz    l0458
  1263.         ret
  1264. ;
  1265. ; Parse B characters
  1266. ;
  1267. l045e:
  1268.         ld      a,(de)          ; Get character
  1269.         inc     c               ; Test wildcard allowed
  1270.         dec     c
  1271.         jr      z,l046b         ; Nope
  1272.         cp      '?'             ; Test single wildcard
  1273.         jr      z,l0470         ; Save it
  1274.         cp      '*'             ; Test multiple wildcards
  1275.         jr      z,l0476         ; Map them
  1276. l046b:
  1277.         call    l0482           ; Test delimiter
  1278.         jr      z,l047b         ; Yeap
  1279. l0470:
  1280.         ld      (hl),a          ; Store character
  1281.         inc     hl
  1282.         inc     de
  1283.         djnz    l045e
  1284.         ret
  1285. l0476:
  1286.         inc     de
  1287. ;
  1288. ; Set B wildcards
  1289. ;
  1290. l0477:
  1291.         ld      a,'?'           ; Set wildcard character
  1292.         jr      l047d
  1293. ;
  1294. ; Blank B positions in ^HL
  1295. ;
  1296. l047b:
  1297.         ld      a,' '
  1298. l047d:
  1299.         ld      (hl),a          ; Save character
  1300.         inc     hl
  1301.         djnz    l047d
  1302.         ret
  1303. ;
  1304. ; Test delimiter
  1305. ; Z set says yes
  1306. ;
  1307. l0482:
  1308.         call    l04a6           ; Convert to upper case
  1309.         cp      ' '             ; Test control
  1310.         jr      c,l0496         ; Yeap, it's a delimiter
  1311.         push    hl
  1312.         push    bc
  1313.         ld      hl,l0498
  1314.         ld      bc,ll0498
  1315.         cpir                    ; Find in table
  1316.         pop     bc
  1317.         pop     hl
  1318.         ret
  1319. l0496:
  1320.         cp      a
  1321.         ret
  1322. ;
  1323. l0498:
  1324.         db      ' .,;:=?*[]<>{}'
  1325. ll0498  equ     $-l0498
  1326. ;
  1327. ; Convert character to UPPER case
  1328. ;
  1329. l04a6:
  1330.         cp      'a'             ; Test range
  1331.         ret     c
  1332.         cp      'z'+1
  1333.         ret     nc
  1334.         sub     'a'-'A'         ; Convert to upper case
  1335.         ret
  1336. ;
  1337. ; Print hex word in reg HL
  1338. ;
  1339. l04af:
  1340.         ld      a,h             ; Get hi
  1341.         call    l04b4           ; Print it
  1342.         ld      a,l             ; Followed by lo
  1343. ;
  1344. ; Print hex byte in Accu
  1345. ;
  1346. l04b4:
  1347.         push    af
  1348.         rra                     ; Isolate hi bits
  1349.         rra
  1350.         rra
  1351.         rra
  1352.         call    l04bd           ; Convert them
  1353.         pop     af
  1354. l04bd:
  1355.         and     LoMask          ; Mak bits
  1356.         add     a,090h          ; Dirty trick
  1357.         daa
  1358.         adc     a,040h
  1359.         daa
  1360.         jp      puttoconsole_a          ; Put to console
  1361. ;
  1362. ; Get byte from 16 bit
  1363. ; ENTRY Reg HL holds 16 bit signed integer
  1364. ; EXIT  Accu holds 0 and carry set if HL<0
  1365. ;       Accu holds -1 and carry reset if HL>256
  1366. ;       Accu holds low part and carry reset else
  1367. ;
  1368. l04c8:
  1369.         xor     a
  1370.         scf
  1371.         bit     7,h             ; Test sign bit
  1372.         ret     nz              ; Return 0 and C set if HL<0
  1373.         ld      a,h
  1374.         or      a
  1375.         ld      a,l
  1376.         ret     z               ; Return LO if HI=0
  1377.         ld      a,-1            ; Else return -1
  1378.         ret
  1379. ;
  1380. ; Test enough space
  1381. ; ENTRY Reg HL holds 1st free address
  1382. ;       Reg DE holds last free address
  1383. ;       Reg BC holds top of ram
  1384. ;       Accu holds run mode
  1385. ;
  1386. l04d4:
  1387.         ld      (l00d8),a       ; Re/Set runmode (0 is TP menue)
  1388.         push    bc
  1389.         call    l1eaf           ; Init heap
  1390.         pop     bc
  1391.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  1392.         or      a
  1393.         sbc     hl,bc           ; Test memory available
  1394.         jp      c,l20a8         ; Nope, exit
  1395.         ex      de,hl
  1396.         pop     de              ; Get caller
  1397.         ld      sp,hl           ; Set new stack
  1398.         ld      bc,-StkSpc
  1399.         add     hl,bc           ; Allow some stack space
  1400.         ld      (l00c6),hl      ; Set recursion pointer
  1401.         xor     a
  1402.         ld      l,a
  1403.         ld      h,a
  1404.         ld      (l00ce),hl      ; Reset current PC
  1405.         ld      (l00dc),a       ; Reset overlay drive
  1406.         ld      a,_JP
  1407.         ld      (l00d9),a       ; Init restart
  1408.         ld      hl,l20de
  1409.         ld      (l00da),hl      ; Set error vector
  1410.         ex      de,hl
  1411.         ld      (l00cc),hl      ; Set base PC
  1412.         jp      (hl)            ; Jump back to caller
  1413. ;
  1414. ; Start of recursive procedure or function
  1415. ; ENTRY Reg BC holds bytes to be preserved
  1416. ;       Reg HL holds address of save area
  1417. ;
  1418. l0508:
  1419.         push    hl
  1420.         ld      hl,(l00c6)      ; Get recursion pointer
  1421.         or      a
  1422.         sbc     hl,bc           ; Calculate new pointer
  1423.         ld      (l00c6),hl
  1424.         ld      de,(l00c4)      ; Get heap pointer
  1425.         or      a
  1426.         sbc     hl,de           ; Test against it
  1427.         add     hl,de
  1428.         ex      de,hl
  1429.         pop     hl
  1430.         jp      c,l1d75         ; Error if overlapping
  1431.         ldir
  1432.         ret
  1433. ;
  1434. ; End of recursive procedure or function
  1435. ; ENTRY Reg BC holds bytes to be preserved
  1436. ;       Reg DE holds address of save area
  1437. ;
  1438. l0522:
  1439.         ld      hl,(l00c6)      ; Get recursion pointer
  1440.         ldir                    ; Reload code
  1441.         ld      (l00c6),hl      ; Update pointer
  1442.         exx
  1443.         ret
  1444. ;
  1445. ; Load real into registers
  1446. ; ENTRY Reg HL points to real variable
  1447. ; EXIT  Regs HL,DE,BC hold number
  1448. ;
  1449. l052c:
  1450.         ld      e,(hl)          ; Get exponent
  1451.         inc     hl
  1452.         ld      d,(hl)          ; Get LSB
  1453.         inc     hl
  1454.         push    de
  1455.         ld      e,(hl)          ; Get 4th mantissa byte
  1456.         inc     hl
  1457.         ld      d,(hl)          ; Get 3rd mantissa byte
  1458.         inc     hl
  1459.         ld      c,(hl)          ; Get 2nd mantissa byte
  1460.         inc     hl
  1461.         ld      b,(hl)          ; Get MSB
  1462.         pop     hl
  1463.         ret
  1464. ;
  1465. ; move string to stack
  1466. ; ENTRY Reg HL points to string
  1467. ;
  1468. l053a:
  1469.         pop     ix              ; Get caller
  1470.         ex      de,hl
  1471.         ld      a,(de)          ; Get length of string
  1472.         ld      c,a
  1473.         ld      b,0
  1474.         cpl                     ; Negate
  1475.         ld      l,a
  1476.         ld      h,-1
  1477.         add     hl,sp           ; Fix stack
  1478.         ld      sp,hl
  1479.         ex      de,hl
  1480.         inc     bc
  1481.         ldir                    ; move to stack
  1482.         jp      (ix)            ; Exit
  1483. ;
  1484. ; move immediate string to stack
  1485. ; ENTRY String started with length after caller
  1486. ;
  1487. l054d:
  1488.         pop     de              ; Get string pointer
  1489.         ld      a,(de)          ; Get length
  1490.         ld      c,a
  1491.         ld      b,0             ; Expand for 16 bit
  1492.         cpl                     ; Negate
  1493.         ld      l,a
  1494.         ld      h,-1
  1495.         add     hl,sp           ; Fix stack
  1496.         ld      sp,hl
  1497.         ex      de,hl
  1498.         inc     bc
  1499.         ldir                    ; move to stack
  1500.         jp      (hl)
  1501. ;
  1502. ; Push set onto stack
  1503. ; ENTRY Reg HL points to set variable
  1504. ;       Reg C holds set length in bits
  1505. ;       Reg B holds set to be cleared
  1506. ;
  1507. l055d:
  1508.         pop     ix              ; Get caller
  1509.         ex      de,hl
  1510.         ld      hl,-set.len
  1511.         add     hl,sp           ; Adjust stack for max set length
  1512.         ld      sp,hl
  1513.         ex      de,hl
  1514.         push    bc
  1515.         inc     b               ; Test bits to clear
  1516.         dec     b
  1517.         jr      z,l0570         ; Nope
  1518.         xor     a
  1519. l056c:
  1520.         ld      (de),a          ; Clear a part
  1521.         inc     de
  1522.         djnz    l056c
  1523. l0570:
  1524.         ldir                    ; Save set on stack
  1525.         pop     bc
  1526.         ld      a,set.len
  1527.         sub     b
  1528.         sub     c               ; Test remaining bits to clear
  1529.         jr      z,l057f         ; Nope
  1530.         ld      b,a
  1531.         xor     a
  1532. l057b:
  1533.         ld      (de),a          ; Clear bits
  1534.         inc     de
  1535.         djnz    l057b
  1536. l057f:
  1537.         jp      (ix)
  1538. ;
  1539. ; Initialize a set on stack
  1540. ;
  1541. l0581:
  1542.         pop     ix              ; Get caller
  1543.         ld      hl,-set.len
  1544.         add     hl,sp           ; Fix stack
  1545.         ld      sp,hl
  1546.         ld      b,set.len       ; Set count
  1547.         xor     a
  1548. l058b:
  1549.         ld      (hl),a          ; Init set
  1550.         inc     hl
  1551.         djnz    l058b
  1552.         jp      (ix)
  1553. ;
  1554. ; Init one set element
  1555. ; ENTRY Reg HL holds set value to be set
  1556. ;
  1557. l0591:
  1558.         pop     ix
  1559.         ld      b,l             ; Get value
  1560.         call    l05ba           ; Get bit
  1561. l0597:
  1562.         or      (hl)            ; Insert it
  1563.         ld      (hl),a
  1564. l0599:
  1565.         jp      (ix)
  1566. ;
  1567. ; Init a contiguous set value
  1568. ; ENTRY Reg HL holds upper limit
  1569. ;       On stack pushed lower limit
  1570. ;
  1571. l059b:
  1572.         pop     ix
  1573.         pop     de              ; Get lower limit
  1574.         ld      a,l
  1575.         sub     e
  1576.         jr      c,l0599         ; Out of range
  1577.         inc     a
  1578.         ld      c,a
  1579.         ld      b,e             ; Get low value
  1580.         call    l05ba           ; Get bit
  1581.         ld      e,a
  1582.         ld      b,c             ; Copy loop value
  1583.         xor     a
  1584. l05ab:
  1585.         or      e
  1586.         sla     e               ; Shift bit
  1587.         jr      nc,l05b6
  1588.         or      (hl)            ; Insert
  1589.         ld      (hl),a
  1590.         inc     hl              ; Point to next
  1591.         xor     a
  1592.         ld      e,1             ; Init low bit for next
  1593. l05b6:
  1594.         djnz    l05ab
  1595.         jr      l0597           ; Set final one
  1596. ;
  1597. ; Access one set bit
  1598. ; ENTRY Reg B holds numeric value of set element
  1599. ; EXIT  Accu holds bit
  1600. ;       Reg HL points to set loacation
  1601. ;
  1602. l05ba:
  1603.         ld      a,b             ; Get value
  1604.         and     11111000b       ; Mask it
  1605.         rrca                    ; Divide by eight
  1606.         rrca
  1607.         rrca
  1608.         add     a,2             ; Fix position for stack
  1609.         ld      l,a
  1610.         ld      h,0
  1611.         add     hl,sp           ; Get position
  1612.         ld      a,b
  1613.         and     00000111b       ; Mask bits
  1614.         inc     a
  1615.         ld      b,a
  1616.         xor     a
  1617.         scf                     ; Init 1
  1618. l05cd:
  1619.         rla                     ; Shift bit into correct position
  1620.         djnz    l05cd
  1621.         ret
  1622. ;
  1623. ; Save real number
  1624. ; ENTRY Reg HL points to real variable
  1625. ;       Alternative regs HL,DE,BC hold number
  1626. ;
  1627. l05d1:
  1628.         push    hl              ; Save pointer
  1629.         exx
  1630.         ex      de,hl
  1631.         ex      (sp),hl         ; Get back pointer
  1632.         ld      (hl),e          ; Save exponent
  1633.         inc     hl
  1634.         ld      (hl),d          ; Save LSB
  1635.         inc     hl
  1636.         pop     de
  1637.         ld      (hl),e          ; Save 4th mantissa byte
  1638.         inc     hl
  1639.         ld      (hl),d          ; Save 3rd byte
  1640.         inc     hl
  1641.         ld      (hl),c          ; Save 2nd byte
  1642.         inc     hl
  1643.         ld      (hl),b          ; Save MSB
  1644.         ret
  1645. ;
  1646. ; Assign string from stack
  1647. ; ENTRY Reg HL points to string to be assigned
  1648. ;       Reg B holds max length of this string
  1649. ;
  1650. l05e2:
  1651.         pop     ix              ; Get caller
  1652.         ld      a,b             ; Get max
  1653.         ex      de,hl           ; Swap pointer
  1654.         ld      hl,0
  1655.         ld      b,h
  1656.         add     hl,sp           ; Fix stack for start of string
  1657.         ld      c,(hl)          ; Get this length
  1658.         push    hl
  1659.         add     hl,bc           ; Calculate new stack
  1660. l05ee:
  1661.         inc     hl
  1662.         ex      (sp),hl
  1663.         cp      c               ; Test length
  1664.         jr      c,l05f4
  1665.         ld      a,c             ; Get smaller one
  1666. l05f4:
  1667.         ld      (de),a          ; Unpack length
  1668.         inc     de
  1669.         inc     hl
  1670.         or      a               ; Test any character
  1671.         jr      z,l05fd         ; Nope
  1672.         ld      c,a
  1673.         ldir                    ; Unpack if so
  1674. l05fd:
  1675.         pop     hl
  1676.         ld      sp,hl
  1677.         jp      (ix)
  1678. ;
  1679. ; Assign string from stack
  1680. ; ENTRY Reg B holds max length of string
  1681. ;
  1682. l0601:
  1683.         pop     ix              ; Get caller
  1684.         ld      a,b             ; Get max
  1685.         ld      hl,0
  1686.         ld      b,h
  1687.         add     hl,sp           ; Fix stack for start of string
  1688.         ld      c,(hl)          ; Get this length
  1689.         push    hl
  1690.         add     hl,bc           ; Calculate new stack
  1691.         inc     hl
  1692.         ld      e,(hl)          ; Fetch address of string
  1693.         inc     hl
  1694.         ld      d,(hl)
  1695.         jr      l05ee           ; Unpack it
  1696. ;
  1697. ; Assign set variable
  1698. ; ENTRY Reg HL points to variable
  1699. ;       Reg BC holds length of set
  1700. ;
  1701. l0612:
  1702.         pop     ix              ; Get caller
  1703.         ex      de,hl
  1704.         ld      l,b             ; Copy length
  1705.         ld      h,0
  1706.         ld      b,h
  1707.         add     hl,sp           ; Point to start location
  1708.         ldir                    ; Unpack set variable
  1709.         ld      hl,set.len
  1710. l061f:
  1711.         add     hl,sp           ; Fix stack
  1712.         ld      sp,hl
  1713.         jp      (ix)            ; Exit
  1714. ;
  1715. ; Assign set variable
  1716. ; ENTRY Reg BC holds length of set
  1717. ;
  1718. l0623:
  1719.         pop     ix              ; Get caller
  1720.         ld      hl,set.len
  1721.         add     hl,sp           ; Point to destination
  1722.         ld      e,(hl)          ; Get it
  1723.         inc     hl
  1724.         ld      d,(hl)
  1725.         ld      l,b             ; Copy length
  1726.         ld      h,0
  1727.         ld      b,h
  1728.         add     hl,sp           ; Point to start location
  1729.         ldir
  1730.         ld      hl,set.len+2    ; Remember address
  1731.         jr      l061f           ; Fix stack
  1732. ;
  1733. ; Set set to stack
  1734. ; ENTRY Reg HL holds address of set
  1735. ;       Reg B  holds length of set
  1736. ;
  1737. l0638:
  1738.         pop     ix              ; Get caller
  1739.         ex      de,hl           ; Swap source
  1740.         ld      a,b
  1741.         cpl
  1742.         ld      l,a
  1743.         ld      h,-1            ; Get -length
  1744.         add     hl,sp           ; Fix stack
  1745.         ld      sp,hl           ; Set new
  1746.         ld      (hl),b          ; Set length
  1747.         inc     hl
  1748.         ld      c,b             ; Expand length
  1749.         ld      b,0
  1750.         ex      de,hl           ; Get back source
  1751.         ldir                    ; move to stack
  1752.         jp      (ix)
  1753. ;
  1754. ; Index check on compiler directive {$R+}
  1755. ; ENTRY Reg HL holds current index
  1756. ;       Reg DE holds max index
  1757. ;
  1758. l064c:
  1759.         or      a
  1760.         sbc     hl,de           ; Verify limit ok
  1761.         add     hl,de
  1762.         ret     c               ; Yeap
  1763.         ld      a,_IndxErr
  1764.         jp      l2027           ; Else process error
  1765. ;
  1766. ; Range check on compiler directive {$R+}
  1767. ; ENTRY Reg HL holds actual value
  1768. ;       Reg DE holds low limit
  1769. ;       Reg BC holds range of value
  1770. ;
  1771. l0656:
  1772.         or      a
  1773.         sbc     hl,de
  1774.         or      a
  1775.         sbc     hl,bc           ; Test max
  1776.         jr      nc,l0661        ; Error
  1777.         add     hl,bc           ; Restore value
  1778.         add     hl,de
  1779.         ret
  1780. l0661:
  1781.         ld      a,_RngErr
  1782.         jp      l2027           ; Set error
  1783. ;
  1784. ; Set up FOR .. TO loop
  1785. ; ENTRY Reg DE holds start value
  1786. ;       Reg HL holds end value
  1787. ; EXIT  Reg DE holds loops
  1788. ;       Reg HL holds start value
  1789. ;
  1790. l0666:
  1791.         or      a
  1792.         sbc     hl,de           ; Get difference
  1793.         ex      de,hl           ; Into reg DE
  1794. l066a:
  1795.         inc     de              ; Fix loop count
  1796.         jp      pe,l0671        ; Check any loop
  1797.         ret     p
  1798.         jr      l0672
  1799. l0671:
  1800.         ret     m
  1801. l0672:
  1802.         ld      de,0            ; Set no loop
  1803.         ret
  1804. ;
  1805. ; Set up FOR .. DOWNTO loop
  1806. ; ENTRY Reg DE holds start value
  1807. ;       Reg HL holds end value
  1808. ; EXIT  Reg DE holds loops
  1809. ;       Reg HL holds start value
  1810. ;
  1811. l0676:
  1812.         push    de
  1813.         ex      de,hl
  1814.         or      a
  1815.         sbc     hl,de           ; Get difference
  1816.         ex      de,hl
  1817.         pop     hl
  1818.         jr      l066a           ; Build loop
  1819. ;
  1820. ; ################## The comparison package ###################
  1821. ; # TRUE set (=1 on TURBO) if relation matches                #
  1822. ; #                                                           #
  1823. ; # On all relational functions the assignment is as follows: #
  1824. ; #                                                           #
  1825. ; # INTEGER : DE:HL                                           #
  1826. ; # REAL    : (Regs):(Regs)'                                  #
  1827. ; # STRING  : (Stack):(next_stack)                            #
  1828. ; #                                                           #
  1829. ; #############################################################
  1830. ;
  1831. ; ********************************
  1832. ; ********** Relation = **********
  1833. ; ********************************
  1834. ;
  1835. ; %%%%%%%%%%%%%
  1836. ; %% INTEGER %%
  1837. ; %%%%%%%%%%%%%
  1838. ;
  1839. l067f:
  1840.         or      a
  1841.         sbc     hl,de           ; Get difference
  1842. l0682:
  1843.         ld      hl,_TRUE        ; Init TRUE
  1844.         ret     z               ; Ok, same
  1845.         dec     hl              ; Fix for FALSE
  1846.         ret
  1847. ;
  1848. ; %%%%%%%%%%
  1849. ; %% REAL %%
  1850. ; %%%%%%%%%%
  1851. ;
  1852. l0688:
  1853.         call    l0bdf           ; Compare
  1854.         jr      l0682           ; Set result
  1855. ;
  1856. ; %%%%%%%%%%%%
  1857. ; %% STRING %%
  1858. ; %%%%%%%%%%%%
  1859. ;
  1860. l068d:
  1861.         call    l09b0           ; Compare
  1862.         jr      l0682           ; Set result
  1863. ;
  1864. ; *********************************
  1865. ; ********** Relation <> **********
  1866. ; *********************************
  1867. ;
  1868. ; %%%%%%%%%%%%%
  1869. ; %% INTEGER %%
  1870. ; %%%%%%%%%%%%%
  1871. ;
  1872. l0692:
  1873.         or      a
  1874.         sbc     hl,de           ; Get difference
  1875. l0695:
  1876.         ld      hl,_TRUE        ; Init TRUE
  1877.         ret     nz              ; Ok, not same
  1878.         dec     hl              ; Fix for FALSE
  1879.         ret
  1880. ;
  1881. ; %%%%%%%%%%
  1882. ; %% REAL %%
  1883. ; %%%%%%%%%%
  1884. ;
  1885. l069b:
  1886.         call    l0bdf           ; Compare
  1887.         jr      l0695           ; Set result
  1888. ;
  1889. ; %%%%%%%%%%%%
  1890. ; %% STRING %%
  1891. ; %%%%%%%%%%%%
  1892. ;
  1893. l06a0:
  1894.         call    l09b0           ; Compare
  1895.         jr      l0695           ; Set result
  1896. ;
  1897. ; *********************************
  1898. ; ********** Relation >= **********
  1899. ; *********************************
  1900. ;
  1901. ; %%%%%%%%%%%%%
  1902. ; %% INTEGER %%
  1903. ; %%%%%%%%%%%%%
  1904. ;
  1905. l06a5:
  1906.         call    l0772           ; Check operands
  1907. l06a8:
  1908.         ld      hl,_TRUE        ; Init TRUE
  1909.         ret     nc              ; Ok if .GTE.
  1910.         dec     hl              ; Else fix for FALSE
  1911.         ret
  1912. ;
  1913. ; %%%%%%%%%%
  1914. ; %% REAL %%
  1915. ; %%%%%%%%%%
  1916. ;
  1917. l06ae:
  1918.         call    l0bdf           ; Compare
  1919.         jr      l06a8           ; Set result
  1920. ;
  1921. ; %%%%%%%%%%%%
  1922. ; %% STRING %%
  1923. ; %%%%%%%%%%%%
  1924. ;
  1925. l06b3:
  1926.         call    l09b0           ; Compare
  1927.         jr      l06a8           ; Set result
  1928. ;
  1929. ; *********************************
  1930. ; ********** Relation <= **********
  1931. ; *********************************
  1932. ;
  1933. ; %%%%%%%%%%%%%
  1934. ; %% INTEGER %%
  1935. ; %%%%%%%%%%%%%
  1936. ;
  1937. l06b8:
  1938.         call    l0772           ; Check operands
  1939. l06bb:
  1940.         ld      hl,_TRUE        ; Init TRUE
  1941.         ret     z               ; Ok if .EQ.
  1942.         ret     c               ; Ok if .LT.
  1943.         dec     hl              ; Else fix for FALSE
  1944.         ret
  1945. ;
  1946. ; %%%%%%%%%%
  1947. ; %% REAL %%
  1948. ; %%%%%%%%%%
  1949. ;
  1950. l06c2:
  1951.         call    l0bdf           ; Compare
  1952.         jr      l06bb           ; Set result
  1953. ;
  1954. ; %%%%%%%%%%%%
  1955. ; %% STRING %%
  1956. ; %%%%%%%%%%%%
  1957. ;
  1958. l06c7:
  1959.         call    l09b0           ; Compare
  1960.         jr      l06bb           ; Set result
  1961. ;
  1962. ; ********************************
  1963. ; ********** Relation > **********
  1964. ; ********************************
  1965. ;
  1966. ; %%%%%%%%%%%%%
  1967. ; %% INTEGER %%
  1968. ; %%%%%%%%%%%%%
  1969. ;
  1970. l06cc:
  1971.         call    l0772           ; Check operands
  1972. l06cf:
  1973.         ld      hl,FALSE        ; Init FALSE
  1974.         ret     z               ; Ok if .EQ.
  1975.         ret     c               ; Ok if .LT.
  1976.         inc     hl              ; Else fix for TRUE
  1977.         ret
  1978. ;
  1979. ; %%%%%%%%%%
  1980. ; %% REAL %%
  1981. ; %%%%%%%%%%
  1982. ;
  1983. l06d6:
  1984.         call    l0bdf           ; Compare
  1985.         jr      l06cf           ; Set result
  1986. ;
  1987. ; %%%%%%%%%%%%
  1988. ; %% STRING %%
  1989. ; %%%%%%%%%%%%
  1990. ;
  1991. l06db:
  1992.         call    l09b0           ; Compare
  1993.         jr      l06cf           ; Set result
  1994. ;
  1995. ; ********************************
  1996. ; ********** Relation < **********
  1997. ; ********************************
  1998. ;
  1999. ; %%%%%%%%%%%%%
  2000. ; %% INTEGER %%
  2001. ; %%%%%%%%%%%%%
  2002. ;
  2003. l06e0:
  2004.         call    l0772           ; Check operands
  2005. l06e3:
  2006.         ld      hl,_TRUE        ; Init TRUE
  2007.         ret     c               ; Ok if .LT.
  2008.         dec     hl              ; Else fix for FALSE
  2009.         ret
  2010. ;
  2011. ; %%%%%%%%%%
  2012. ; %% REAL %%
  2013. ; %%%%%%%%%%
  2014. ;
  2015. l06e9:
  2016.         call    l0bdf           ; Compare
  2017.         jr      l06e3           ; Set result
  2018. ;
  2019. ; %%%%%%%%%%%%
  2020. ; %% STRING %%
  2021. ; %%%%%%%%%%%%
  2022. ;
  2023. l06ee:
  2024.         call    l09b0           ; Compare
  2025.         jr      l06e3           ; Set result
  2026. ;
  2027. ; ################# End of comparison package #################
  2028. ;
  2029. ; Function SQR(integer):integer;
  2030. ; ENTRY Reg HL holds number
  2031. ; EXIT  Reg HL holds power
  2032. ;
  2033. l06f3:
  2034.         ld      d,h             ; Copy number
  2035.         ld      e,l
  2036. ;
  2037. ; Operator *
  2038. ; Multiply signed integers
  2039. ; ENTRY Reg DE holds multiplicand
  2040. ;       Reg HL holds multiplier
  2041. ; EXIT  Reg HL holds product
  2042. ;
  2043. l06f5:
  2044.         ld      c,e             ; Copy multiplicand
  2045.         ld      b,d
  2046.         ex      de,hl
  2047.         ld      hl,0            ; Init product
  2048.         ld      a,d
  2049.         or      a               ; Test word
  2050.         ld      a,16
  2051.         jr      nz,l0704        ; Yeap, set bit count
  2052.         ld      d,e
  2053.         ld      a,8             ; Change bit count
  2054. l0704:
  2055.         add     hl,hl           ; Do the multiplication
  2056.         ex      de,hl
  2057.         add     hl,hl
  2058.         ex      de,hl
  2059.         jr      nc,l070b
  2060.         add     hl,bc
  2061. l070b:
  2062.         dec     a
  2063.         jr      nz,l0704
  2064.         ret
  2065. ;
  2066. ; Operator DIV
  2067. ; Divide signed integers
  2068. ; ENTRY Reg DE holds dividend
  2069. ;       Reg HL holds divisor
  2070. ; EXIT  Reg HL holds quotient
  2071. ;       Reg DE holds remainder
  2072. ;
  2073. l070f:
  2074.         ld      a,h             ; Test zero divisor
  2075.         or      l
  2076.         jp      z,l0a03         ; Divide by zero
  2077.         ld      a,h
  2078.         xor     d               ; Calculate sign
  2079.         push    af
  2080.         call    l0780           ; Make both numbers positive
  2081.         ex      de,hl
  2082.         call    l0780
  2083.         ex      de,hl
  2084.         ld      b,h             ; Copy divisor
  2085.         ld      c,l
  2086.         xor     a
  2087.         ld      h,a             ; Clear result
  2088.         ld      l,a
  2089.         ld      a,17            ; Set bit count
  2090. l0726:
  2091.         adc     hl,hl           ; Perform division
  2092.         sbc     hl,bc
  2093.         jr      nc,l072e
  2094.         add     hl,bc
  2095.         scf
  2096. l072e:
  2097.         ccf
  2098.         rl      e
  2099.         rl      d
  2100.         dec     a               ; Test done
  2101.         jr      nz,l0726        ; Nope, loop on
  2102.         ex      de,hl
  2103.         pop     af              ; Get resulting sign
  2104.         ret     p
  2105.         jr      l0783           ; Negate result
  2106. ;
  2107. ; Function RANDOM(integer):integer
  2108. ; ENTRY Reg HL holds integer limit
  2109. ; EXIT  Reg HL holds random
  2110. ;
  2111. l073b:
  2112.         push    hl
  2113.         call    l0792           ; Get random value
  2114.         srl     h               ; Make positive, dividing by 2
  2115.         rr      l
  2116.         pop     de
  2117.         ex      de,hl
  2118. ;
  2119. ; Operator MOD
  2120. ; Get modulo of signed integers
  2121. ; ENTRY Reg DE holds dividend
  2122. ;       Reg HL holds divisor
  2123. ; EXIT  Reg HL holds remainder
  2124. ;
  2125. l0745:
  2126.         call    l070f           ; HL:=DE DIV HL;DE:=DE MOD HL
  2127.         ex      de,hl           ; Swap remainder
  2128.         bit     7,d             ; Test result
  2129.         ret     z
  2130.         jr      l0783           ; Negate
  2131. ;
  2132. ; Operator SHL
  2133. ; Shift left number
  2134. ; ENTRY Reg DE holds number to be shifted
  2135. ;       Reg HL holds shift count
  2136. ; EXIT  Reg HL holds result
  2137. ;
  2138. l074e:
  2139.         call    l0761           ; Get shift values
  2140.         ret     z               ; End on zero
  2141. l0752:
  2142.         add     hl,hl           ; Shift
  2143.         djnz    l0752
  2144.         ret
  2145. ;
  2146. ; Operator SHR
  2147. ; Shift right number
  2148. ; ENTRY Reg DE holds number to be shifted
  2149. ;       Reg HL holds shift count
  2150. ; EXIT  Reg HL holds result
  2151. ;
  2152. l0756:
  2153.         call    l0761           ; Get shift values
  2154.         ret     z               ; End on zero
  2155. l075a:
  2156.         srl     h               ; Shift
  2157.         rr      l
  2158.         djnz    l075a
  2159.         ret
  2160. ;
  2161. ; Set shift values
  2162. ; ENTRY Reg HL holds number to be shifted
  2163. ;       Reg DE holds shift count
  2164. ; EXIT  Reg B holds shift count
  2165. ;       Zero flag set on nothing to be shifted
  2166. ;       Reg HL may be preset to zero
  2167. ;
  2168. l0761:
  2169.         ex      de,hl           ; Swap factor
  2170.         ld      a,d             ; Test hi zero value
  2171.         or      a
  2172.         jr      nz,l076e        ; Nope, should be
  2173.         ld      a,e
  2174.         cp      16              ; Test max length
  2175.         jr      nc,l076e        ; Overflow
  2176.         ld      b,a
  2177.         or      a
  2178.         ret
  2179. l076e:
  2180.         xor     a
  2181.         ld      h,a             ; Clear result
  2182.         ld      l,a
  2183.         ret
  2184. ;
  2185. ; Compare signed integers
  2186. ; ENTRY Reg DE holds 1st number
  2187. ;       Reg HL holds 2nd number
  2188. ; EXIT  Zero  flag set if DE=HL
  2189. ;       Carry flag set if DE<HL
  2190. ;
  2191. l0772:
  2192.         ex      de,hl
  2193.         ld      a,h
  2194.         xor     d               ; Test same signs
  2195.         ld      a,h
  2196.         jp      m,l077e         ; Nope, fix carry
  2197.         cp      d               ; Compare hi
  2198.         ret     nz
  2199.         ld      a,l
  2200.         cp      e               ; Compare lo if hi is same
  2201.         ret
  2202. l077e:
  2203.         rla                     ; Get sign of first number
  2204.         ret
  2205. ;
  2206. ; Function ABS(integer):integer;
  2207. ; ENTRY Reg HL holds signed integer
  2208. ; EXIT  Reg HL holds positive integer
  2209. ;
  2210. l0780:
  2211.         bit     _MB,h           ; Test sign
  2212.         ret     z               ; Already positive
  2213. l0783:
  2214.         ld      a,h             ; Build one's complement
  2215.         cpl
  2216.         ld      h,a
  2217.         ld      a,l
  2218.         cpl
  2219.         ld      l,a
  2220.         inc     hl              ; Fix for two's complement
  2221.         ret
  2222. ;
  2223. ; Function ODD(integer):boolean
  2224. ;
  2225. l078b:
  2226.         ld      a,l             ; Get lo byte
  2227.         and     LSB             ; Extract bit
  2228.         ld      l,a             ; Expand to 16 bit
  2229.         ld      h,0
  2230.         ret
  2231. ;
  2232. ; Get random value
  2233. ; EXIT  Regs BC and HL hold byte 3 and 4 of resulting random
  2234. ;       Reg  DE holds middle part of real number
  2235. ;
  2236. l0792:
  2237.         ld      bc,(l00c8+2)    ; Load old values
  2238.         ld      de,(l00c8)
  2239.         push    bc              ; Save them
  2240.         push    de
  2241.         ld      a,b             ; Expand to 40 bits
  2242.         ld      b,c
  2243.         ld      c,d
  2244.         ld      d,e
  2245.         ld      e,0
  2246.         rra                     ; Shift them all
  2247.         rr      b
  2248.         rr      c
  2249.         rr      d
  2250.         rr      e
  2251.         pop     hl
  2252.         add     hl,de           ; Add to old
  2253.         ex      de,hl
  2254.         pop     hl
  2255.         adc     hl,bc
  2256.         ld      b,h
  2257.         ld      c,l
  2258.         ld      hl,0110001011101001b
  2259.         add     hl,de           ; Fix them - add 62E9H
  2260.         ld      (l00c8),hl      ; Save new values
  2261.         ex      de,hl
  2262.         ld      hl,0011011000011001b
  2263.         adc     hl,bc           ; Add 3619H
  2264.         ld      (l00c8+2),hl
  2265.         ld      b,h             ; Copy result
  2266.         ld      c,l
  2267.         ret
  2268. ;
  2269. ; Convert positive integer to ASCII number
  2270. ; ENTRY Reg IX points to ASCII buffer
  2271. ;       Reg HL holds integer
  2272. ; EXIT  Buffer filled
  2273. ;
  2274. l07c6:
  2275.         ld      b,0             ; Init flag
  2276.         ld      de,10000
  2277.         call    l07e2           ; Start with 10000s
  2278.         ld      de,1000
  2279.         call    l07e2           ; Then 1000s
  2280.         ld      de,100
  2281.         call    l07e2           ; Then 100s
  2282.         ld      e,10
  2283.         call    l07e2           ; Then 10s
  2284.         ld      a,l             ; Get remainder
  2285.         jr      l07ef
  2286. l07e2:
  2287.         xor     a               ; Clear quotient
  2288. l07e3:
  2289.         inc     a               ; Advance quotient
  2290.         sbc     hl,de           ; Divide
  2291.         jr      nc,l07e3        ; Still positive
  2292.         add     hl,de           ; Fix for last number
  2293.         inc     b               ; Access flag
  2294.         dec     a               ; Test zero digit
  2295.         jr      nz,l07ef        ; Nope, so store result
  2296.         dec     b               ; Test flag
  2297.         ret     z               ; No leading zeroes
  2298. l07ef:
  2299.         add     a,'0'           ; Make ASCII
  2300.         ld      (ix+0),a        ; Save it
  2301.         inc     ix              ; Advance buffer
  2302.         ret
  2303. ;
  2304. ; Convert ASCII number to integer
  2305. ; ENTRY Reg IX points to ASCII number
  2306. ; EXIT  Reg HL holds integer
  2307. ;       Carry set on overflow
  2308. ;
  2309. l07f7:
  2310.         ld      a,(ix+0)
  2311.         sub     '$'             ; Test hex indicator
  2312.         ld      c,a             ; Save flag
  2313.         ld      hl,0            ; Init result
  2314.         jr      nz,l0804
  2315. l0802:
  2316.         inc     ix              ; Skip indicator
  2317. l0804:
  2318.         ld      a,(ix+0)
  2319.         call    l04a6           ; Convert to upper case
  2320.         sub     '0'             ; Strip off offset
  2321.         jr      c,l0837         ; Out of range
  2322.         cp      9+1             ; Test decimal
  2323.         jr      c,l0820         ; Yeap
  2324.         inc     c               ; Test hex allowed
  2325.         dec     c
  2326.         jr      nz,l0837        ; Nope
  2327.         sub     'A'-'0'-10      ; Fix hex offset
  2328.         cp      10              ; Verify correct range
  2329.         jr      c,l0837
  2330.         cp      15+1
  2331.         jr      nc,l0837
  2332. l0820:
  2333.         ld      d,h             ; Copy current number
  2334.         ld      e,l
  2335.         add     hl,hl           ; * 2
  2336.         ret     c               ; Overflow
  2337.         add     hl,hl           ; * 4
  2338.         ret     c
  2339.         inc     c               ; Test hex
  2340.         dec     c
  2341.         jr      nz,l082c
  2342.         ld      d,h             ; Copy * 4
  2343.         ld      e,l
  2344. l082c:
  2345.         add     hl,de           ; * 5 or * 8
  2346.         ret     c
  2347.         add     hl,hl           ; * 10 or * 16
  2348.         ret     c
  2349.         ld      e,a
  2350.         ld      d,0
  2351.         add     hl,de           ; Insert new digit
  2352.         ret     c
  2353.         jr      l0802
  2354. l0837:
  2355.         ld      a,c
  2356.         or      a               ; Test hex
  2357.         ret     z               ; Yeap
  2358.         ld      a,h
  2359.         add     a,a             ; Get MSB into carry if decimal
  2360.         ret
  2361. ;
  2362. ; Add two strings
  2363. ; ENTRY Stack holds strings
  2364. ; EXIT  Stack holds combined string
  2365. ;
  2366. l083d:
  2367.         pop     ix              ; Get caller
  2368.         pop     hl
  2369.         push    hl
  2370.         ld      a,l             ; Get length of 1st
  2371.         ld      h,0
  2372.         inc     hl
  2373.         add     hl,sp           ; Point to 2nd
  2374.         ld      c,(hl)
  2375.         add     a,c             ; Add lengthes
  2376.         jr      c,l0866         ; Too long
  2377.         ld      (hl),a          ; Set new length
  2378.         ex      de,hl
  2379.         ld      hl,0
  2380.         ld      b,h
  2381.         sbc     hl,bc           ; Prepare moving strings
  2382.         add     hl,sp
  2383.         ld      sp,hl
  2384.         ex      de,hl
  2385.         push    hl
  2386.         inc     bc
  2387.         ldir                    ; move into right place
  2388.         ex      de,hl
  2389.         pop     hl
  2390.         dec     hl
  2391.         dec     de
  2392.         ld      c,a
  2393.         inc     bc
  2394.         lddr
  2395.         ex      de,hl
  2396.         inc     hl
  2397.         ld      sp,hl
  2398.         jp      (ix)
  2399. l0866:
  2400.         ld      a,_StrLenErr    ; Set error
  2401.         jp      l2029
  2402. ;
  2403. ; Function COPY(string,start,length):string
  2404. ; ENTRY Start on stack, followed by string
  2405. ;       Reg HL holds length
  2406. ; EXIT  Substring on stack
  2407. ;
  2408. l086b:
  2409.         pop     ix              ; Get caller
  2410.         call    l04c8           ; Get length byte from integer
  2411.         ld      d,a
  2412.         pop     hl              ; Get start
  2413.         call    l09dd           ; Verify 1..255
  2414.         ld      e,a
  2415.         pop     hl              ; Get length ( - and 1st character)
  2416.         push    hl
  2417.         ld      a,l
  2418.         sub     e               ; Test against start
  2419.         jr      c,l0896         ; Out of bounds
  2420.         inc     d               ; Test zero length
  2421.         dec     d
  2422.         jr      z,l0896         ; Yeap, done
  2423.         cp      d               ; Compare against length
  2424.         jr      c,l0899         ; Nothing to move
  2425.         ld      c,d             ; Fix a bit
  2426.         ld      b,0
  2427.         ld      h,b
  2428.         add     hl,sp
  2429.         ld      a,e
  2430.         add     a,d
  2431.         ld      d,h
  2432.         ld      e,l
  2433.         dec     a
  2434.         ld      l,a
  2435.         ld      h,b
  2436.         add     hl,sp
  2437.         ld      a,c
  2438.         lddr                    ; Then move down
  2439.         ex      de,hl
  2440.         jr      l089f
  2441. l0896:
  2442.         xor     a               ; Set zero length
  2443.         jr      l089c
  2444. l0899:
  2445.         inc     a               ; Fix length
  2446.         ld      l,e
  2447.         dec     l               ; Fix position
  2448. l089c:
  2449.         ld      h,0
  2450.         add     hl,sp           ; Copy position
  2451. l089f:
  2452.         ld      (hl),a          ; Store length
  2453.         ld      sp,hl           ; Get stack
  2454.         jp      (ix)            ; Exit
  2455. ;
  2456. ; Function LENGTH(string):integer
  2457. ; ENTRY String on stack
  2458. ; EXIT  Reg HL holds length
  2459. ;
  2460. l08a3:
  2461.         pop     ix              ; Get caller
  2462.         pop     hl              ; Get length ( - and 1st character)
  2463.         push    hl
  2464.         ld      a,l             ; Save length
  2465.         ld      h,0
  2466.         inc     hl
  2467.         add     hl,sp
  2468.         ld      sp,hl           ; Fix stack
  2469.         ld      l,a             ; Get 16 bit length
  2470.         ld      h,0
  2471.         jp      (ix)            ; Exit
  2472. ;
  2473. ; Function POS(substring,string):integer
  2474. ; ENTRY String on stack, followed by substring
  2475. ; EXIT  Reg HL holds position, 0 is not found
  2476. ;
  2477. l08b2:
  2478.         pop     ix              ; Get caller
  2479.         ld      hl,0
  2480.         ld      d,h
  2481.         add     hl,sp           ; Copy stack
  2482.         ld      e,(hl)          ; Get length of main_string
  2483.         ld      c,e
  2484.         inc     hl
  2485.         push    hl
  2486.         add     hl,de           ; Point to sub_string
  2487.         ld      e,(hl)          ; Get length of sub_string
  2488.         ld      b,e
  2489.         inc     hl
  2490.         push    hl
  2491.         add     hl,de           ; Point to end of both
  2492.         push    hl
  2493.         pop     iy              ; Copy address
  2494.         pop     de              ; Get sub_string
  2495.         pop     hl              ; Get main_string
  2496.         ld      a,c
  2497.         sub     b               ; Test range
  2498.         jr      c,l08dc         ; Sub_string > main_string - no match
  2499.         inc     a               ; Fix count
  2500.         ld      c,a
  2501. l08ce:
  2502.         push    bc
  2503.         push    de
  2504.         push    hl
  2505. l08d1:
  2506.         ld      a,(de)
  2507.         cp      (hl)            ; Compare
  2508.         jr      z,l08e1         ; Maybe success
  2509.         pop     hl
  2510.         pop     de
  2511.         pop     bc
  2512.         inc     hl
  2513.         dec     c               ; Test more to search
  2514.         jr      nz,l08ce        ; Ok, then try next
  2515. l08dc:
  2516.         ld      hl,0            ; Set zero result
  2517.         jr      l08ef
  2518. l08e1:
  2519.         inc     hl
  2520.         inc     de
  2521.         djnz    l08d1           ; Loop thru sub_string
  2522.         pop     de
  2523.         pop     hl
  2524.         pop     bc
  2525.         ld      hl,0
  2526.         add     hl,sp           ; Get pointers
  2527.         ex      de,hl
  2528.         sbc     hl,de           ; Calculate resulting position
  2529. l08ef:
  2530.         ld      sp,iy           ; Set stack
  2531.         jp      (ix)            ; Exit
  2532. ;
  2533. ; Procedure DELETE(string,start,length)
  2534. ; ENTRY Start on stack, followed by string
  2535. ;       Reg HL holds length
  2536. ;
  2537. l08f3:
  2538.         pop     ix              ; Get caller
  2539.         call    l04c8           ; Get length byte from integer
  2540.         ld      c,a
  2541.         pop     hl
  2542.         call    l09dd           ; Verify length in range 1..255
  2543.         ld      e,a
  2544.         pop     hl              ; Get start_string
  2545.         ld      a,(hl)          ; Get length
  2546.         sub     e               ; Test start > length
  2547.         jr      c,l091e         ; Exit if so
  2548.         inc     c
  2549.         dec     c               ; Test any length
  2550.         jr      z,l091e         ; Nope, exit
  2551.         sub     c               ; Test remaining count
  2552.         jr      c,l091c         ; Nope, done
  2553.         push    af
  2554.         ld      a,(hl)
  2555.         sub     c
  2556.         ld      (hl),a
  2557.         ld      b,0
  2558.         ld      d,b
  2559.         add     hl,de           ; Point to destination
  2560.         ld      d,h
  2561.         ld      e,l
  2562.         add     hl,bc           ; Point to source
  2563.         pop     af
  2564.         inc     a
  2565.         ld      c,a
  2566.         ldir                    ; Unpack
  2567.         jr      l091e
  2568. l091c:
  2569.         dec     e               ; Adjust length
  2570.         ld      (hl),e          ; Store it
  2571. l091e:
  2572.         jp      (ix)            ; Exit
  2573. ;
  2574. ; Procedure INSERT(string,substring,start)
  2575. ; ENTRY Pointer of substring on stack, followed by string
  2576. ;       Reg HL holds start
  2577. ;       Reg B holds max length of string
  2578. ;
  2579. l0920:
  2580.         pop     ix              ; Get caller
  2581.         call    l09dd           ; Verify start in range 1..255
  2582.         ld      c,a
  2583.         pop     de              ; Get sub_string
  2584.         ld      (l00e8),de
  2585.         ld      hl,0
  2586.         add     hl,sp           ; Get string pointer
  2587.         ld      a,(de)
  2588.         push    af
  2589.         add     a,(hl)          ; Get combined length
  2590.         jr      c,l0937         ; Truncate on overflow
  2591.         cp      b               ; Compare against max
  2592.         jr      c,l0938         ; Ok
  2593. l0937:
  2594.         ld      a,b             ; Set max defualt
  2595. l0938:
  2596.         ld      (de),a          ; Save combined length
  2597.         pop     af              ; Get length of substring
  2598.         ld      d,a
  2599.         ld      e,(hl)
  2600.         sub     c               ; Get remainder
  2601.         jr      c,l096e         ; Skip
  2602.         inc     a
  2603.         ld      l,a
  2604.         ld      a,d
  2605.         add     a,e
  2606.         jr      c,l0949
  2607.         cp      b
  2608.         ld      a,l
  2609.         jr      c,l0951
  2610. l0949:
  2611.         ld      a,b
  2612.         sub     e
  2613.         jr      c,l0973
  2614.         sub     c
  2615.         jr      c,l0973
  2616.         inc     a
  2617. l0951:
  2618.         or      a
  2619.         jr      z,l0973
  2620.         push    bc
  2621.         push    de
  2622.         ld      hl,(l00e8)      ; Get back sub_string pointer
  2623.         ld      e,a
  2624.         dec     e
  2625.         ld      d,0
  2626.         ld      b,d
  2627.         add     hl,de
  2628.         add     hl,bc
  2629.         pop     de
  2630.         push    de
  2631.         push    hl
  2632.         ld      d,b
  2633.         add     hl,de
  2634.         ex      de,hl
  2635.         pop     hl
  2636.         ld      c,a
  2637.         lddr                    ; move down
  2638.         pop     de
  2639.         pop     bc
  2640.         jr      l0973
  2641. l096e:
  2642.         ld      a,d
  2643.         inc     a
  2644.         jr      z,l098b
  2645.         ld      c,a
  2646. l0973:
  2647.         ld      a,b
  2648.         sub     c
  2649.         inc     a
  2650.         cp      e
  2651.         jr      c,l097a
  2652.         ld      a,e
  2653. l097a:
  2654.         or      a
  2655.         jr      z,l098b
  2656.         ld      hl,(l00e8)      ; Get sub_string pointer
  2657.         ld      b,0
  2658.         add     hl,bc
  2659.         ex      de,hl
  2660.         ld      hl,1
  2661.         add     hl,sp
  2662.         ld      c,a
  2663.         ldir                    ; move
  2664. l098b:
  2665.         ld      hl,0
  2666.         ld      d,h
  2667.         add     hl,sp           ; Fix stack
  2668.         ld      e,(hl)
  2669.         inc     de
  2670.         add     hl,de
  2671.         ld      sp,hl           ; Set stack
  2672.         jp      (ix)            ; Exit
  2673. ;
  2674. ; Check assignment of string to character
  2675. ; EXIT  Reg L holds character
  2676. ;
  2677. l0996:
  2678.         pop     ix              ; Get caller
  2679.         pop     hl              ; Get length and character
  2680.         dec     l               ; Verify character only
  2681.         jp      nz,l0866        ; Error if not
  2682.         ld      l,h             ; Unpack character
  2683.         ld      h,0
  2684.         jp      (ix)            ; Exit
  2685. ;
  2686. ; Set character into string
  2687. ;
  2688. l09a2:
  2689.         ld      hl,2
  2690.         ld      d,h
  2691.         add     hl,sp           ; Point to string
  2692.         ld      e,(hl)          ; Get length
  2693.         inc     de
  2694.         add     hl,de           ; Point to top
  2695.         ld      a,(hl)          ; Get character
  2696.         ld      (hl),1          ; Set length
  2697.         inc     hl
  2698.         ld      (hl),a          ; Store character
  2699.         ret
  2700. ;
  2701. ; Compare two strings
  2702. ; ENTRY 1st stack 1st pushed, 2nd stack 2nd pushed
  2703. ; EXIT  Carry flag set if 1st<2nd
  2704. ;       Zero  flag set if 1st=2nd
  2705. ;
  2706. l09b0:
  2707.         ld      hl,2*2          ; Note 2nd level call
  2708.         ld      d,h
  2709.         add     hl,sp           ; Point to 2nd string
  2710.         ld      e,(hl)          ; Get length
  2711.         ld      c,e
  2712.         inc     hl
  2713.         push    hl
  2714.         add     hl,de           ; Point to first string
  2715.         ld      e,(hl)          ; Get length
  2716.         ld      b,e
  2717.         inc     hl
  2718.         push    hl
  2719.         add     hl,de           ; Set return stack
  2720.         push    hl
  2721.         pop     iy              ; Copy into reg IY
  2722.         pop     de              ; Get 1st string
  2723.         pop     hl              ; Get 2nd string
  2724. l09c4:
  2725.         xor     a               ; Try zero length
  2726.         cp      b
  2727.         jr      z,l09cc
  2728.         cp      c               ; Test on both
  2729.         jr      nz,l09d3
  2730.         ld      a,b
  2731. l09cc:
  2732.         cp      c
  2733. l09cd:
  2734.         pop     hl              ; Get back callers
  2735.         pop     de
  2736.         ld      sp,iy           ; Set new stack
  2737.         push    de              ; Set 2nd kevel caller
  2738.         jp      (hl)            ; Exit
  2739. l09d3:
  2740.         ld      a,(de)
  2741.         cp      (hl)            ; Compare
  2742.         jr      nz,l09cd        ; No match
  2743.         inc     hl
  2744.         inc     de
  2745.         dec     b
  2746.         dec     c
  2747.         jr      l09c4
  2748. ;
  2749. ; Verify value in reg HL in range 1..255
  2750. ;
  2751. l09dd:
  2752.         ld      a,h             ; Verify < 256
  2753.         or      a
  2754.         jr      nz,l09e4
  2755.         ld      a,l
  2756.         or      a               ; Verify <> 0
  2757.         ret     nz
  2758. l09e4:
  2759.         ld      a,_StrIdx
  2760.         jp      l2029
  2761. ;
  2762. ; Function ADD:real
  2763. ; ENTRY Regs (HL,DE,BC)  hold 1st number
  2764. ;       Regs (HL,DE,BC)' hold 2nd number
  2765. ; EXIT  Regs (HL,DE,BC)  hold sum
  2766. ;
  2767. l09e9:
  2768.         call    l0a0d           ; Add
  2769. l09ec:
  2770.         ret     nc              ; Check result
  2771.         ld      a,_FLPovfl
  2772.         jp      l2027           ; Set error and abort
  2773. ;
  2774. ; Function SUBTRACT:real
  2775. ; ENTRY Regs (HL,DE,BC)  hold 1st number
  2776. ;       Regs (HL,DE,BC)' hold 2nd number
  2777. ; EXIT  Regs (HL,DE,BC)  hold difference
  2778. ;
  2779. l09f2:
  2780.         call    l0a81           ; Subtract
  2781.         jr      l09ec           ; Check result
  2782. ;
  2783. ; Function SQR(real):real
  2784. ; ENTRY Regs (HL,DE,BC) hold number
  2785. ; EXIT  Regs (HL,DE,BC) hold square
  2786. ;
  2787. l09f7:
  2788.         call    l0fac           ; Copy number, then multiply
  2789. ;
  2790. ; Function MULTIPLY:real
  2791. ; ENTRY Regs (HL,DE,BC)  hold multiplicand
  2792. ;       Regs (HL,DE,BC)' hold multiplier
  2793. ; EXIT  Regs (HL,DE,BC)  hold product
  2794. ;
  2795. l09fa:
  2796.         call    l0a97           ; Multiply
  2797.         jr      l09ec           ; Check result
  2798. ;
  2799. ; Function DIVIDE:real
  2800. ; ENTRY Regs (HL,DE,BC)  hold 1st dividend
  2801. ;       Regs (HL,DE,BC)' hold 2nd divisor
  2802. ; EXIT  Regs (HL,DE,BC)  hold quotient
  2803. ;
  2804. l09ff:
  2805.         exx                     ; Get divisor
  2806.         ld      a,l
  2807.         or      a               ; Verify not zero
  2808.         exx
  2809. l0a03:
  2810.         ld      a,_DivZero
  2811.         jp      z,l2027         ; Error if division by zero
  2812.         call    l0af5           ; Divide
  2813.         jr      l09ec           ; Check result
  2814. ;
  2815. ; Add reals
  2816. ; ENTRY Regs (HL,DE,BC)  hold 1st number
  2817. ;       Regs (HL,DE,BC)' hold 2nd number
  2818. ; EXIT  Regs (HL,DE,BC)  hold sum
  2819. ;       Carry set on overflow
  2820. ;
  2821. l0a0d:
  2822.         exx
  2823.         bit     sgn.bit,b       ; Test sign of 2nd number
  2824.         exx
  2825.         jp      nz,l0a88        ; Subtract if less 0
  2826. l0a14:
  2827.         exx
  2828.         ld      a,l             ; Test 2nd number zero
  2829.         or      a
  2830.         exx
  2831.         ret     z               ; Ok, result is the 1st number
  2832.         exx
  2833.         push    bc              ; Save 1st number
  2834.         push    de
  2835.         push    hl
  2836.         exx
  2837.         ld      a,l
  2838.         or      a               ; Test 1st number zero
  2839.         jr      nz,l0a27        ; Nope
  2840.         exx
  2841.         res     sgn.bit,b       ; Clear sign
  2842.         jr      l0a7b           ; Get 2nd number as result
  2843. l0a27:
  2844.         push    bc
  2845.         set     sgn.bit,b       ; Force bit set
  2846.         xor     a
  2847.         ex      af,af'
  2848.         exx
  2849.         set     sgn.bit,b
  2850.         ld      a,l
  2851.         exx
  2852.         sub     l               ; Test same exponents
  2853.         jr      z,l0a47         ; Yeap
  2854.         jr      nc,l0a3c
  2855.         neg
  2856.         ex      af,af'
  2857.         dec     a
  2858.         ex      af,af'
  2859.         exx
  2860. l0a3c:
  2861.         call    l0b7a           ; Shift mantissa right
  2862.         inc     l               ; Bump exponent
  2863.         dec     a
  2864.         jr      nz,l0a3c
  2865.         ex      af,af'
  2866.         jr      z,l0a47
  2867.         exx
  2868. l0a47:
  2869.         pop     af              ; Get back mantissa MSB
  2870.         and     sign.bit        ; Test sign
  2871.         jr      nz,l0a5b        ; It's negative
  2872.         call    l0b92           ; Add mantissas
  2873.         jr      nc,l0a76        ; Test bit out
  2874.         call    l0b7b           ; Rotate mantissa right
  2875.         or      a
  2876.         inc     l               ; Fix exponent
  2877.         jr      nz,l0a76        ; Test underflow
  2878.         scf
  2879.         jr      l0a7b
  2880. l0a5b:
  2881.         call    l0bc6           ; Compare mantissas
  2882.         ccf
  2883.         push    af
  2884.         jr      z,l0a72         ; It's same
  2885.         jr      c,l0a65         ; It's less
  2886.         exx
  2887. l0a65:
  2888.         call    l0bac           ; Subtract mantissas
  2889. l0a68:
  2890.         bit     sgn.bit,b       ; Test normalized
  2891.         jr      nz,l0a75        ; Yeap
  2892.         call    l0b86           ; Shift left
  2893.         dec     l
  2894.         jr      nz,l0a68
  2895. l0a72:
  2896.         call    l0b72           ; Zero result
  2897. l0a75:
  2898.         pop     af
  2899. l0a76:
  2900.         jr      c,l0a7a         ; Test sign
  2901.         res     sgn.bit,b       ; Reset if positive
  2902. l0a7a:
  2903.         or      a
  2904. l0a7b:
  2905.         exx
  2906.         pop     hl
  2907.         pop     de
  2908.         pop     bc
  2909.         exx
  2910.         ret
  2911. ;
  2912. ; Subtract reals
  2913. ; ENTRY Regs (HL,DE,BC)  hold 1st number
  2914. ;       Regs (HL,DE,BC)' hold 2nd number
  2915. ; EXIT  Regs (HL,DE,BC)  hold difference
  2916. ;       Carry set on overflow
  2917. ;
  2918. l0a81:
  2919.         exx
  2920.         bit     sgn.bit,b       ; Test sign of 2nd number
  2921.         exx
  2922.         jp      nz,l0a14        ; Add if less 0
  2923. l0a88:
  2924.         call    l0a8f           ; Negate
  2925.         call    l0a14           ; Then add
  2926.         ret     c
  2927. ;
  2928. ; Negate real
  2929. ; ENTRY Regs HL,DE,BC hold real number
  2930. ; EXIT  Sign changed if real > 0
  2931. ;
  2932. l0a8f:
  2933.         inc     l               ; Test exponent zero
  2934.         dec     l
  2935.         ret     z               ; Exit if so
  2936.         ld      a,b
  2937.         xor     sign.bit        ; Change sign bit
  2938.         ld      b,a
  2939.         ret
  2940. ;
  2941. ; Multiply reals
  2942. ; ENTRY Regs (HL,DE,BC)  hold multiplicand
  2943. ;       Regs (HL,DE,BC)' hold multiplier
  2944. ; EXIT  Regs (HL,DE,BC)  hold product
  2945. ;       Carry set on overflow
  2946. ;
  2947. l0a97:
  2948.         exx
  2949.         ld      a,l
  2950.         or      a               ; Test zero multiplier
  2951.         exx
  2952.         jp      z,l0b72         ; Return 0.0 if so
  2953.         ld      a,l
  2954.         or      a
  2955.         ret     z               ; Return if multiplicand zero
  2956.         exx
  2957.         add     a,l             ; Add exponents
  2958.         exx
  2959.         call    l0b4d           ; Fix exponent
  2960.         push    bc              ; Save number
  2961.         push    de
  2962.         push    hl
  2963.         add     ix,sp
  2964.         call    l0b72           ; Prepare result
  2965.         exx
  2966.         ld      l,mant.len      ; Set mantissa count
  2967.         exx
  2968. l0ab3:
  2969.         ld      a,bit.len       ; Set bit count
  2970.         inc     ix
  2971.         ld      l,(ix+0)
  2972. l0aba:
  2973.         ex      af,af'
  2974.         rr      l               ; Shift bit
  2975.         jr      nc,l0ac2
  2976.         call    l0b92           ; Add mantissa if bit out
  2977. l0ac2:
  2978.         call    l0b7b           ; Rotate mantissa right
  2979.         ex      af,af'
  2980.         dec     a               ; Go thru all bits
  2981.         jr      nz,l0aba
  2982.         exx
  2983.         dec     l
  2984.         exx
  2985.         jr      nz,l0ab3
  2986.         ld      l,(ix-mant.len) ; Get byte back
  2987.         bit     sgn.bit,b       ; Test sign
  2988.         jr      nz,l0ade
  2989.         ex      af,af'
  2990.         call    l0b87           ; Get bit
  2991.         inc     l
  2992.         dec     l
  2993.         jr      z,l0ade
  2994.         dec     l
  2995. l0ade:
  2996.         pop     af              ; Clean stack
  2997.         pop     af
  2998.         pop     af
  2999. l0ae1:
  3000.         or      a
  3001. l0ae2:
  3002.         ex      af,af'
  3003.         pop     af
  3004.         exx
  3005.         pop     bc
  3006.         pop     hl
  3007.         exx
  3008.         pop     ix
  3009.         res     sgn.bit,b       ; Reset hi bit
  3010.         or      b
  3011.         ld      b,a             ; Insert sign
  3012.         inc     l
  3013.         dec     l
  3014.         call    z,l0b72         ; Clear if underflow
  3015.         ex      af,af'
  3016.         ret
  3017. ;
  3018. ; Divide reals
  3019. ; ENTRY Regs (HL,DE,BC)  hold 1st dividend
  3020. ;       Regs (HL,DE,BC)' hold 2nd divisor
  3021. ; EXIT  Regs (HL,DE,BC)  hold quotient
  3022. ;       Carry set on overflow
  3023. ;
  3024. l0af5:
  3025.         ld      a,l
  3026.         or      a               ; Test zero divisor
  3027.         ret     z
  3028.         exx
  3029.         sub     l               ; Get resulting exponent
  3030.         exx
  3031.         ccf
  3032.         call    l0b4d           ; Fix it
  3033.         push    hl
  3034.         push    hl
  3035.         push    hl
  3036.         add     ix,sp
  3037.         exx
  3038.         ld      l,mant.len      ; Get complete count
  3039.         exx
  3040.         ld      a,bit.len       ; Set bit count
  3041. l0b0a:
  3042.         ex      af,af'
  3043.         call    l0bc6           ; Compare mantissas
  3044.         jr      c,l0b13
  3045.         call    l0bac           ; Subtract mantissas
  3046. l0b13:
  3047.         ccf
  3048.         rl      l
  3049.         ex      af,af'
  3050.         dec     a               ; Go thru the bits
  3051.         jr      nz,l0b26
  3052.         ld      (ix+mant.len),l ; Set result
  3053.         dec     ix
  3054.         exx
  3055.         dec     l               ; Go thru the mantissa
  3056.         exx
  3057.         jr      z,l0b32         ; Total end
  3058.         ld      a,bit.len       ; Reset bit count
  3059. l0b26:
  3060.         call    l0b86           ; Shift left
  3061.         jr      nc,l0b0a
  3062.         ex      af,af'
  3063.         call    l0bac           ; Subtract mantissas
  3064.         or      a
  3065.         jr      l0b13
  3066. l0b32:
  3067.         call    l0b86           ; Shift left
  3068.         jr      c,l0b3b
  3069.         call    l0bc6           ; Compare mantissas
  3070.         ccf
  3071. l0b3b:
  3072.         pop     hl
  3073.         pop     de
  3074.         pop     bc
  3075.         bit     sgn.bit,b       ; Test bit
  3076.         jr      nz,l0b47
  3077.         call    l0b87           ; Shift in
  3078.         jr      l0ae1
  3079. l0b47:
  3080.         inc     l               ; Test ok
  3081.         jr      nz,l0ae1
  3082.         scf
  3083.         jr      l0ae2
  3084. ;
  3085. ; Fix exponent
  3086. ; ENTRY Accu and Carry reflect state of addition or
  3087. ;       subtraction of exponents
  3088. ;
  3089. l0b4d:
  3090.         jr      c,l0b55         ; Test bit out
  3091.         add     a,exp.offset    ; Add offset
  3092.         jr      c,l0b59         ; Test bit
  3093.         jr      l0b70
  3094. l0b55:
  3095.         add     a,exp.offset
  3096.         jr      c,l0b70
  3097. l0b59:
  3098.         ld      l,a             ; Set new exponent
  3099.         ex      (sp),ix         ; Get caller
  3100.         exx
  3101.         push    hl
  3102.         push    bc
  3103.         ld      a,b
  3104.         set     sgn.bit,b       ; Set bit
  3105.         exx
  3106.         xor     b
  3107.         and     sign.bit        ; Get result
  3108.         push    af
  3109.         set     sgn.bit,b       ; Second, too
  3110.         push    ix              ; Bring back caller
  3111.         ld      ix,0            ; Return IX=0
  3112.         ret
  3113. l0b70:
  3114.         pop     hl
  3115.         ret     c
  3116. ;
  3117. ; Clear real number
  3118. ; EXIT  Regs (HL,DE,BC) hold zero
  3119. ;
  3120. l0b72:
  3121.         xor     a
  3122.         ld      l,a             ; Clear all involved bytes
  3123.         ld      b,a
  3124.         ld      c,a
  3125.         ld      d,a
  3126.         ld      e,a
  3127.         ld      h,a
  3128.         ret
  3129. ;
  3130. ; Shift mantissa right
  3131. ;
  3132. l0b7a:
  3133.         or      a               ; Clear carry
  3134. ;
  3135. ; Rotate mantissa right
  3136. ;
  3137. l0b7b:
  3138.         rr      b               ; Shift 5 bytes right
  3139.         rr      c
  3140.         rr      d
  3141.         rr      e
  3142.         rr      h
  3143.         ret
  3144. ;
  3145. ; Shift mantissa left
  3146. ;
  3147. l0b86:
  3148.         or      a               ; Clear carry
  3149. ;
  3150. ; Rotate mantissa left
  3151. ;
  3152. l0b87:
  3153.         rl      h               ; Shift 5 bytes left
  3154.         rl      e
  3155.         rl      d
  3156.         rl      c
  3157.         rl      b
  3158.         ret
  3159. ;
  3160. ; Add mantissas
  3161. ;
  3162. l0b92:
  3163.         ld      a,h             ; Get 1st
  3164.         exx                     ; Then second
  3165.         add     a,h             ; Add
  3166.         exx
  3167.         ld      h,a             ; Into 1st
  3168.         ld      a,e
  3169.         exx
  3170.         adc     a,e
  3171.         exx
  3172.         ld      e,a
  3173.         ld      a,d
  3174.         exx
  3175.         adc     a,d
  3176.         exx
  3177.         ld      d,a
  3178.         ld      a,c
  3179.         exx
  3180.         adc     a,c
  3181.         exx
  3182.         ld      c,a
  3183.         ld      a,b
  3184.         exx
  3185.         adc     a,b
  3186.         exx
  3187.         ld      b,a
  3188.         ret
  3189. ;
  3190. ; Subtract mantissas
  3191. ;
  3192. l0bac:
  3193.         ld      a,h             ; Get 1st
  3194.         exx                     ; Then second
  3195.         sub     h               ; Subtract
  3196.         exx
  3197.         ld      h,a             ; Into 1st
  3198.         ld      a,e
  3199.         exx
  3200.         sbc     a,e
  3201.         exx
  3202.         ld      e,a
  3203.         ld      a,d
  3204.         exx
  3205.         sbc     a,d
  3206.         exx
  3207.         ld      d,a
  3208.         ld      a,c
  3209.         exx
  3210.         sbc     a,c
  3211.         exx
  3212.         ld      c,a
  3213.         ld      a,b
  3214.         exx
  3215.         sbc     a,b
  3216.         exx
  3217.         ld      b,a
  3218.         ret
  3219. ;
  3220. ; Compare mantissas
  3221. ;
  3222. l0bc6:
  3223.         ld      a,b             ; Get 1st
  3224.         exx                     ; Then second
  3225.         cp      b               ; Compare
  3226.         exx
  3227.         ret     nz              ; Exit if .NE. zero
  3228.         ld      a,c
  3229.         exx
  3230.         cp      c
  3231.         exx
  3232.         ret     nz
  3233.         ld      a,d
  3234.         exx
  3235.         cp      d
  3236.         exx
  3237.         ret     nz
  3238.         ld      a,e
  3239.         exx
  3240.         cp      e
  3241.         exx
  3242.         ret     nz
  3243.         ld      a,h
  3244.         exx
  3245.         cp      h
  3246.         exx
  3247.         ret
  3248. ;
  3249. ; Compare two reals
  3250. ; ENTRY 1st real in register set
  3251. ;       2nd real in alternative set
  3252. ; EXIT  Carry flag set if 1st<2nd
  3253. ;       Zero  flag set if 1st=2nd
  3254. ;
  3255. l0bdf:
  3256.         exx
  3257.         ld      a,b             ; Get sign
  3258.         exx
  3259.         xor     b               ; Test same signs
  3260.         jp      p,l0be9         ; Yeap
  3261.         ld      a,b             ; Get 1st sign
  3262.         rla                     ; Calculate result
  3263.         ret
  3264. l0be9:
  3265.         bit     sgn.bit,b       ; Test 1st > 0
  3266.         jr      z,l0bf3         ; Yeap
  3267.         call    l0bf3           ; Compare
  3268.         ret     z
  3269.         ccf
  3270.         ret
  3271. l0bf3:
  3272.         ld      a,l             ; Get exponent
  3273.         exx
  3274.         cp      l               ; Compare
  3275.         exx
  3276.         ret     nz              ; Not same
  3277.         or      a               ; Test zero
  3278.         ret     z
  3279.         jp      l0bc6           ; Compare mantissas
  3280. ;
  3281. ; Function INT(real):real
  3282. ;
  3283. l0bfd:
  3284.         ld      a,l
  3285.         sub     Exp.One         ; Test >= 1
  3286.         jp      c,l0b72         ; Nope, return 0.0
  3287.         inc     a               ; Fix count
  3288.         cp      mant.bits       ; Test fraction
  3289.         ret     nc              ; No, that's it
  3290.         exx
  3291.         push    bc              ; save 2nd
  3292.         push    de
  3293.         push    hl
  3294.         ex      af,af'
  3295.         call    l0b72           ; Init result
  3296.         ex      af,af'
  3297. l0c10:
  3298.         scf
  3299.         call    l0b7b           ; Rotate mantissa right
  3300.         dec     a
  3301.         jr      nz,l0c10
  3302.         exx
  3303.         ld      a,h             ; Mask result
  3304.         exx
  3305.         and     h
  3306.         exx
  3307.         ld      h,a
  3308.         ld      a,e
  3309.         exx
  3310.         and     e
  3311.         exx
  3312.         ld      e,a
  3313.         ld      a,d
  3314.         exx
  3315.         and     d
  3316.         exx
  3317.         ld      d,a
  3318.         ld      a,c
  3319.         exx
  3320.         and     c
  3321.         exx
  3322.         ld      c,a
  3323.         ld      a,b
  3324.         exx
  3325.         and     b
  3326.         exx
  3327.         ld      b,a
  3328. l0c31:
  3329.         jp      l0a7b
  3330. ;
  3331. ; Function FRAC(real):real
  3332. ;
  3333. l0c34:
  3334.         exx
  3335.         push    bc
  3336.         push    de
  3337.         push    hl
  3338.         exx
  3339.         call    l0fac           ; Copy number
  3340.         exx
  3341.         call    l0bfd           ; Get integer part
  3342.         exx
  3343.         call    l0a81           ; Subtract from original number
  3344.         jr      l0c31
  3345. ;
  3346. ; Function SQRT(real):real
  3347. ;
  3348. l0c46:
  3349.         ld      a,l             ; Test zero operand
  3350.         or      a
  3351.         ret     z               ; Ok, that's it
  3352.         bit     sgn.bit,b       ; Verify operand >= 0
  3353.         ld      a,_NegSqrt
  3354.         jp      nz,l2027        ; Should be
  3355.         call    l0fac           ; Copy number
  3356.         ld      a,l
  3357.         add     a,exp.offset
  3358.         sra     a               ; Fix resulting exponent
  3359.         add     a,exp.offset
  3360.         ld      l,a
  3361.         sub     sqr.exp         ; Fix exponent
  3362.         push    af
  3363.         exx
  3364. l0c5f:
  3365.         push    bc
  3366.         push    de
  3367.         push    hl
  3368.         call    l0af5           ; Divide reals
  3369.         call    l0a0d           ; Add reals
  3370.         dec     l               ; Exponent - 1
  3371.         push    bc
  3372.         push    de
  3373.         push    hl
  3374.         call    l0a81           ; Subtract reals
  3375.         ld      a,l
  3376.         pop     hl
  3377.         pop     de
  3378.         pop     bc
  3379.         exx
  3380.         pop     hl
  3381.         pop     de
  3382.         pop     bc
  3383.         ex      (sp),hl
  3384.         cp      h               ; Test ready
  3385.         ex      (sp),hl
  3386.         jr      nc,l0c5f        ; Loop on
  3387.         pop     af
  3388.         exx
  3389.         ret
  3390. ;
  3391. ; Function COS(real):real
  3392. ;
  3393. l0c7f:
  3394.         exx
  3395.         call    l0f8e           ; Load constant PI
  3396.         dec     l               ; Make 90 degrees
  3397.         call    l0a81           ; Subtract reals
  3398. ;
  3399. ; Function SIN(real):real
  3400. ;
  3401. l0c87:
  3402.         exx
  3403.         call    l0f8e           ; Load constant PI
  3404.         inc     l               ; Make 360 degrees
  3405.         exx
  3406.         ld      a,l
  3407.         cp      sin.min         ; Test underflow
  3408.         ret     c
  3409.         push    bc
  3410.         res     sgn.bit,b       ; Clear sign
  3411.         call    l0bdf           ; Compare against period
  3412.         pop     bc
  3413.         jr      c,l0ca3
  3414.         call    l0af5           ; Divide reals
  3415.         call    l0c34           ; Get fraction
  3416.         call    l0a97           ; Multiply reals
  3417. l0ca3:
  3418.         bit     sgn.bit,b       ; Test sign
  3419.         jr      z,l0caa
  3420.         call    l0a0d           ; Add reals
  3421. l0caa:
  3422.         exx
  3423.         dec     l               ; Make 180 degrees
  3424.         exx
  3425.         call    l0bdf           ; Test within 180 degrees
  3426.         push    af
  3427.         jr      c,l0cb6
  3428.         call    l0a81           ; Subtract reals
  3429. l0cb6:
  3430.         exx
  3431.         dec     l               ; Make 90 degrees
  3432.         exx
  3433.         call    l0bdf           ; Test within 90 degrees
  3434.         jr      c,l0cc3
  3435.         exx
  3436.         inc     l               ; Make 180 degrees
  3437.         call    l0a81           ; Subtract reals
  3438. l0cc3:
  3439.         ld      a,l
  3440.         cp      sin.min         ; Test underflow
  3441.         jr      c,l0d03
  3442.         exx
  3443.         ld      bc,02aaah       ; Set 1/3
  3444.         ld      de,0aaaah
  3445.         ld      hl,0aa7fh
  3446.         call    l0a97           ; Multiply reals (Divide by 3)
  3447.         push    ix
  3448.         ld      ix,l0d0d-Real.Len
  3449.         ld      a,Trg.Len
  3450.         call    l0f34           ; Do the TAYLOR loop
  3451.         pop     ix
  3452.         call    l0fac           ; Copy number
  3453.         call    l0a97           ; Multiply reals
  3454.         call    l0a97           ; Multiply reals
  3455.         push    bc
  3456.         push    de
  3457.         push    hl
  3458.         exx
  3459.         call    l0fac           ; Copy number
  3460.         dec     l               ; Divide by 4
  3461.         dec     l
  3462.         exx
  3463.         dec     l               ; Divide by 2
  3464.         call    l0a0d           ; Add reals
  3465.         exx
  3466.         pop     hl
  3467.         pop     de
  3468.         pop     bc
  3469.         exx
  3470.         call    l0a81           ; Subtract reals
  3471.         inc     l               ; Multiply by 4
  3472.         inc     l
  3473. l0d03:
  3474.         pop     af
  3475.         inc     l               ; Test zero
  3476.         dec     l
  3477.         ret     z
  3478.         ret     c               ; Check sign
  3479.         ld      a,b
  3480.         xor     sign.bit        ; Toggle it
  3481.         ld      b,a
  3482.         ret
  3483. ;
  3484. ; Taylor series for SINE and COSINE
  3485. ;
  3486. l0d0d:
  3487.         db      067h,0aah,03fh,02bh,032h,0d7h   ; -1/11!
  3488.         db      06eh,0b6h,02ah,01dh,0efh,038h   ;  1/9!
  3489.         db      074h,00dh,0d0h,000h,00dh,0d0h   ; -1/7!
  3490.         db      07ah,088h,088h,088h,088h,008h   ;  1/5!
  3491.         db      07eh,0abh,0aah,0aah,0aah,0aah   ; -1/3!
  3492. Trg.Len equ     ($-l0d0d)/Real.Len
  3493. ;
  3494. ; Function LN(real):real
  3495. ;
  3496. l0d2b:
  3497.         inc     l
  3498.         dec     l               ; Check zero
  3499.         ld      a,_LNerr
  3500.         jp      z,l2027         ; Error if so
  3501.         bit     sgn.bit,b
  3502.         jp      nz,l2027        ; If negative, too
  3503.         exx
  3504.         call    l0f98           ; Load constant SQRT(2)
  3505.         exx
  3506.         ld      a,l
  3507.         ld      l,Exp.One       ; Fix exponent
  3508.         sub     l
  3509.         push    af
  3510.         call    l0af5           ; Divide reals
  3511.         exx
  3512.         call    l0f86           ; Load constant 1.0
  3513.         exx
  3514.         call    l0a81           ; Subtract reals
  3515.         push    bc
  3516.         push    de
  3517.         push    hl
  3518.         exx
  3519.         inc     l               ; Number times 2
  3520.         call    l0a0d           ; Add reals
  3521.         exx
  3522.         pop     hl
  3523.         pop     de
  3524.         pop     bc
  3525.         call    l0af5           ; Divide reals
  3526.         push    ix
  3527.         ld      ix,l0d92-Real.Len
  3528.         ld      a,LN.len
  3529.         call    l0f34           ; Do the TAYLOR loop
  3530.         pop     ix
  3531.         inc     l               ; Number times 2
  3532.         exx
  3533.         call    l0fa2           ; Load constant LN(2)
  3534.         dec     l               ; Halve it
  3535.         exx
  3536.         call    l0a0d           ; Add reals
  3537.         pop     af
  3538.         push    bc
  3539.         push    de
  3540.         push    hl
  3541.         ld      l,a
  3542.         ld      h,0
  3543.         jr      nc,l0d7c
  3544.         dec     h               ; Set -1
  3545. l0d7c:
  3546.         call    l1008           ; Convert to real
  3547.         exx
  3548.         inc     l               ; Number times 2
  3549.         call    l0a97           ; Multiply reals
  3550.         exx
  3551.         pop     hl
  3552.         pop     de
  3553.         pop     bc
  3554.         call    l0a0d           ; Add reals
  3555.         ld      a,l
  3556.         cp      ln.min          ; Test underflow
  3557.         jp      c,l0b72         ; Return 0.0 if so
  3558.         ret
  3559. ;
  3560. ; Taylor series for Natural Logarithm
  3561. ;
  3562. l0d92:
  3563.         db      07dh,08ah,09dh,0d8h,089h,01dh   ; 1/13
  3564.         db      07dh,0e9h,0a2h,08bh,02eh,03ah   ; 1/11
  3565.         db      07dh,08eh,0e3h,038h,08eh,063h   ; 1/9
  3566.         db      07eh,049h,092h,024h,049h,012h   ; 1/7
  3567.         db      07eh,0cdh,0cch,0cch,0cch,04ch   ; 1/5
  3568.         db      07fh,0abh,0aah,0aah,0aah,02ah   ; 1/3
  3569. LN.len  equ     ($-l0d92)/Real.Len
  3570. ;
  3571. ; Function EXP(real):real
  3572. ;
  3573. l0db6:
  3574.         exx
  3575.         call    l0fa2           ; Load constant LN(2)
  3576.         exx
  3577.         or      a
  3578.         bit     sgn.bit,b
  3579.         push    af              ; Save sign
  3580.         res     sgn.bit,b       ; Clear it
  3581.         call    l0af5           ; Divide reals
  3582.         ld      a,l
  3583.         cp      exp.max         ; Test overflow
  3584.         jr      nc,l0e10
  3585.         push    bc
  3586.         push    de
  3587.         push    hl
  3588.         inc     l               ; Times 2
  3589.         call    l0fd0           ; Get integer
  3590.         push    hl
  3591.         srl     h               ; Divide by 2
  3592.         rr      l
  3593.         ld      a,l
  3594.         pop     hl
  3595.         push    af
  3596.         call    l1008           ; Back to real
  3597.         inc     l               ; Test zero
  3598.         dec     l
  3599.         jr      z,l0de0
  3600.         dec     l               ; Fix if not
  3601. l0de0:
  3602.         exx
  3603.         pop     af
  3604.         pop     hl
  3605.         pop     de
  3606.         pop     bc
  3607.         push    af
  3608.         call    l0a81           ; Subtract reals
  3609.         push    ix
  3610.         ld      ix,l0e16-Real.Len
  3611.         ld      a,EXP.Len
  3612.         call    l0f49           ; Do the TAYLOR loop
  3613.         pop     ix
  3614.         pop     af
  3615.         jr      nc,l0e03
  3616.         push    af
  3617.         exx
  3618.         call    l0f98           ; Load constant SQRT(2)
  3619.         exx
  3620.         call    l0a97           ; Multiply reals
  3621.         pop     af
  3622. l0e03:
  3623.         add     a,l             ; Build resulting exponent
  3624.         ld      l,a
  3625.         jr      c,l0e10         ; Overflow
  3626.         pop     af              ; Test sign
  3627.         ret     z
  3628.         exx
  3629.         call    l0f86           ; Load constant 1.0
  3630.         jp      l0af5           ; Divide reals (1/number)
  3631. l0e10:
  3632.         pop     hl
  3633.         ld      a,_FLPovfl      ; Error
  3634.         jp      l2027
  3635. ;
  3636. ; Taylor series for natural EXPonetiation
  3637. ;
  3638. l0e16:
  3639.         db      06dh,02eh,01dh,011h,060h,031h   ; 1.3215 E-6
  3640.         db      070h,046h,02ch,0feh,0e5h,07fh   ; 1.5252 E-5
  3641.         db      074h,036h,07ch,089h,084h,021h   ; 1.5403 E-4
  3642.         db      077h,053h,03ch,0ffh,0c3h,02eh   ; 1.3333 E-3
  3643.         db      07ah,0d2h,07dh,05bh,095h,01dh   ; 9.6181 E-3
  3644.         db      07ch,025h,0b8h,046h,058h,063h   ; 5.5504 E-2
  3645.         db      07eh,016h,0fch,0efh,0fdh,075h   ; 2.4022 E-1
  3646.         db      080h,0d2h,0f7h,017h,072h,031h   ; 6.9314 E-1
  3647. EXP.Len equ     ($-l0e16)/Real.Len
  3648. ;
  3649. ; Function ARCTAN(real):real
  3650. ;
  3651. l0e46:
  3652.         ld      a,l
  3653.         or      a               ; Test zero
  3654.         ret     z
  3655.         push    ix
  3656.         exx
  3657.         call    l0f86           ; Load constant 1.0
  3658.         exx
  3659.         xor     a
  3660.         bit     sgn.bit,b       ; Test sign
  3661.         jr      z,l0e58
  3662.         inc     a
  3663.         res     sgn.bit,b       ; Make absolute
  3664. l0e58:
  3665.         push    af
  3666.         call    l0bdf           ; Compare against 1.0
  3667.         jr      c,l0e66
  3668.         exx
  3669.         call    l0af5           ; Divide reals (1/number)
  3670.         pop     af
  3671.         set     sgn.bit,a       ; Indicate reverse
  3672.         push    af
  3673. l0e66:
  3674.         exx
  3675.         ld      bc,006cfh       ; Load 0.13165
  3676.         ld      de,0e98eh
  3677.         ld      hl,04a7eh
  3678.         exx
  3679.         call    l0bdf           ; Compare reals
  3680.         jr      nc,l0e7b
  3681.         call    l0f2e           ; Build TAYLOR series
  3682.         jr      l0eca
  3683. l0e7b:
  3684.         ld      ix,l0ee0-3*Real.Len
  3685.         ld      a,2             ; Set loop
  3686. l0e81:
  3687.         ex      af,af'
  3688.         exx
  3689.         ld      de,3*Real.Len
  3690.         add     ix,de
  3691.         call    l0f73           ; Get value from table
  3692.         exx
  3693.         call    l0bdf           ; Compare reals
  3694.         jr      c,l0e9c
  3695.         ex      af,af'
  3696.         dec     a               ; Go thru the loop
  3697.         jr      nz,l0e81
  3698.         exx
  3699.         ld      de,2*Real.Len
  3700.         add     ix,de           ; Fix table
  3701.         exx
  3702. l0e9c:
  3703.         exx
  3704.         call    l0f6e           ; Get next from table
  3705.         set     sgn.bit,b       ; Make negative
  3706.         call    l0a0d           ; Add reals
  3707.         push    bc
  3708.         push    de
  3709.         push    hl
  3710.         call    l0f73           ; Get value back
  3711.         call    l0a97           ; Multiply reals
  3712.         exx
  3713.         call    l0f86           ; Load constant 1.0
  3714.         call    l0a0d           ; Add reals
  3715.         exx
  3716.         pop     hl
  3717.         pop     de
  3718.         pop     bc
  3719.         call    l0af5           ; Divide reals
  3720.         push    ix
  3721.         call    l0f2e           ; Do TAYLOR
  3722.         pop     ix
  3723.         exx
  3724.         call    l0f6e           ; Get from table
  3725.         call    l0a0d           ; Add reals
  3726. l0eca:
  3727.         pop     af
  3728.         rla                     ; Get sign bit
  3729.         jr      nc,l0ed8
  3730.         push    af
  3731.         exx
  3732.         call    l0f8e           ; Load constant PI
  3733.         dec     l               ; Make 90 degrees
  3734.         call    l0a81           ; Subtract reals
  3735.         pop     af
  3736. l0ed8:
  3737.         pop     ix
  3738.         bit     1,a             ; Test operand sign
  3739.         ret     z
  3740.         set     sgn.bit,b       ; Set negative
  3741.         ret
  3742. ;
  3743. ; 2nd Taylor series for ARCTangent
  3744. ;
  3745. l0ee0:
  3746.         db      07fh,0e7h,0cfh,0cch,013h,054h   ; 4.1421 E-1
  3747.         db      07fh,0f6h,0f4h,0a2h,030h,009h   ; 2.6794 E-1
  3748.         db      07fh,06ah,0c1h,091h,00ah,006h   ; 2.6179 E-1
  3749.         db      080h,0b5h,09eh,08ah,06fh,044h   ; 7.6732 E-1
  3750.         db      080h,082h,02ch,03ah,0cdh,013h   ; 5.7735 E-1
  3751.         db      080h,06ah,0c1h,091h,00ah,006h   ; 5.2359 E-1
  3752.         db      081h,000h,000h,000h,000h,000h   ; 1.0000
  3753.         db      080h,021h,0a2h,0dah,00fh,049h   ; 7.8539 E-1
  3754. ;
  3755. ; Taylor series for ARCTangent
  3756. ;
  3757. l0f10:
  3758.         db      07dh,0e8h,0a2h,08bh,02eh,0bah   ; -1/11
  3759.         db      07dh,08eh,0e3h,038h,08eh,063h   ;  1/9
  3760.         db      07eh,049h,092h,024h,049h,092h   ; -1/7
  3761.         db      07eh,0cdh,0cch,0cch,0cch,04ch   ;  1/5
  3762.         db      07fh,0abh,0aah,0aah,0aah,0aah   ; -1/3
  3763. AT.Len  equ     ($-l0f10)/Real.Len
  3764. ;
  3765. ; Perform TAYLOR series
  3766. ; Calculate SERIES(x^2)*x
  3767. ;
  3768. l0f2e:
  3769.         ld      ix,l0f10-Real.Len
  3770.         ld      a,AT.Len
  3771. l0f34:
  3772.         push    bc
  3773.         push    de
  3774.         push    hl
  3775.         push    af
  3776.         call    l0fac           ; Copy number
  3777.         call    l0a97           ; Multiply reals [^2]
  3778.         pop     af
  3779.         call    l0f49           ; Do the TAYLOR loop
  3780.         exx
  3781.         pop     hl
  3782.         pop     de
  3783.         pop     bc
  3784.         jp      l0a97           ; Multiply reals
  3785. ;
  3786. ; The TAYLOR series loop
  3787. ; ENTRY Reg IX points to table
  3788. ;       Accu holds loop count
  3789. ; Calculate : 1-(1/3!)x+..+/-..-(1/11!)x^8
  3790. ;
  3791. l0f49:
  3792.         push    af
  3793.         exx
  3794.         call    l0f6e           ; Load from table
  3795.         jr      l0f60           ; Skip addition this time
  3796. l0f50:
  3797.         push    af
  3798.         exx
  3799.         push    bc
  3800.         push    de
  3801.         push    hl
  3802.         call    l0f6e           ; Get next value from table
  3803.         call    l0a0d           ; Add reals
  3804.         exx
  3805.         pop     hl
  3806.         pop     de
  3807.         pop     bc
  3808.         exx
  3809. l0f60:
  3810.         call    l0a97           ; Multiply reals
  3811.         pop     af
  3812.         dec     a               ; Test done
  3813.         jr      nz,l0f50        ; Nope
  3814.         exx
  3815.         call    l0f86           ; Load constant 1.0
  3816.         jp      l0a0d           ; Add reals
  3817. ;
  3818. ; Load next real from table
  3819. ; ENTRY Reg IX points to table
  3820. ; EXIT  Regs (HL,DE,BC) hold real
  3821. ;
  3822. l0f6e:
  3823.         ld      de,Real.Len
  3824.         add     ix,de           ; Point to nexr
  3825. ;
  3826. ; Load real from table
  3827. ; ENTRY Reg IX points to table
  3828. ; EXIT  Regs (HL,DE,BC) hold real
  3829. ;
  3830. l0f73:
  3831.         ld      l,(ix+0)        ; Get exponent
  3832.         ld      h,(ix+1)        ; Mantissa LSB
  3833.         ld      e,(ix+2)
  3834.         ld      d,(ix+3)
  3835.         ld      c,(ix+4)
  3836.         ld      b,(ix+5)        ; Mantissa MSB
  3837.         ret
  3838. ;
  3839. ; Load constant 1.0
  3840. ;
  3841. l0f86:
  3842.         ld      hl,Exp.One      ; Load 6 bytes 2^0
  3843.         ld      b,h
  3844.         ld      c,h
  3845.         ld      d,h
  3846.         ld      e,h
  3847.         ret
  3848. ;
  3849. ; Load constant PI=3.141592654
  3850. ;
  3851. l0f8e:
  3852.         ld      bc,0490fh       ; Load 6 bytes
  3853.         ld      de,0daa2h
  3854.         ld      hl,02182h
  3855.         ret
  3856. ;
  3857. ; Load constant SQRT (2)=1.414213562
  3858. ;
  3859. l0f98:
  3860.         ld      bc,03504h       ; Load 6 bytes
  3861.         ld      de,0f333h
  3862.         ld      hl,0fa81h
  3863.         ret
  3864. ;
  3865. ; Load constant LN (2)=0.693147181
  3866. ;
  3867. l0fa2:
  3868.         ld      bc,03172h       ; Load 6 bytes
  3869.         ld      de,017f7h
  3870.         ld      hl,0d280h
  3871.         ret
  3872. ;
  3873. ; Copy real number
  3874. ; ENTRY Regs (HL,DE,BC) hold number
  3875. ; EXIT  Number copied to alternating regs (HL,DE,BC)'
  3876. ;
  3877. l0fac:
  3878.         push    bc              ; Push onto stack
  3879.         push    de
  3880.         push    hl
  3881.         exx                     ; Copy into alternate registers
  3882.         pop     hl              ; Pop back
  3883.         pop     de
  3884.         pop     bc
  3885.         ret
  3886. ;
  3887. ; Function RANDOM:real;
  3888. ; EXIT  Regs (HL,DE,BC) hold number
  3889. ;
  3890. l0fb4:
  3891.         call    l0792           ; Get random value
  3892.         ld      hl,exp.offset   ; Init exponent and count
  3893.         ld      a,mant.bits-bit.len
  3894. l0fbc:
  3895.         bit     sgn.bit,b       ; Test MSB set
  3896.         jr      nz,l0fcd
  3897.         sla     e               ; Shift left if not
  3898.         rl      d
  3899.         rl      c
  3900.         rl      b
  3901.         dec     l               ; Count down exponent
  3902.         dec     a
  3903.         jr      nz,l0fbc
  3904.         ld      l,a
  3905. l0fcd:
  3906.         res     sgn.bit,b       ; .. make 1.0> x >=0.0
  3907.         ret
  3908. ;
  3909. ; Function ROUND(real):integer
  3910. ;
  3911. l0fd0:
  3912.         bit     sgn.bit,b       ; Attache sign
  3913.         exx
  3914.         call    l0f86           ; Load constant 1.0
  3915.         jr      z,l0fda         ; Test < 0
  3916.         set     sgn.bit,b       ; make constant -1.0
  3917. l0fda:
  3918.         dec     l               ; Set +-0.5
  3919.         call    l0a0d           ; Add reals
  3920. ;
  3921. ; Function TRUNC(real):integer
  3922. ;
  3923. l0fde:
  3924.         or      a
  3925.         bit     sgn.bit,l       ; Test exponent < 0
  3926.         jr      z,l0fff         ; Return zero if so
  3927.         bit     sgn.bit,b       ; Mark sign
  3928.         ex      af,af'
  3929.         set     sgn.bit,b       ; Set bit
  3930. l0fe8:
  3931.         ld      a,int.max
  3932.         cp      l
  3933.         jr      c,l1003         ; Test overflow
  3934.         jr      z,l0ff5         ; Or end of conversion
  3935.         call    l0b7a           ; Shift mantissa right
  3936.         inc     l               ; Bump exponent
  3937.         jr      l0fe8
  3938. l0ff5:
  3939.         call    l0b7a           ; Shift mantissa right
  3940.         ex      af,af'
  3941.         ld      h,b             ; Get result
  3942.         ld      l,c
  3943.         ret     z               ; End if > 0
  3944.         jp      l0783           ; Negate
  3945. l0fff:
  3946.         ld      hl,0            ; Return 0
  3947.         ret
  3948. l1003:
  3949.         ld      a,_TruncOvl
  3950.         jp      l2027           ; Set error
  3951. ;
  3952. ; Convert integer to floating point
  3953. ; ENTRY Reg HL holds signed integer
  3954. ; EXIT  Regs (HL,DE,BC) hold real
  3955. ;
  3956. ; NOTE: ON INTEGER 8000H AND ONLY ON THIS NUMBER
  3957. ;       THIS ROUTINE WILL LOOP FOREVER !!!!!!!!
  3958. ;
  3959. l1008:
  3960.         ld      a,h             ; Test Zero
  3961.         or      l
  3962.         jp      z,l0b72         ; Set 0.0 if so
  3963.         bit     sgn.bit,h       ; Test sign
  3964.         ex      af,af'
  3965.         call    l0780           ; Make number positive
  3966.         ld      a,int.max+1     ; Init exponent
  3967. l1015:
  3968.         add     hl,hl           ; Shift mantissa
  3969.         dec     a               ; Fix exponent
  3970.         bit     sgn.bit,h       ; Test ready
  3971.         jr      z,l1015         ; Nope, wait for bit
  3972.         ld      b,h             ; Get into hi part of mantissa
  3973.         ld      c,l
  3974.         ld      de,0            ; Clear lo part
  3975.         ld      h,d
  3976.         ld      l,a
  3977.         ex      af,af'          ; Test sign
  3978.         ret     nz
  3979.         res     sgn.bit,b       ; Set > 0
  3980.         ret
  3981. ;
  3982. ; Convert real to formatted ASCII string
  3983. ; ENTRY Reg HL holds fix comma places (-1 on none)
  3984. ;       Reg DE holds decimal places
  3985. ;       Regs (HL,BC,DE)' hold real number
  3986. ;       Reg IX points to ASCII buffer
  3987. ;
  3988. l1027:
  3989.         call    l04c8           ; Get fix comma places
  3990.         ex      de,hl
  3991.         ld      e,0
  3992.         jr      c,l1033         ; Integer was < 0, no places
  3993.         cp      real.dig+1      ; Test max digits
  3994.         jr      c,l104b
  3995. l1033:
  3996.         dec     e
  3997.         call    l04c8           ; Get decimal places
  3998.         exx
  3999.         bit     sgn.bit,b       ; Test sign
  4000.         exx
  4001.         ld      d,real.field    ; Init field size
  4002.         jr      z,l1040
  4003.         inc     d               ; Fix for sign < 0.0
  4004. l1040:
  4005.         sub     d               ; Test against field length
  4006.         jr      nc,l1044
  4007.         xor     a
  4008. l1044:
  4009.         cp      real.field+2    ; Test max
  4010.         jr      c,l104a
  4011.         ld      a,real.field+2
  4012. l104a:
  4013.         inc     a
  4014. l104b:
  4015.         ld      d,a
  4016.         push    de
  4017.         exx
  4018.         ld      iy,Number ;number ;???
  4019.         push    ix
  4020.         call    l10eb           ; Prepare conversion
  4021.         pop     ix
  4022.         pop     de
  4023.         ld      c,a             ; Save result exponent
  4024.         ld      a,d
  4025.         inc     a
  4026.         bit     sgn.bit,e       ; Test sign
  4027.         jr      nz,l1071        ; < 0
  4028.         add     a,c             ; Fix exponent
  4029.         jp      p,l106b
  4030.         ld      (iy),0          ; Clear entry
  4031.         jr      l1076
  4032. l106b:
  4033.         cp      real.ASCII      ; Test decimal places
  4034.         jr      c,l1071
  4035.         ld      a,real.ASCII-1  ; Truncate it
  4036. l1071:
  4037.         push    de
  4038.         call    l1180           ; Normalize ASCII
  4039.         pop     de
  4040. l1076:
  4041.         bit     sgn.bit,b       ; Test sign
  4042.         jr      z,l107f
  4043.         ld      a,'-'
  4044.         call    l10e5           ; Set sign
  4045. l107f:
  4046.         bit     sgn.bit,e       ; Test sign
  4047.         jr      z,l1086
  4048.         ld      h,c             ; Unpack
  4049.         ld      c,0
  4050. l1086:
  4051.         bit     sgn.bit,c       ; Test sign
  4052.         jr      z,l108f
  4053.         call    l10e3           ; Set 0
  4054.         jr      l1096
  4055. l108f:
  4056.         call    l10d9           ; Copy ASCII
  4057.         dec     c               ; Bump down
  4058.         jp      p,l108f
  4059. l1096:
  4060.         ld      a,d             ; Test mantissa
  4061.         or      a
  4062.         jr      z,l10b1         ; None
  4063.         ld      a,'.'
  4064.         call    l10e5           ; Set decimal dot
  4065. l109f:
  4066.         inc     c               ; Fix exponent
  4067.         jr      z,l10a8
  4068.         call    l10e3           ; Set 0
  4069.         dec     d
  4070.         jr      nz,l109f
  4071. l10a8:
  4072.         dec     d
  4073.         jp      m,l10b1
  4074.         call    l10d9           ; Copy ASCII
  4075.         jr      l10a8
  4076. l10b1:
  4077.         bit     sgn.bit,e       ; Test exponent
  4078.         ret     z               ; Nope
  4079.         ld      a,'E'
  4080.         call    l10e5           ; Set 'E'xponent
  4081.         ld      a,'+'
  4082.         bit     sgn.bit,h       ; Test bit
  4083.         jr      z,l10c5
  4084.         ld      a,h
  4085.         neg                     ; Make exponent > 0
  4086.         ld      h,a
  4087.         ld      a,'-'
  4088. l10c5:
  4089.         call    l10e5           ; Store sign of exponent
  4090.         ld      a,h             ; Get exponent
  4091.         ld      b,'0'-1         ; Init HI
  4092. l10cb:
  4093.         inc     b               ; Fix result
  4094.         sub     10              ; Divide by 10
  4095.         jr      nc,l10cb
  4096.         add     a,'9'+1         ; Make remainder ASCII
  4097.         ld      (ix),b          ; save HI
  4098.         inc     ix
  4099.         jr      l10e5           ; Store LO
  4100. ;
  4101. ; Copy from buffer, set 0 if end
  4102. ;
  4103. l10d9:
  4104.         ld      a,(iy)          ; Get number
  4105.         inc     iy
  4106.         or      a               ; Test end
  4107.         jr      nz,l10e5        ; Nope
  4108.         dec     iy              ; Fix for zero storage
  4109. ;
  4110. ; Store ASCII zero into number
  4111. ;
  4112. l10e3:
  4113.         ld      a,'0'           ; Set zero
  4114. ;
  4115. ; Store ASCII into number
  4116. ;
  4117. l10e5:
  4118.         ld      (ix),a          ; Store number
  4119.         inc     ix              ; Update pointer
  4120.         ret
  4121. ;
  4122. ; Prepare ASCII for real to formatted ASCII conversion
  4123. ; ENTRY Reg IY points to ASXII buffer
  4124. ;       Regs (HL,BC,DE) hold real number
  4125. ; EXIT  Buffer pre-filled
  4126. ;       Accu holds exponent equivalent
  4127. ;
  4128. l10eb:
  4129.         push    iy              ; save buffer
  4130.         inc     l               ; Test zero number
  4131.         dec     l
  4132.         jr      nz,l10ff
  4133.         ld      b,real.ASCII    ; Set length
  4134. l10f3:
  4135.         ld      (iy),'0'        ; Clear ASCII number
  4136.         inc     iy
  4137.         djnz    l10f3
  4138.         xor     a
  4139.         jp      l117d
  4140. l10ff:
  4141.         push    bc              ; Save sign
  4142.         res     sgn.bit,b       ; Reset sign
  4143.         ld      a,l
  4144.         exx
  4145.         sub     exp.offset      ; Strip off offset
  4146.         ld      l,a
  4147.         sbc     a,a             ; Expand to signed 16 bit
  4148.         ld      h,a
  4149.         ld      de,ExpFix
  4150.         call    l06f5           ; HL:=HL*DE
  4151.         ld      de,10 / 2
  4152.         add     hl,de           ; Gix exponent
  4153.         ld      a,h
  4154.         cp      ExpRange        ; Test range
  4155.         jr      nz,l1119
  4156.         inc     a               ; Fix result
  4157. l1119:
  4158.         ld      (iy),a          ; Store into buffer
  4159.         neg
  4160.         call    l1240
  4161.         ld      a,l
  4162.         cp      Exp.One         ; Test exponent
  4163.         jr      nc,l112c
  4164.         call    l12b3           ; Fix mantissa
  4165.         dec     (iy)            ; Fix exponent
  4166. l112c:
  4167.         set     sgn.bit,b       ; Set bit
  4168.         ld      a,exp.offset+4
  4169.         sub     l               ; Test exponent
  4170.         ld      l,0
  4171.         jr      z,l113d
  4172. l1135:
  4173.         call    l0b7a           ; Shift mantissa right
  4174.         rr      l
  4175.         dec     a
  4176.         jr      nz,l1135
  4177. l113d:
  4178.         ld      a,(iy)          ; Get exponent
  4179.         push    af
  4180.         ld      a,real.ASCII    ; Set count
  4181. l1143:
  4182.         ex      af,af'
  4183.         ld      a,b             ; Get MSB
  4184.         rra                     ; Isolate hi
  4185.         rra
  4186.         rra
  4187.         rra
  4188.         and     LoMask          ; Mask bits
  4189.         add     a,'0'           ; Make ASCII
  4190.         ld      (iy),a
  4191.         inc     iy
  4192.         ld      a,b
  4193.         and     LoMask
  4194.         ld      b,a
  4195.         push    bc
  4196.         push    de
  4197.         push    hl
  4198.         sla     l
  4199.         call    l0b87           ; Rotate mantissa left *2
  4200.         sla     l
  4201.         call    l0b87           ; * 4
  4202.         ex      de,hl
  4203.         ex      (sp),hl
  4204.         add     hl,de           ; * 5
  4205.         pop     de
  4206.         ex      (sp),hl
  4207.         adc     hl,de
  4208.         ex      de,hl
  4209.         pop     hl
  4210.         ex      (sp),hl
  4211.         adc     hl,bc
  4212.         ld      b,h
  4213.         ld      c,l
  4214.         pop     hl
  4215.         sla     l
  4216.         call    l0b87           ; *10
  4217.         ex      af,af'
  4218.         dec     a
  4219.         jr      nz,l1143
  4220.         pop     af
  4221.         pop     bc
  4222. l117d:
  4223.         pop     iy
  4224.         ret
  4225. ;
  4226. ; Normalize ASCII number
  4227. ; ENTRY Accu holds length of number
  4228. ;
  4229. l1180:
  4230.         push    iy
  4231.         pop     hl              ; Copy buffer
  4232.         ld      e,a
  4233.         ld      d,0
  4234.         add     hl,de
  4235.         ld      a,(hl)          ; Get last digit
  4236.         ld      (hl),0
  4237.         cp      '5'             ; Test to be normalized
  4238.         ret     c               ; Nope
  4239. l118d:
  4240.         dec     e               ; Count down
  4241.         jp      m,l119c
  4242.         dec     hl              ; Get previous
  4243.         ld      a,(hl)
  4244.         inc     a               ; Advance digit
  4245.         ld      (hl),a
  4246.         cp      '9'+1           ; Test in range
  4247.         ret     c               ; Yeap
  4248.         ld      (hl),0          ; Clear this one
  4249.         jr      l118d
  4250. l119c:
  4251.         ld      (hl),'1'        ; Set carry
  4252.         inc     hl
  4253.         ld      (hl),0          ; Clear next
  4254.         inc     c
  4255.         ret
  4256. ;
  4257. ; Convert ASCII string to Floating Point number
  4258. ; ENTRY Reg IX points to ASCII number
  4259. ; EXIT  Regs HL,DE,BC hold real
  4260. ;       Carry set indicates conversion error
  4261. ;
  4262. l11a3:
  4263.         exx
  4264.         ld      bc,0            ; Reset flags
  4265.         exx
  4266.         call    l0b72           ; Init 0.0
  4267. l11ab:
  4268.         ld      a,(ix)          ; Get character
  4269.         call    l04a6           ; Convert to upper case
  4270.         cp      '.'             ; Test decimal point
  4271.         jr      nz,l11c1
  4272.         exx
  4273.         bit     dot.bit,b       ; Test already selected
  4274.         scf
  4275.         ret     nz              ; Error if so
  4276.         set     dot.bit,b       ; Indicate dot
  4277.         exx
  4278. l11bd:
  4279.         inc     ix              ; Skip character
  4280.         jr      l11ab           ; Get next
  4281. l11c1:
  4282.         cp      'E'             ; Test exponent
  4283.         jr      z,l11e6         ; Yeap, process it
  4284.         call    l1239           ; Test digit
  4285.         jr      nc,l121e        ; Nope
  4286.         ex      af,af'
  4287.         call    l12b3           ; Convert mantissa
  4288.         ret     c               ; Error
  4289.         ex      af,af'
  4290.         exx
  4291.         push    bc
  4292.         ld      l,a             ; Build integer
  4293.         ld      h,0
  4294.         call    l1008           ; Convert to floating point
  4295.         call    l09e9           ; Add reals
  4296.         exx
  4297.         pop     bc
  4298.         ret     c               ; End if overflow
  4299.         bit     dot.bit,b       ; Test decimal point
  4300.         jr      z,l11e3
  4301.         dec     c               ; Fix length if so
  4302. l11e3:
  4303.         exx
  4304.         jr      l11bd
  4305. ;
  4306. ; Found 'E'xponent
  4307. ;
  4308. l11e6:
  4309.         call    l121e           ; Fix mantissa
  4310.         ret     c               ; Overflow
  4311.         exx
  4312.         set     exp.bit,b       ; Set bit
  4313.         inc     ix
  4314.         ld      a,(ix)
  4315.         cp      '+'             ; Test any sign
  4316.         jr      z,l11fc         ; Skip plus
  4317.         cp      '-'
  4318.         jr      nz,l11fe
  4319.         set     exps.bit,b      ; Indicate negative exponent
  4320. l11fc:
  4321.         inc     ix
  4322. l11fe:
  4323.         call    l1236           ; Get 1st digit
  4324.         ccf
  4325.         ret     c               ; Invalid
  4326.         ld      c,a
  4327.         inc     ix
  4328.         call    l1236           ; Get 2nd digit
  4329.         jr      nc,l1215        ; Only one
  4330.         inc     ix
  4331.         ld      d,a
  4332.         ld      a,c             ; Get first one - it's tens
  4333.         add     a,a             ; * 2
  4334.         add     a,a             ; * 4
  4335.         add     a,c             ; * 5
  4336.         add     a,a             ; *10
  4337.         add     a,d             ; Insert 2nd
  4338.         ld      c,a
  4339. l1215:
  4340.         bit     exps.bit,b      ; Test exponent < 0
  4341.         jr      z,l121d         ; Nope
  4342.         ld      a,c
  4343.         neg                     ; Change it if so
  4344.         ld      c,a
  4345. l121d:
  4346.         exx
  4347. l121e:
  4348.         exx
  4349.         ld      a,c             ; Get exponent
  4350.         add     a,exp.offset    ; Set offset
  4351.         cp      05ah            ; Check range
  4352.         ret     c               ; Underflow
  4353.         cp      0a6h
  4354.         ccf
  4355.         ret     c               ; Overflow
  4356.         push    bc
  4357.         push    ix
  4358.         ld      a,c
  4359.         call    l1240           ; Fix exponent
  4360.         pop     ix
  4361.         exx
  4362.         pop     bc              ; Fix stack
  4363.         exx
  4364.         ret
  4365. ;
  4366. ; Get character and test if digit
  4367. ; ENTRY Reg IX points to character
  4368. ; EXIT  Accu holds character
  4369. ;       Carry reset if in range
  4370. ;
  4371. l1236:
  4372.         ld      a,(ix)          ; Get character
  4373. ;
  4374. ; Test character a digit - C set if so
  4375. ; ENTRY Accu holds character
  4376. ; EXIT  Carry reset if in range
  4377. ;
  4378. l1239:
  4379.         sub     '0'             ; Strip off offset
  4380.         ccf
  4381.         ret     nc              ; Out of range
  4382.         cp      9+1
  4383.         ret
  4384. ;
  4385. ; Fix exponent for real to ASCII conversion
  4386. ; ENTRY Accu holds exponent equivalent
  4387. ; EXIT  Real fixed
  4388. ;
  4389. l1240:
  4390.         push    af              ; Save exponent
  4391.         or      a               ; Test sign
  4392.         jp      p,l1247
  4393.         neg                     ; Make >0
  4394. l1247:
  4395.         push    af
  4396.         srl     a               ; Shift
  4397.         srl     a
  4398.         inc     a               ; Then fix
  4399.         ld      hl,-Real.Len    ; Init index
  4400.         ld      de,Real.Len
  4401. l1253:
  4402.         add     hl,de           ; Fix index
  4403.         dec     a
  4404.         jr      nz,l1253
  4405.         ex      de,hl
  4406.         ld      ix,l1277        ; Point to table
  4407.         add     ix,de
  4408.         call    l0f73           ; Get number from table
  4409.         pop     af
  4410.         and     11b             ; Get MOD 4
  4411.         jr      z,l126e
  4412. l1266:
  4413.         push    af
  4414.         call    l12b3           ; Fix mantissa
  4415.         pop     af
  4416.         dec     a
  4417.         jr      nz,l1266
  4418. l126e:
  4419.         pop     af              ; Get back exponent
  4420.         or      a
  4421.         jp      p,l0a97         ; Multiply reals if > 0
  4422.         exx
  4423.         jp      l0af5           ; Divide reals if < 0
  4424. ;
  4425. ; Fix up table
  4426. ;
  4427. l1277:
  4428.         db      081h,000h,000h,000h,000h,000h   ; 1 E 0
  4429.         db      08eh,000h,000h,000h,040h,01ch   ; 1 E 4
  4430.         db      09bh,000h,000h,020h,0bch,03eh   ; 1 E 8
  4431.         db      0a8h,000h,010h,0a5h,0d4h,068h   ; 1 E12
  4432.         db      0b6h,004h,0bfh,0c9h,01bh,00eh   ; 1 E16
  4433.         db      0c3h,0ach,0c5h,0ebh,078h,02dh   ; 1 E20
  4434.         db      0d0h,0cdh,0ceh,01bh,0c2h,053h   ; 1 E24
  4435.         db      0deh,0f9h,078h,039h,03fh,001h   ; 1 E28
  4436.         db      0ebh,02bh,0a8h,0adh,0c5h,01dh   ; 1 E32
  4437.         db      0f8h,0c9h,07bh,0ceh,097h,040h   ; 1 E36
  4438. ;
  4439. ; Fix mantissa for real to ASCII conversion
  4440. ; ENTRY Regs (BC,DE,HL) hold real
  4441. ; EXIT  Real fixed
  4442. ;
  4443. l12b3:
  4444.         ld      a,l             ; Test exponent
  4445.         or      a
  4446.         ret     z               ; Zero
  4447.         set     _MB,b           ; Set bit
  4448.         push    bc
  4449.         push    de
  4450.         ld      a,h
  4451.         call    l0b7a           ; Shift mantissa right
  4452.         call    l0b7a           ; Two places
  4453.         add     a,h             ; Add LSB
  4454.         ld      h,a
  4455.         ex      (sp),hl         ; Get middle part
  4456.         adc     hl,de           ; Add it
  4457.         ex      de,hl
  4458.         pop     hl
  4459.         ex      (sp),hl
  4460.         adc     hl,bc           ; Same for hi part
  4461.         ld      b,h             ; Copy to high
  4462.         ld      c,l
  4463.         pop     hl              ; Get back old hi
  4464.         jr      nc,l12d6
  4465.         call    l0b7b           ; Rotate mantissa right
  4466.         inc     l               ; Fix exponent
  4467.         scf
  4468.         ret     z
  4469. l12d6:
  4470.         ld      a,l
  4471.         add     a,3             ; Fix exponent
  4472.         ld      l,a
  4473.         res     _MB,b           ; Clear bit
  4474.         ret
  4475. ;
  4476. ; Test sets not equal (<>)
  4477. ; ENTRY Both sets on stack
  4478. ; EXIT  Reg HL holds boolean result
  4479. ;
  4480. l12dd:
  4481.         ld      c,_TRUE         ; Set flag
  4482.         jr      l12e3           ; Compare
  4483. ;
  4484. ; Test sets equal (=)
  4485. ; ENTRY Both sets on stack
  4486. ; EXIT  Reg HL holds boolean result
  4487. ;
  4488. l12e1:
  4489.         ld      c,FALSE
  4490. l12e3:
  4491.         call    l133f           ; Get sets
  4492. l12e6:
  4493.         ld      a,(de)
  4494.         cp      (hl)            ; Compare
  4495.         jr      nz,l12f2        ; Not equal
  4496.         inc     hl
  4497.         inc     de
  4498.         djnz    l12e6
  4499.         ld      a,c
  4500.         xor     _TRUE           ; Zoggle flag if equal
  4501.         ld      c,a
  4502. l12f2:
  4503.         ld      hl,2*set.len
  4504.         add     hl,sp           ; Fix stack
  4505.         ld      sp,hl
  4506.         ld      l,c             ; Get state
  4507.         ld      h,0
  4508.         jp      (ix)            ; Exit
  4509. ;
  4510. ; Test two sets included (1st in 2nd, <=)
  4511. ; ENTRY Both sets on stack
  4512. ; EXIT  Reg HL holds boolean result
  4513. ;
  4514. l12fc:
  4515.         ld      c,_TRUE         ; Set flag
  4516.         jr      l1302
  4517. ;
  4518. ; Test two sets included (2nd in 1st, >=)
  4519. ; ENTRY Both sets on stack
  4520. ; EXIT  Reg HL holds boolean result
  4521. ;
  4522. l1300:
  4523.         ld      c,FALSE
  4524. l1302:
  4525.         call    l133f           ; Get sets
  4526.         dec     c               ; Test comparision mode
  4527.         jr      nz,l1309
  4528.         ex      de,hl
  4529. l1309:
  4530.         ld      c,FALSE
  4531. l130b:
  4532.         ld      a,(de)
  4533.         or      (hl)            ; Combine
  4534.         cp      (hl)            ; Compare
  4535.         jr      nz,l12f2
  4536.         inc     hl
  4537.         inc     de
  4538.         djnz    l130b
  4539.         ld      c,_TRUE         ; Return TRUE
  4540.         jr      l12f2
  4541. ;
  4542. ; Combine two sets (add, +)
  4543. ; ENTRY Both sets on stack
  4544. ; EXIT  Combined set on stack
  4545. ;
  4546. l1318:
  4547.         call    l133f           ; Get sets
  4548. l131b:
  4549.         ld      a,(de)
  4550.         or      (hl)            ; Combine sets
  4551.         ld      (hl),a
  4552.         inc     hl
  4553.         inc     de
  4554.         djnz    l131b
  4555. l1322:
  4556.         ex      de,hl
  4557.         ld      sp,hl
  4558.         jp      (ix)
  4559. ;
  4560. ; Combine two sets (subtract, -)
  4561. ; ENTRY Both sets on stack
  4562. ; EXIT  Combined set on stack
  4563. ;
  4564. l1326:
  4565.         call    l133f           ; Get sets
  4566. l1329:
  4567.         ld      a,(de)
  4568.         cpl                     ; Complement
  4569.         and     (hl)            ; Mask bits
  4570.         ld      (hl),a
  4571.         inc     hl
  4572.         inc     de
  4573.         djnz    l1329
  4574.         jr      l1322
  4575. ;
  4576. ; Combine two sets (intersection, *)
  4577. ; ENTRY Both sets on stack
  4578. ; EXIT  Combined set on stack
  4579. ;
  4580. l1333:
  4581.         call    l133f           ; Get sets
  4582. l1336:
  4583.         ld      a,(de)
  4584.         and     (hl)            ; Mask
  4585.         ld      (hl),a
  4586.         inc     hl
  4587.         inc     de
  4588.         djnz    l1336
  4589.         jr      l1322
  4590. ;
  4591. ; Get addresses of sets
  4592. ; ENTRY Both sets on stack
  4593. ; EXIT  Regs HL and DE point to sets
  4594. ;       Reg  IX holds caller address
  4595. ;       Reg  B  holds set length
  4596. ;
  4597. l133f:
  4598.         pop     iy              ; Get last caller
  4599.         pop     ix              ; Get caller before last one
  4600.         ld      hl,0
  4601.         add     hl,sp
  4602.         ex      de,hl           ; Get 1st set
  4603.         ld      hl,set.len
  4604.         ld      b,l             ; Get length
  4605.         add     hl,sp           ; Get 2nd set
  4606.         jp      (iy)            ; Return
  4607. ;
  4608. ; Test element in set (IN)
  4609. ; ENTRY Both sets on stack
  4610. ; EXIT  Reg HL holds boolean result
  4611. ;
  4612. l134f:
  4613.         pop     ix              ; Get caller
  4614.         ld      hl,set.len+1
  4615.         add     hl,sp           ; Get pointer to set
  4616.         ld      a,(hl)
  4617.         or      a               ; Test any set
  4618.         jr      z,l135c
  4619.         xor     a
  4620.         jr      l1362           ; Force FALSE
  4621. l135c:
  4622.         dec     hl
  4623.         ld      b,(hl)
  4624.         call    l05ba           ; Get bit state
  4625.         and     (hl)
  4626. l1362:
  4627.         ld      hl,set.len+2
  4628.         add     hl,sp
  4629.         ld      sp,hl           ; Set return stack
  4630.         ld      hl,FALSE        ; Init FALSE
  4631.         jr      z,l136d         ; Test result
  4632.         inc     hl              ; Set TRUE
  4633. l136d:
  4634.         jp      (ix)
  4635. ;
  4636. ; Procedure ASSIGN(file,filename)
  4637. ; ENTRY Filenname as string on stack
  4638. ;       FIB followed string
  4639. ;
  4640. ; Assign text file
  4641. ;
  4642. l136f:
  4643.         db      skip            ; Set non zero
  4644. ;
  4645. ; Assign (un)typed file
  4646. ;
  4647. l1370:
  4648.         xor     a               ; Set zero
  4649.         ld      (l00e8),a       ; Put into mode
  4650.         pop     iy              ; Get back caller
  4651.         ld      hl,(l00d2)      ; Get top of memory
  4652.         ld      b,16            ; And max length
  4653.         call    l05e2           ; Assign string from stack
  4654.         xor     a
  4655.         ld      (de),a          ; Close it
  4656.         pop     hl              ; Fetch FIB
  4657.         ld      (l00e2),hl      ; Put into device
  4658.         push    iy              ; Bring back caller
  4659.         ld      a,h             ; Verify not standard but file
  4660.         or      a
  4661.         jr      nz,l1390
  4662.         ld      a,_StdAssErr    ; Set illegal FIB
  4663.         ld      (l00d0),a
  4664.         ret
  4665. l1390:
  4666.         ld      a,(l00e8)       ; Get back mode
  4667.         or      a               ; Test text file
  4668.         jr      z,l13a0         ; Nope
  4669.         call    l13b6           ; Find standard device
  4670.         jr      nz,l13a0        ; Nope
  4671.         ld      hl,(l00e2)      ; Get back FIB
  4672.         ld      (hl),a          ; Set flag
  4673.         ret
  4674. l13a0:
  4675.         call    l03f2           ; Parse file
  4676.         ld      hl,(l00e2)
  4677.         ld      (hl),0
  4678.         ld      de,FIB.FCB
  4679.         add     hl,de           ; Point to FCB part
  4680.         ex      de,hl
  4681.         ld      hl,l005c
  4682.         ld      bc,FCBlen
  4683.         ldir                    ; move FCB to FIB
  4684.         ret
  4685. ;
  4686. ; Find standard IO device
  4687. ; ENTRY TOPRAM filled with device string
  4688. ; EXIT  Zero flag set if device found
  4689. ;       Accu holds FIB flag if so
  4690. ;
  4691. l13b6:
  4692.         ld      b,Std.Len       ; Init length
  4693.         ld      hl,l13e6        ; Get table address
  4694. l13bb:
  4695.         push    bc
  4696.         push    hl
  4697.         ld      b,Std.Itm-1     ; Set length of one item
  4698.         ld      de,(l00d2)      ; Get top of memory
  4699. l13c3:
  4700.         inc     de
  4701.         ld      a,(de)
  4702.         cp      ' '             ; Skip leading blanks
  4703.         jr      z,l13c3
  4704. l13c9:
  4705.         ld      a,(de)          ; Get character
  4706.         call    l04a6           ; Convert to upper case
  4707.         sub     (hl)            ; Compare
  4708.         jr      z,l13da         ; Maybe a hit
  4709.         pop     hl
  4710.         pop     bc
  4711.         ld      de,Std.Itm
  4712.         add     hl,de           ; Point to next entry
  4713.         djnz    l13bb           ; Try more
  4714.         or      a
  4715.         ret
  4716. l13da:
  4717.         inc     hl
  4718.         inc     de
  4719.         djnz    l13c9           ; Loop until all found
  4720.         pop     bc
  4721.         pop     bc
  4722.         ld      a,(de)
  4723.         cp      ':'             ; Verify standard device
  4724.         ret     nz
  4725.         ld      a,(hl)          ; Get flag if so
  4726.         ret
  4727. ;
  4728. ; Standard character I/O devices
  4729. ;
  4730. l13e6:
  4731.         db      'CON'
  4732.         db      11000001b       ; Input output for CON 
  4733. Std.Itm equ     $-l13e6
  4734.         db      'TRM'
  4735.         db      11000001b       ; Input output for TRM
  4736.         db      'KBD'
  4737.         db      10000010b       ; Input for KBD
  4738.         db      'LST'
  4739.         db      01000011b       ; Output for LST
  4740.         db      'AUX'
  4741.         db      11000100b       ; Input output for AUX
  4742.         db      'USR'
  4743.         db      11000101b       ; Input output for USR
  4744. Std.Len equ     ($-l13e6) / Std.Itm
  4745. ;
  4746. ; Prepare files
  4747. ; ENTRY Reg HL points to FIB
  4748. ;
  4749. ; Procedure REWRITE(text_file)
  4750. ;
  4751. l13fe:
  4752.         db      skip
  4753. ;
  4754. ; Procedure RESET(text_file)
  4755. ;
  4756. l13ff:
  4757.         xor     a
  4758.         ld      (l00e8),a       ; Set mode (0=RESET)
  4759.         call    l1469           ; Close open file
  4760.         ld      a,(l00d0)
  4761.         or      a               ; Test error
  4762.         ret     nz              ; End if so
  4763.         ld      hl,(l00e2)      ; Get FIB
  4764.         res     wr.bit,(hl)     ; Reset write flag
  4765.         ld      a,(hl)
  4766.         and     FIBtype         ; Get type
  4767.         ret     nz              ; Exit on standard device
  4768.         call    l1430           ; Prepare file operation
  4769.         ld      a,(l00d0)
  4770.         or      a               ; Test error
  4771.         ret     nz              ; Exit if so
  4772.         ld      hl,(l00e2)      ; Get back FIB
  4773.         ld      a,(l00e8)       ; Get file mode
  4774.         or      a               ; Test RESET
  4775.         ld      bc,RecLng*256+_.in
  4776.         jr      z,l142b         ; Yeap
  4777.         ld      bc,0*256+_.out
  4778. l142b:
  4779.         ld      (hl),c          ; Set flag
  4780.         inc     hl
  4781.         inc     hl
  4782.         ld      (hl),b          ; Set buffer pointer
  4783.         ret
  4784. ;
  4785. ; Prepare file operation for current FIB
  4786. ;
  4787. l1430:
  4788.         call    l145a           ; Clear FCB of this FIB
  4789.         ld      hl,(l00e2)      ; Get FIB
  4790.         ld      de,FIB.FCB
  4791.         add     hl,de           ; Point to FCB
  4792.         ex      de,hl
  4793.         ld      a,(l00e8)       ; Get file mode
  4794.         or      a               ; Test RESET
  4795.         ld      bc,_NoFile*256+_open
  4796.         jr      z,l144e         ; Yeap, go open file
  4797.         push    de
  4798.         ld      c,_delete
  4799.         call    BDOS            ; Delete file before rewrite
  4800.         pop     de
  4801.         ld      bc,_DirFull*256+_make
  4802. l144e:
  4803.         push    bc
  4804.         call    BDOS            ; Now open or make file
  4805.         pop     bc
  4806.         inc     a               ; Test success
  4807.         ret     nz              ; Yeap
  4808.         ld      a,b
  4809.         ld      (l00d0),a       ; Set error if not
  4810.         ret
  4811. ;
  4812. ; Clear FCB of current FIB
  4813. ;
  4814. l145a:
  4815.         ld      hl,(l00e2)      ; Get FIB
  4816.         ld      de,FIB.FCB+_ex
  4817.         add     hl,de           ; Point to EX filed
  4818.         ld      b,FCBlen-_ex    ; Set length
  4819. l1463:
  4820.         ld      (hl),0          ; Clear it
  4821.         inc     hl
  4822.         djnz    l1463
  4823.         ret
  4824. ;
  4825. ; Close text file
  4826. ;
  4827. ; Procedure CLOSE(text_file)
  4828. ;
  4829. ; ENTRY Reg HL holds FIB
  4830. ;
  4831. l1469:
  4832.         ld      (l00e2),hl      ; Save FIB for current device
  4833.         ld      a,(hl)
  4834.         and     FIBtype         ; Get type
  4835.         ret     nz              ; Exit if not a file
  4836.         bit     out.bit,(hl)    ; Test output
  4837.         jr      z,l147e         ; Skip if not
  4838.         ld      a,eof
  4839.         call    l16c6           ; Close file by EOF
  4840.         call    l170c           ; Then flash buffer
  4841.         jr      l1481
  4842. l147e:
  4843.         bit     in.bit,(hl)     ; Test input
  4844.         ret     z               ; Nope, end
  4845. l1481:
  4846.         ld      hl,(l00e2)      ; Get FIB
  4847.         push    hl
  4848.         ld      de,FIB.FCB
  4849.         add     hl,de           ; Point to FCB
  4850.         ex      de,hl
  4851.         ld      c,_close
  4852.         call    BDOS            ; Close file
  4853.         pop     hl
  4854.         inc     a               ; Test success
  4855.         jr      nz,l1498        ; Yeap
  4856.         ld      a,_NoClose
  4857.         ld      (l00d0),a       ; Set error
  4858. l1498:
  4859.         ld      (hl),0          ; Reset FIB flag
  4860.         ret
  4861. ;
  4862. ; Set standard device
  4863. ;
  4864. l149b:
  4865.         ex      (sp),hl
  4866.         ld      (l00e4),hl      ; Save caller
  4867.         ex      (sp),hl
  4868.         push    hl
  4869.         ld      hl,l00c2
  4870.         ld      (l00e2),hl      ; Set standard as FIB
  4871.         pop     hl
  4872.         ret
  4873. ;
  4874. ; Check file before read
  4875. ; ENTRY Reg HL points to FIB
  4876. ;
  4877. l14a9:
  4878.         ex      (sp),hl
  4879.         ld      (l00e4),hl      ; Save caller for error
  4880.         ex      (sp),hl
  4881.         ld      (l00e2),hl      ; Save FIB
  4882.         bit     in.bit,(hl)     ; Test read allowed
  4883.         ret     nz              ; Yeap
  4884.         ld      a,_NoRead
  4885.         ld      (l00d0),a       ; Set error
  4886.         ret
  4887. ;
  4888. ; Check file before write
  4889. ; ENTRY Reg HL points to FIB
  4890. ;
  4891. l14ba:
  4892.         ex      (sp),hl
  4893.         ld      (l00e4),hl      ; Save caller for error
  4894.         ex      (sp),hl
  4895.         ld      (l00e2),hl      ; Save FIB
  4896.         bit     out.bit,(hl)    ; Test write allowed
  4897.         ret     nz              ; Yeap
  4898.         ld      a,_NoWrite
  4899.         ld      (l00d0),a       ; Set error
  4900.         ret
  4901. ;
  4902. ; Function READLN(var)
  4903. ; ENTRY Reg HL points to variable
  4904. ;
  4905. l14cb:
  4906.         db      skip
  4907. ;
  4908. ; Function READ(var)
  4909. ; ENTRY Reg HL points to variable
  4910. ; EXIT  Reg HL points to variable
  4911. ;
  4912. l14cc:
  4913.         xor     a
  4914.         ex      (sp),hl         ; Get caller
  4915.         ld      (l00e4),hl      ; Save it
  4916.         ex      (sp),hl
  4917.         push    hl
  4918.         ld      hl,l00c2
  4919.         ld      (l00e2),hl      ; Set standard device
  4920.         res     wr.bit,(hl)     ; Reset write bit
  4921.         push    af              ; Save mode
  4922.         call    l14e8           ; Read a line
  4923.         pop     af
  4924.         or      a               ; Test READLN
  4925.         jr      z,l14e6
  4926.         call    l01e1           ; Give new line if so
  4927. l14e6:
  4928.         pop     hl
  4929.         ret
  4930. ;
  4931. ; Read a line from keyboard
  4932. ;
  4933. l14e8:
  4934.         ld      b,0             ; Reset flag
  4935. l14ea:
  4936.         ld      hl,l00d1        ; Point to buffer length
  4937.         ld      a,(hl)          ; Get buffer length
  4938.         cp      _MaxBuf+1       ; Verify in range
  4939.         jr      c,l14f4
  4940.         ld      a,_MaxBuf       ; Truncate if not
  4941. l14f4:
  4942.         ld      c,a
  4943.         ld      (hl),_MaxBuf    ; Set default length
  4944.         ld      hl,(l00d2)      ; Get top of memory
  4945.         ld      (l00d4),hl      ; Unpack it
  4946. l14fd:
  4947.         ld      d,0             ; Reset character count
  4948. l14ff:
  4949.         call    readfromkbd             ; Read character
  4950.         ld      (hl),a          ; Unpack it
  4951.         ld      e,1             ; Init flag
  4952.         cp      bs              ; Test backspace
  4953.         jr      z,l153f
  4954.         ;cp     DEL             ; Test delete
  4955.         ;jr     z,l153f
  4956.         dec     e
  4957.         cp      CtrlX           ; Test ^X
  4958.         jr      z,l153f
  4959.         cp      esc             ; Test escape
  4960.         jr      z,l153f
  4961.         cp      eof             ; Test end of file
  4962.         jr      z,l1550
  4963.         cp      cr              ; Test end of line
  4964.         jr      z,l1556
  4965.         cp      ' '             ; Test printable
  4966.         jr      nc,l1533
  4967.         cp      CtrlC           ; Test ^C
  4968.         jr      nz,l14ff
  4969.         ld      a,(l00dd)       ; Get $C mode
  4970.         or      a               ; Test abort
  4971.         jr      z,l14ff         ; $C- - so ignore
  4972.         ld      ix,(l00e4)
  4973.         jp      l2016           ; Abort
  4974. ;
  4975. ; Found printable character
  4976. ;
  4977. l1533:
  4978.         ld      a,c             ; Get max
  4979.         cp      d               ; Test against count
  4980.         jr      z,l14ff         ; Yeap, ignore
  4981.         ld      a,(hl)          ; Get character
  4982.         inc     d               ; Advance counter
  4983.         inc     hl              ; Point to next storage location
  4984.         call    puttoconsole_a          ; Put to console
  4985.         jr      l14ff
  4986. ;
  4987. ; Special control detected: Backspace, DELete, ^X, ESCape
  4988. ;
  4989. l153f:
  4990.         dec     d               ; Fix count
  4991.         jp      m,l14fd         ; Ignore if at 1st position
  4992.         dec     hl
  4993.         call    l0200           ; Position cursor left
  4994.         db      bs,' ',bs
  4995.         db      null
  4996.         dec     e               ; Test backspace or delete
  4997.         jr      z,l14ff         ; Yeap
  4998.         jr      l153f           ; Else delete two characters on screen
  4999. ;
  5000. ; Found EOF
  5001. ;
  5002. l1550:
  5003.         inc     b               ; Test flag
  5004.         dec     b
  5005.         jr      z,l14ff         ; Ignore input
  5006.         jr      l155a           ; Close input line
  5007. ;
  5008. ; Found CR
  5009. ;
  5010. l1556:
  5011.         inc     b               ; Test flag
  5012.         dec     b
  5013.         jr      nz,l155e        ; Ignore EOF
  5014. l155a:
  5015.         ld      (hl),eof        ; Close line
  5016.         jr      l1566
  5017. l155e:
  5018.         call    l01e1           ; Give new line
  5019.         ld      (hl),cr         ; Close line
  5020.         inc     hl
  5021.         ld      (hl),lf
  5022. l1566:
  5023.         inc     hl
  5024.         ld      (l00d6),hl      ; Set top pointer
  5025.         ret
  5026. ;
  5027. ; Get character from file or console buffer
  5028. ;
  5029. l156b:
  5030.         ld      hl,(l00e2)      ; Get FIB
  5031.         ld      a,(l00d0)
  5032.         or      a               ; Test error
  5033.         jp      nz,l15ed        ; Force EOF if so
  5034.         ld      a,(hl)
  5035.         bit     wr.bit,a        ; Test preread
  5036.         jp      nz,l15e9        ; Fetch if so
  5037.         and     FIBtype         ; Test device
  5038.         jr      nz,l15ab        ; Yeap, standard I/O
  5039.         inc     hl              ; Point to sector buffer
  5040.         inc     hl
  5041.         ld      a,(hl)
  5042.         or      a               ; Test filled
  5043.         jp      p,l1597         ; Not yet
  5044.          ;push  hl
  5045.          ;ex de,hl
  5046.          ;ld    c,_setdma
  5047.          ;call  l19ba           ; set DTA
  5048.          ;pop   hl        
  5049.         ld      c,_rdseq
  5050.         push    hl
  5051.         call    l19ba           ; Read sector
  5052.         pop     hl
  5053.         ;jr     z,l1595         ; Read was successfull
  5054.          cp 128 ;EOF in NedoOS
  5055.          jr nz,l1595            ; Read was successfull
  5056.          ;jr $ ;lister.pas
  5057. ;CP/M has eofs in the end of last sector?
  5058. ;do this by hand:
  5059.         or a
  5060.         jr z,read_load_noaddeofs ;full sector
  5061. ;a=128+bytes loaded
  5062.         neg
  5063. ;a=128-bytes loaded
  5064.         ld b,a
  5065.         ld a,l
  5066.         add a,127
  5067.         ld e,a
  5068.         adc a,h
  5069.         sub e
  5070.         ld d,a
  5071.         ;ld de,l7957+127        ;de= Point to buffer end
  5072.         ld a,eof;-1
  5073.         ld (de),a
  5074.         dec de
  5075.         djnz $-2
  5076. read_load_noaddeofs
  5077.  
  5078.         push    hl
  5079.         ld      de,FIB.buff-2
  5080.         add     hl,de           ; Point to buffer
  5081.         ld      (hl),eof        ; Set EOF
  5082.         pop     hl
  5083. l1595:
  5084.         xor     a
  5085.         ld      (hl),a          ; Reset buffer pointer
  5086. l1597:
  5087.         inc     (hl)            ; Bump pointer
  5088.         add     a,FIB.buff-2
  5089.         ld      e,a
  5090.         ld      d,0
  5091.         add     hl,de           ; Calculate current buffer
  5092.         ld      a,(hl)
  5093.         cp      eof             ; Test EOF
  5094.         jr      nz,l15e0        ; Nope
  5095.         ld      hl,(l00e2)
  5096.         inc     hl
  5097.         inc     hl
  5098.         dec     (hl)            ; Fix pointer if eof found
  5099.         jr      l15e0
  5100. l15ab:
  5101.         dec     a               ; Test CON:
  5102.         jr      nz,l15c9
  5103.         ld      hl,(l00d4)      ; Get current ppinter
  5104.         ld      de,(l00d6)      ; Get top pointer
  5105.         or      a
  5106.         sbc     hl,de           ; Test more in buffer
  5107.         jr      c,l15bf         ; Ok
  5108.         ld      b,-1
  5109.         call    l14ea           ; Else get more
  5110. l15bf:
  5111.         ld      hl,(l00d4)      ; Get current pointer
  5112.         ld      a,(hl)
  5113.         inc     hl              ; Bump
  5114.         ld      (l00d4),hl
  5115.         jr      l15e0
  5116. l15c9:
  5117.         dec     a               ; Test KBD:
  5118.         jr      nz,l15d2
  5119.         call    l00a3           ; Read KBD
  5120.         ld      a,l
  5121.         jr      l15e0
  5122. l15d2:
  5123.         dec     a               ; Test AUX:
  5124.         dec     a
  5125.         jr      nz,l15dc
  5126.         call    l00af           ; Get from auxiliary
  5127.         ld      a,l
  5128.         jr      l15e0
  5129. l15dc:
  5130.         call    l00b5           ; Read USR
  5131.         ld      a,l
  5132. l15e0:
  5133.         ld      hl,(l00e2)      ; Get back FIB
  5134.         set     wr.bit,(hl)     ; Set preread flag
  5135.         inc     hl
  5136.         ld      (hl),a          ; Save character
  5137.         dec     hl
  5138.         ret
  5139. l15e9:
  5140.         inc     hl              ; Point to character buffer
  5141.         ld      a,(hl)          ; Get character
  5142.         dec     hl
  5143.         ret
  5144. l15ed:
  5145.         ld      a,eof           ; Return EOF
  5146.         ret
  5147. ;
  5148. ; Get character from current device
  5149. ; Fix up controls
  5150. ;
  5151. l15f0:
  5152.         push    hl
  5153.         ld      hl,(l00e2)      ; Get FIB
  5154.         ld      a,(hl)
  5155.         and     FIBtype         ; Get device
  5156.         cp      RAMdevice       ; Test RAM
  5157.         jr      z,l1622
  5158. l15fb:
  5159.         call    l156b           ; Get character from device
  5160.         cp      ' '+1           ; Test control
  5161.         jr      nc,l160a        ; Nope
  5162.         cp      eof             ; Test EOF
  5163.         jr      z,l160a         ; Yeap
  5164.         res     wr.bit,(hl)     ; Reset preread
  5165.         jr      l15fb           ; Then synchronize
  5166. l160a:
  5167.         ld      de,Number       ; Set buffer
  5168.         ld      b,_MaxSamp      ; Set max
  5169. l160f:
  5170.         push    bc
  5171.         push    de
  5172.         call    l156b           ; Get character from device
  5173.         pop     de
  5174.         pop     bc
  5175.         cp      ' '+1           ; Test control
  5176.         jr      c,l1620         ; Yeap, end if so
  5177.         res     wr.bit,(hl)     ; No preread
  5178.         ld      (de),a          ; save character
  5179.         inc     de
  5180.         djnz    l160f
  5181. l1620:
  5182.         xor     a
  5183.         ld      (de),a          ; Close buffer
  5184. l1622:
  5185.         pop     hl
  5186.         ret
  5187. ;
  5188. ; Check negative sign of ASCII number
  5189. ; ENTRY Location NUMBER filled
  5190. ; EXIT  Reg IX points to number buffer
  5191. ;       Reg B holds 0 on no negative sign
  5192. ;               and 1 on negative sign found
  5193. ;       Zero flag indicates empty buffer
  5194. ;
  5195. l1624:
  5196.         ld      ix,Number       ; Init pointer
  5197.         ld      a,(ix)          ; Get character
  5198.         or      a
  5199.         ret     z               ; Exit if zero
  5200.         ld      b,0
  5201.         cp      '-'             ; Test negative sign
  5202.         ret     nz              ; Nope
  5203.         inc     b               ; Fix result
  5204.         inc     ix              ; Skip pointer
  5205.         ret
  5206. ;
  5207. ; Fix number conversion for error
  5208. ; ENTRY Reg IX points behind number
  5209. ;       Carry set reflects overflow
  5210. ; EXIT  Carry set indicates error
  5211. ;       IORESULT set to error 010H
  5212. ;
  5213. l1636:
  5214.         jr      c,l163d         ; Fall into error
  5215.         ld      a,(ix)          ; Test correct end
  5216.         or      a
  5217.         ret     z               ; Yeap
  5218. l163d:
  5219.         ld      a,_IllNum
  5220.         ld      (l00d0),a       ; Set error
  5221.         scf
  5222.         ret
  5223. ;
  5224. ; Get character from input READ(char)
  5225. ; ENTRY Reg HL points to character variable
  5226. ;
  5227. l1644:
  5228.         push    hl              ; Save pointer
  5229.         call    l156b           ; Get character
  5230.         res     wr.bit,(hl)     ; Reset preread
  5231.         pop     hl              ; Get back pointer
  5232.         ld      (hl),a          ; Save character
  5233.         ret
  5234. ;
  5235. ; Get byte from input READ(byte)
  5236. ; ENTRY Reg HL points to byte variable
  5237. ;
  5238. l164d:
  5239.         db      skip            ; Set byte flag
  5240. ;
  5241. ; Get integer from input READ(integer)
  5242. ; ENTRY Reg HL points to integer variable
  5243. ;
  5244. l164e:
  5245.         xor     a               ; Reset byte flag
  5246.         ld      c,a
  5247.         push    bc
  5248.         call    l15f0           ; Get number input
  5249.         pop     bc
  5250.         call    l1624           ; Test sign
  5251.         ret     z               ; Empty number, exit
  5252.         push    bc
  5253.         push    hl
  5254.         call    l07f7           ; Convert ASCII to integer
  5255.         pop     de
  5256.         pop     bc
  5257.         call    l1636           ; Test error
  5258.         ret     c               ; Yeap, exit
  5259.         dec     b               ; Test negative sign
  5260.         call    z,l0783         ; Negate if so
  5261.         ex      de,hl
  5262.         ld      (hl),e          ; Save low or byte
  5263.         inc     c
  5264.         dec     c               ; Test byte
  5265.         jr      nz,l1670        ; Skip if so
  5266.         inc     hl
  5267.         ld      (hl),d          ; Save high on integer
  5268. l1670:
  5269.         ex      de,hl
  5270.         ret
  5271. ;
  5272. ; Get real from input READ(real)
  5273. ; ENTRY Reg HL points to real variable
  5274. ;
  5275. l1672:
  5276.         call    l15f0           ; Get ASCII number
  5277.         call    l1624           ; Test sign
  5278.         ret     z               ; Empty number, exit
  5279.         push    bc
  5280.         push    hl
  5281.         call    l11a3           ; Convert to real
  5282.         exx
  5283.         pop     hl
  5284.         pop     bc
  5285.         call    l1636           ; Test error
  5286.         ret     c               ; Yeap, exit
  5287.         dec     b               ; Test negative sign
  5288.         exx
  5289.         call    z,l0a8f         ; Negate if so
  5290.         exx
  5291.         jp      l05d1           ; Save real number
  5292. ;
  5293. ; Get string from input READ(string[max])
  5294. ; ENTRY Reg HL points to string variable
  5295. ;       Reg B holds max characters in string
  5296. ;
  5297. l168e:
  5298.         push    hl              ; Save pointer
  5299.         ex      de,hl
  5300.         ld      c,0             ; Clear character count
  5301. l1692:
  5302.         push    bc
  5303.         push    de
  5304.         call    l156b           ; Get character
  5305.         pop     de
  5306.         pop     bc
  5307.         cp      cr              ; Test end of line
  5308.         jr      z,l16a8
  5309.         cp      eof             ; Test end of file
  5310.         jr      z,l16a8
  5311.         res     wr.bit,(hl)     ; Reset preread
  5312.         inc     c               ; Advance count
  5313.         inc     de              ; Advance pointer
  5314.         ld      (de),a
  5315.         djnz    l1692
  5316. l16a8:
  5317.         pop     hl              ; Get back pointer
  5318.         ld      (hl),c          ; Set length
  5319.         ret
  5320. ;
  5321. ; Handle end of line after READLN from file
  5322. ;
  5323. l16ab:
  5324.         call    l156b           ; Get character
  5325.         cp      eof             ; Test end of file
  5326.         jr      z,l16c5
  5327.         res     wr.bit,(hl)     ; Reset preread
  5328.         cp      lf              ; Test new line
  5329.         jr      z,l16c5
  5330.         cp      cr              ; Wait for end of line
  5331.         jr      nz,l16ab
  5332.         call    l156b
  5333.         cp      lf              ; Maybe new line
  5334.         jr      nz,l16c5
  5335.         res     wr.bit,(hl)     ; Reset preread if so
  5336. l16c5:
  5337.         ret
  5338. ;
  5339. ; Output character to device
  5340. ; ENTRY Accu holds character
  5341. ;
  5342. l16c6:
  5343.         ld      hl,(l00e2)      ; Get FIB
  5344.         ld      c,a             ; Save character
  5345.         ld      a,(l00d0)
  5346.         or      a               ; Test I/O error
  5347.         ret     nz              ; Exit if so
  5348.         ld      a,(hl)          ; Get type
  5349.         and     FIBtype         ; Test device
  5350.         jr      nz,l16e4        ; Yeap
  5351.         inc     hl              ; Point to sector buffer
  5352.         inc     hl
  5353.         push    hl
  5354.         ld      a,(hl)          ; Get pointer
  5355.         add     a,FIB.buff-2
  5356.         ld      e,a
  5357.         ld      d,0
  5358.         add     hl,de           ; Make pointer absolute
  5359.         ld      (hl),c          ; Save character
  5360.         pop     hl
  5361.         inc     (hl)            ; Advance count
  5362.         ret     p               ; Still in range
  5363.         jr      l170c           ; Write record
  5364. l16e4:
  5365.         cp      RAMdevice       ; Test store to RAM
  5366.         jr      z,l16fd         ; Yeap
  5367.         pop     hl
  5368.         ld      b,0
  5369.         push    bc
  5370.         push    hl
  5371.         dec     a               ; 1=CON:
  5372.         jp      z,l00a6         ; Put to console
  5373.         dec     a               ; 3=LST:
  5374.         dec     a
  5375.         jp      z,l00a9         ; Put to printer
  5376.         dec     a               ; 4=AUX:
  5377.         jp      z,l00ac         ; Put to auxiliary
  5378.                                 ; 5=USR:
  5379.         jp      l00b2           ; Put to console
  5380. l16fd:
  5381.         ld      hl,(l00e8)      ; Get string pointer
  5382.         ld      a,(l00ea)       ; Get max length
  5383.         cp      (hl)            ; Test in range
  5384.         ret     z               ; Nope, exit
  5385.         inc     (hl)            ; Bump count
  5386.         ld      e,(hl)
  5387.         ld      d,0
  5388.         add     hl,de           ; Build address
  5389.         ld      (hl),c          ; Store character
  5390.         ret
  5391. ;
  5392. ; Write sector to file if any item in buffer
  5393. ;
  5394. l170c:
  5395.         ld      hl,(l00e2)      ; Get FIB
  5396.         inc     hl
  5397.         inc     hl
  5398.         ld      a,(hl)          ; Get record pointer
  5399.         or      a               ; Test any in buffer
  5400.         ret     z               ; Nope, exit
  5401.         ld      (hl),0          ; Clear pointer
  5402.         ld      c,_wrseq
  5403.         call    l19ba           ; Write record
  5404.         ret     z               ; Ok, no errr
  5405.         ld      a,_WrErr
  5406.         ld      (l00d0),a       ; Set error
  5407.         ret
  5408. ;
  5409. ; Write character to device
  5410. ; WRITE(char)
  5411. ; ENTRY Reg L holds character
  5412. ;
  5413. l1722:
  5414.         ld      a,l             ; Get character
  5415.         jp      l16c6           ; Put it
  5416. ;
  5417. ; Write integer to device
  5418. ; WRITE(int)
  5419. ; WRITE(int:m)
  5420. ; ENTRY Integer on stack
  5421. ;       Reg HL holds digit count (zero without count)
  5422. ;
  5423. l1726:
  5424.         pop     bc
  5425.         pop     de
  5426.         push    bc
  5427.         ld      ix,(l00d2)      ; Get top of memory for buffer
  5428.         bit     sgn.bit,h       ; Test sign of count
  5429.         jr      z,l1737         ; >= 0
  5430.         call    l0783           ; Negate
  5431.         ex      de,hl           ; Swap values
  5432.         jr      l1745
  5433. l1737:
  5434.         ex      de,hl
  5435.         bit     sgn.bit,h       ; Test sign of number
  5436.         jr      z,l1745         ; >= 0
  5437.         call    l0783           ; Negate
  5438.         ld      (ix),'-'        ; Init sign
  5439.         inc     ix
  5440. l1745:
  5441.         push    de
  5442.         call    l07c6           ; Convert integer to ASCII
  5443. l1749:
  5444.         pop     hl
  5445.         call    l04c8           ; Get byte from integer
  5446.         ld      de,(l00d2)      ; Get back top of memory
  5447.         push    ix
  5448.         pop     hl
  5449.         or      a
  5450.         sbc     hl,de           ; Calculate length of string
  5451.         ld      c,l
  5452.         ex      de,hl
  5453. l1759:
  5454.         sub     c               ; Test against count
  5455.         jr      c,l176a         ; Ignore if out of range
  5456.         jr      z,l176a
  5457.         ld      b,a             ; Save count
  5458.         push    hl
  5459. l1760:
  5460.         ld      a,' '
  5461.         push    bc
  5462.         call    l16c6           ; Blank leading places
  5463.         pop     bc
  5464.         djnz    l1760
  5465.         pop     hl
  5466. l176a:
  5467.         ld      b,c             ; Get back length
  5468.         inc     b
  5469. l176c:
  5470.         dec     b
  5471.         ret     z
  5472.         ld      a,(hl)
  5473.         push    bc
  5474.         push    hl
  5475.         call    l16c6           ; Type digits
  5476.         pop     hl
  5477.         pop     bc
  5478.         inc     hl
  5479.         jr      l176c
  5480. ;
  5481. ; Formatted write
  5482. ; WRITE(real)
  5483. ; WRITE(real:n)
  5484. ; WRITE(real:n:m)
  5485. ; ENTRY Reg HL holds fix comma places (-1 on none)
  5486. ;       Stack holds decimal places and real
  5487. ;       (Without decimal places defaults to 24)
  5488. ;
  5489. l1779:
  5490.         pop     bc
  5491.         pop     de              ; Get places
  5492.         exx
  5493.         pop     hl              ; Get number
  5494.         pop     de
  5495.         pop     bc
  5496.         exx
  5497.         push    bc
  5498.         ld      ix,(l00d2)      ; Get top of memory for buffer
  5499.         push    de
  5500.         call    l1027           ; Convert real to ASCII
  5501.         jr      l1749
  5502. ;
  5503. ; Boolean write
  5504. ; WRITE(bool)
  5505. ; WRITE(bool:m)
  5506. ; ENTRY Reg HL holds places (0 on none)
  5507. ;       Stack holds boolean
  5508. ;
  5509. l178b:
  5510.         pop     bc
  5511.         pop     de              ; Get boolean
  5512.         push    bc
  5513.         call    l04c8           ; Get byte from integer
  5514.         bit     _LB,e           ; Test bit
  5515.         ld      hl,l17a1
  5516.         ld      c,l17a1.l
  5517.         jr      nz,l1759        ; It is TRUE
  5518.         ld      hl,l17a5
  5519.         ld      c,l17a5.l
  5520.         jr      l1759           ; Tell FALSE
  5521. ;
  5522. l17a1:
  5523.         db      'TRUE'
  5524. l17a1.l equ     $-l17a1
  5525. l17a5:
  5526.         db      'FALSE'
  5527. l17a5.l equ     $-l17a5
  5528. ;
  5529. ; String and formatted character write
  5530. ; WRITE(string)
  5531. ; WRITE(string:m)
  5532. ; WRITE(char:m)
  5533. ; ENTRY Reg HL holds places (0 on none)
  5534. ;       Stack holds string (chracter=string with length=1)
  5535. ;
  5536. l17aa:
  5537.         call    l04c8           ; Get byte from integer for places
  5538.         ld      hl,2
  5539.         add     hl,sp           ; Fix stack
  5540.         ld      c,(hl)          ; Get length
  5541.         inc     hl
  5542.         call    l1759           ; Print right justified
  5543.         pop     de              ; Get back caller
  5544.         ld      sp,hl           ; Reset stack
  5545.         push    de
  5546.         ret
  5547. ;
  5548. ; Immediate string write
  5549. ; WRITE('string')
  5550. ; ENTRY Stack holds string starting with length
  5551. ;
  5552. l17ba:
  5553.         pop     hl              ; Get pointer to string
  5554.         ld      a,(hl)          ; Get length
  5555.         inc     hl
  5556.         or      a               ; Test any
  5557.         jr      z,l17cc
  5558.         ld      b,a             ; save length if so
  5559. l17c1:
  5560.         ld      a,(hl)          ; Get character
  5561.         push    bc
  5562.         push    hl
  5563.         call    l16c6           ; Write it
  5564.         pop     hl
  5565.         pop     bc
  5566.         inc     hl
  5567.         djnz    l17c1
  5568. l17cc:
  5569.         jp      (hl)
  5570. ;
  5571. ; Give new line
  5572. ; WRITELN{...}
  5573. ;
  5574. l17cd:
  5575.         ld      a,cr
  5576.         call    l16c6           ; Give return
  5577.         ld      a,lf
  5578.         jp      l16c6           ; Followed by line feed
  5579. ;
  5580. ; The logical delimiter functions
  5581. ; Function SEEKEOLN(device):boolean
  5582. ; ENTRY Reg HL points to FIB
  5583. ; EXIT  Reg HL holds TRUE or FALSE
  5584. ;
  5585. l17d7:
  5586.         ld      de,1*256+cr     ; Set CR
  5587.         jr      l17e9
  5588. ;
  5589. ; Function EOLN(device):boolean
  5590. ;
  5591. l17dc:
  5592.         ld      de,cr
  5593.         jr      l17e9
  5594. ;
  5595. ; Function SEEKEOF(device):boolean
  5596. ;
  5597. l17e1:
  5598.         ld      de,1*256+eof    ; Set EOF
  5599.         jr      l17e9
  5600. ;
  5601. ; Function EOF(device):boolean
  5602. ;
  5603. l17e6::
  5604.         ld      de,eof
  5605. l17e9:
  5606.         ld      (l00e2),hl      ; Set device
  5607.         bit     in.bit,(hl)     ; Test input possible
  5608.         jr      z,l180c         ; Nope
  5609. l17f0:
  5610.         push    de
  5611.         call    l156b           ; Get character
  5612.         pop     de
  5613.         cp      e               ; Test end found
  5614.         jr      z,l1808         ; Yeap
  5615.         cp      eof             ; Test end of file
  5616.         jr      z,l1808         ; Force TRUE if so
  5617.         cp      ' '+1           ; Test control
  5618.         jr      nc,l180c        ; Nope
  5619.         inc     d               ; Test control to be checked
  5620.         dec     d
  5621.         jr      z,l180c         ; Yeap
  5622.         res     wr.bit,(hl)     ; Reset preread
  5623.         jr      l17f0
  5624. l1808:
  5625.         ld      hl,_TRUE        ; Return TRUE
  5626.         ret
  5627. l180c:
  5628.         ld      hl,FALSE        ; Return FALSE
  5629.         ret
  5630. ;
  5631. ; Prepare typed files
  5632. ; Procedure REWRITE(typed_file)
  5633. ; ENTRY Reg HL points to FIB
  5634. ;       Reg DE holds length of record
  5635. ;
  5636. l1810:
  5637.         db      skip
  5638. ;
  5639. ; Procedure RESET(typed_file)
  5640. ;
  5641. l1811:
  5642.         xor     a
  5643.         ld      (l00e8),a       ; Set mode (0=RESET)
  5644.         ld      (l00e6),de      ; Save record length
  5645.         call    l187a           ; Close file
  5646.         ld      a,(l00d0)       ; Test error
  5647.         or      a
  5648.         ret     nz              ; End if so
  5649.         call    l1430           ; Set up FIB
  5650.         ld      a,(l00d0)       ; Test error
  5651.         or      a
  5652.         ret     nz              ; End if so
  5653.         ld      hl,(l00e2)      ; Init FIB flag
  5654.         ld      (hl),_.in+_.out+_.read
  5655.         inc     hl
  5656.         inc     hl
  5657.         ld      (hl),a          ; Init record pointer
  5658.         ld      de,FIB.cur-2
  5659.         add     hl,de           ; Point to current record
  5660.         ld      (hl),a          ; Clear it
  5661.         inc     hl
  5662.         ld      (hl),a
  5663.         ld      de,FIB.FCB+_rrn-FIB.cur-1
  5664.         add     hl,de           ; Point to random record
  5665.         ld      (hl),a          ; Clear it
  5666.         inc     hl
  5667.         ld      (hl),a
  5668.         ld      de,FIB.rec-FIB.FCB-_rrn-1
  5669.         add     hl,de           ; Point to FIB record
  5670.         ld      a,(l00e8)
  5671.         or      a               ; Test mode
  5672.         jr      nz,l1864        ; Skip RESET
  5673. ;
  5674. ; Perform RESET
  5675. ;
  5676.         push    hl
  5677.         ld      bc,FixRecLen    ; Set four bytes
  5678.         xor     a
  5679.         call    l1909           ; Prepare read
  5680.         pop     hl
  5681.         inc     hl
  5682.         inc     hl
  5683.         ld      c,(hl)          ; Point to max records
  5684.         inc     hl
  5685.         ld      b,(hl)
  5686.         ld      hl,(l00e6)
  5687.         or      a
  5688.         sbc     hl,bc           ; Test agianst tem in file
  5689.         ret     z               ; Correct value
  5690.         ld      a,_InvRec
  5691.         ld      (l00d0),a       ; Set error
  5692.         ret
  5693. ;
  5694. ; Perform REWRITE
  5695. ;
  5696. l1864:
  5697.         push    hl
  5698.         xor     a
  5699.         ld      (hl),a          ; Clear record
  5700.         inc     hl
  5701.         ld      (hl),a
  5702.         inc     hl
  5703.         ld      de,(l00e6)      ; Fetch length
  5704.         ld      (hl),e          ; Store into FIB
  5705.         inc     hl
  5706.         ld      (hl),d
  5707.         pop     hl
  5708.         ld      bc,FixRecLen
  5709.         ld      a,Rec.New+Rec.Wr
  5710.         jp      l1909           ; Prepare write
  5711. ;
  5712. ; Procedure CLOSE(typed_file)
  5713. ; ENTRY Reg HL points to FIB
  5714. ;
  5715. l187a:
  5716.         ld      (l00e2),hl      ; Save FIB
  5717.         ld      a,(hl)          ; Get state
  5718.         and     _.in+_.out      ; Test any action
  5719.         ret     z               ; Nope
  5720.         call    l19ae           ; Write record if requested
  5721.         ld      hl,(l00e2)      ; Get FIB
  5722.         ld      de,FIB.FCB+_rrn
  5723.         add     hl,de           ; Point to random recird
  5724.         xor     a
  5725.         ld      (hl),a          ; Clear it
  5726.         inc     hl
  5727.         ld      (hl),a
  5728.         ld      de,-FIB.FCB-_rrn+1
  5729.         add     hl,de           ; Point to record
  5730.         ld      (hl),a          ; Clear it
  5731.         inc     hl
  5732.         inc     hl
  5733.         ld      bc,FixRecLen
  5734.         ld      a,Rec.Wr
  5735.         call    l1909           ; Prepare write
  5736.         call    l19ae           ; Write if requested
  5737.         jp      l1481           ; Close file
  5738. ;
  5739. ; Prepare write to record file
  5740. ; ENTRY Reg HL points to FIB
  5741. ;
  5742. l18a4:
  5743.         ex      (sp),hl
  5744.         ld      (l00e4),hl      ; Save caller
  5745.         ex      (sp),hl
  5746.         ld      (l00e2),hl      ; Save FIB
  5747.         ld      a,(hl)
  5748.         and     _.in+_.out      ; Test I/O allowed
  5749.         ret     nz              ; Yeap
  5750. l18b0:
  5751.         ld      a,_BlkErr
  5752.         ld      (l00d0),a       ; Set error
  5753.         ret
  5754. ;
  5755. ; Get structure from input READ(type)
  5756. ; ENTRY Reg HL points to FIB
  5757. ;
  5758. l18b6:
  5759.         ld      a,(l00d0)       ; Get error
  5760.         or      a               ; Test previous
  5761.         ret     nz              ; Yeap
  5762.         push    hl
  5763.         call    l1a5a           ; Get record data
  5764.         ex      de,hl
  5765.         or      a
  5766.         sbc     hl,de           ; Test against last record
  5767.         pop     hl
  5768.         jr      nc,l18d6        ; Error
  5769.         xor     a
  5770.         call    l1909           ; Read
  5771. l18ca:
  5772.         ld      hl,(l00e2)      ; Get back FIB
  5773.         ld      de,FIB.cur
  5774.         add     hl,de
  5775.         inc     (hl)            ; Bump record
  5776.         ret     nz
  5777.         inc     hl
  5778.         inc     (hl)
  5779.         ret
  5780. l18d6:
  5781.         ld      a,_IllEOF
  5782.         ld      (l00d0),a       ; Set error
  5783.         ret
  5784. ;
  5785. ; Put structure to output WRITE(type)
  5786. ; ENTRY Reg HL points to FIB
  5787. ;
  5788. l18dc:
  5789.         ld      a,(l00d0)       ; Get error
  5790.         or      a               ; Test previous
  5791.         ret     nz              ; Yeap
  5792.         push    hl
  5793.         call    l1a5a           ; Get record data
  5794.         or      a
  5795.         sbc     hl,de           ; Test same size
  5796.         ld      a,Rec.Wr
  5797.         jr      nz,l18fc
  5798.         ld      hl,(l00e2)
  5799.         ld      de,FIB.rec
  5800.         add     hl,de           ; Point to record
  5801.         inc     (hl)            ; Bump it
  5802.         jr      nz,l18fa
  5803.         inc     hl
  5804.         inc     (hl)
  5805.         jr      z,l1902         ; Overflow error
  5806. l18fa:
  5807.         ld      a,Rec.New+Rec.Wr
  5808. l18fc:
  5809.         pop     hl
  5810.         call    l1909           ; Execute write
  5811.         jr      l18ca
  5812. l1902:
  5813.         pop     hl
  5814.         ld      a,_OvflErr
  5815.         ld      (l00d0),a       ; Set error
  5816.         ret
  5817. ;
  5818. ; Perform record IO
  5819. ; ENTRY Reg HL points to FIB record field
  5820. ;       Reg BC holds record length
  5821. ;       (Four on CLOSE, RESET and REWRITE)
  5822. ;       Accu holds code :
  5823. ;               0 : On RESET and READ
  5824. ;               1 : On CLOSE and WRITE
  5825. ;               3 : On WRITE and REWRITE
  5826. ;
  5827. l1909:
  5828.         ld      (l00e9),a       ; Save code
  5829.         ex      de,hl
  5830. l190d:
  5831.         ld      hl,(l00e2)      ; Get FIB
  5832.         bit     rd.bit,(hl)     ; Test known buffer
  5833.         jr      z,l1943         ; Nope
  5834.         res     rd.bit,(hl)     ; Reset bit
  5835.         ld      a,(l00e9)       ; Get mode
  5836.         bit     Rec.Wr.bit,a    ; Test write
  5837.         jr      z,l1935         ; Nope, so read
  5838.         inc     hl
  5839.         inc     hl
  5840.         ld      a,(hl)          ; Get record pointer
  5841.         dec     hl
  5842.         dec     hl
  5843.         or      a
  5844.         jr      nz,l1935        ; Not empty, so read
  5845.         ld      a,(l00e9)       ; Get code
  5846.         bit     Rec.New.bit,a   ; Test new
  5847.         jr      nz,l1943        ; Yeap
  5848.         ld      a,b             ; Get counter
  5849.         or      a
  5850.         jr      nz,l1943
  5851.         ld      a,c             ; Test new
  5852.         or      a
  5853.         jp      m,l1943
  5854. l1935:
  5855.         push    bc
  5856.         push    de
  5857.         ld      c,_rndrd
  5858.         call    l19ba           ; Read record
  5859.         pop     de
  5860.         pop     bc
  5861.         jr      nz,l1991        ; Error return
  5862.         ld      hl,(l00e2)      ; Get back FIB
  5863. l1943:
  5864.         ld      a,(l00e9)       ; Get mode
  5865.         bit     Rec.Wr.bit,a    ; Test write allowed
  5866.         jr      z,l194c         ; Nope
  5867.         set     wr.bit,(hl)     ; Set bit
  5868. l194c:
  5869.         inc     hl
  5870.         inc     hl
  5871.         ld      a,(hl)          ; Get pointer to buffer
  5872.         add     a,FIB.buff-2
  5873.         push    de
  5874.         ld      e,a
  5875.         ld      d,0
  5876.         add     hl,de           ; Get address of buffer
  5877.         pop     de
  5878.         sub     FIB.buff-2      ; Reset pointer
  5879.         call    l199a           ; Swap pointer
  5880. l195c:
  5881.         ldi                     ; move bytes
  5882.         jp      po,l1966        ; Test done
  5883.         inc     a               ; Bump pointer
  5884.         jp      p,l195c         ; Test done
  5885.         dec     a
  5886. l1966:
  5887.         inc     a
  5888.         call    l199a           ; Swap back
  5889.         ld      hl,(l00e2)      ; Get FIB
  5890.         inc     hl
  5891.         inc     hl
  5892.         and     NOMSB           ; Test remainder in buffer
  5893.         ld      (hl),a
  5894.         jr      nz,l198a        ; Yeap
  5895.         push    bc
  5896.         push    de
  5897.         push    hl
  5898.         call    l19ae           ; Write record
  5899.         pop     hl
  5900.         pop     de
  5901.         pop     bc
  5902.         jr      nz,l1994        ; Error return
  5903.         push    de
  5904.         ld      de,FIB.FCB+_rrn-2
  5905.         add     hl,de           ; Point to record
  5906.         pop     de
  5907.         inc     (hl)            ; Advance it
  5908.         jr      nz,l198a
  5909.         inc     hl
  5910.         inc     (hl)
  5911. l198a:
  5912.         ld      a,b             ; Test all done
  5913.         or      c
  5914.         jp      nz,l190d        ; Nope
  5915.         ex      de,hl
  5916.         ret
  5917. l1991:
  5918.         ld      a,_IllEOF
  5919.         db      skip.2
  5920. l1994:
  5921.         ld      a,_WrErr
  5922.         ld      (l00d0),a       ; Set error
  5923.         ret
  5924. ;
  5925. ; Swap record pointers on request
  5926. ; ENTRY Reg HL and DE hold pointer
  5927. ; EXIT  Register swapped on write selected
  5928. ;
  5929. l199a:
  5930.         push    af
  5931.         ld      a,(l00e9)       ; Get mode
  5932.         bit     Rec.Wr.bit,a    ; Test selection
  5933.         jr      z,l19a3
  5934.         ex      de,hl           ; Swap
  5935. l19a3:
  5936.         pop     af
  5937.         ret
  5938. ;
  5939. ; Force record write
  5940. ; Procedure FLUSH(type)
  5941. ; ENTRY Reg HL holds FIB
  5942. ;
  5943. l19a5:
  5944.         ld      (l00e2),hl      ; Save FIB
  5945.         call    l19ae           ; Write if possible
  5946.         ret     z
  5947.         jr      l1994           ; Set error
  5948. ;
  5949. ; Write random record if select, set read
  5950. ;
  5951. l19ae:
  5952.         ld      c,_rndwr        ; Set OS function
  5953.         ld      hl,(l00e2)      ; Get FIB
  5954.         set     rd.bit,(hl)     ; Set read bit
  5955.         bit     wr.bit,(hl)     ; Test write
  5956.         ret     z               ; Nope
  5957.         res     wr.bit,(hl)     ; Reset and write
  5958. ;
  5959. ; Execute file function
  5960. ; ENTRY Reg C holds file function
  5961. ; EXIT  Zero flag reflects state of function
  5962. ;       Accu holds BDOS code
  5963. ;
  5964. l19ba:
  5965.         ld      hl,(l00e2)      ; Load FIB
  5966.         push    hl
  5967.         push    bc
  5968.         ld      de,FIB.buff
  5969.         add     hl,de           ; Point to buffer
  5970.         ex      de,hl
  5971.         ld      c,_setdma
  5972.         call    BDOS            ; Set disk buffer
  5973.         pop     bc
  5974.         pop     hl
  5975.         ld      de,FIB.FCB
  5976.         add     hl,de           ; Point to FCB
  5977.         ex      de,hl
  5978.         call    BDOS            ; Execute OS function
  5979.         or      a               ; Build result
  5980.         ret
  5981. ;
  5982. ; Procedure SEEK(file,record)
  5983. ; ENTRY Reg HL holds record seeked for
  5984. ;       FIB pushed onto stack
  5985. ;
  5986. l19d5:
  5987.         pop     bc
  5988.         pop     de
  5989.         ld      (l00e2),de      ; Save FIB
  5990.         push    bc
  5991.         push    hl
  5992.         call    l1a5a           ; Get FIB data
  5993.         pop     de
  5994.         or      a
  5995.         sbc     hl,de           ; Test record less size
  5996.         jr      c,l1a26         ; Error if so
  5997.         ld      hl,(l00e2)      ; Get FIB
  5998.         ld      bc,FIB.reclen   ; Point to length of record
  5999.         add     hl,bc
  6000.         ld      c,(hl)          ; Get record
  6001.         inc     hl
  6002.         ld      b,(hl)
  6003.         inc     hl
  6004.         ld      (hl),e          ; Save record number
  6005.         inc     hl
  6006.         ld      (hl),d
  6007.         call    l1a2c           ; Multiply it
  6008.         ld      bc,FixRecLen
  6009.         add     hl,bc           ; Adjust for header
  6010.         jr      nc,l19fe
  6011.         inc     de
  6012. l19fe:
  6013.         ld      a,l
  6014.         and     NOMSB           ; Get record pointer
  6015.         add     hl,hl           ; * 2
  6016.         ex      de,hl
  6017.         adc     hl,hl
  6018.         ex      de,hl
  6019.         ld      d,e             ; / 256
  6020.         ld      e,h
  6021.         ld      hl,(l00e2)      ; Get FIB
  6022.         inc     hl
  6023.         inc     hl
  6024.         ld      (hl),a          ; Store record pointer
  6025.         ld      bc,FIB.FCB+_rrn-2
  6026.         add     hl,bc           ; Point to random record
  6027.         ld      c,(hl)          ; Get it
  6028.         inc     hl
  6029.         ld      b,(hl)
  6030.         ex      de,hl
  6031.         or      a
  6032.         sbc     hl,bc           ; Test record already set
  6033.         add     hl,bc
  6034.         ret     z               ; Yeap
  6035.         push    de
  6036.         push    hl
  6037.         call    l19ae           ; Write record
  6038.         pop     de
  6039.         pop     hl
  6040.         ld      (hl),d          ; Set current record
  6041.         dec     hl
  6042.         ld      (hl),e
  6043.         ret
  6044. l1a26:
  6045.         ld      a,_SeekEOF
  6046.         ld      (l00d0),a       ; Set error
  6047.         ret
  6048. ;
  6049. ; Multiply record number by record length
  6050. ; ENTRY Reg BC holds length of record
  6051. ;       Reg DE holds number of record
  6052. ; EXIT  Reg HL holds the product of both
  6053. ;
  6054. l1a2c:
  6055.         push    de              ; Copy number
  6056.         exx
  6057.         pop     hl              ; Get copy
  6058.         exx
  6059.         ld      hl,0            ; Init result
  6060.         ld      d,h
  6061.         ld      e,l
  6062.         ld      a,16            ; Set bit length
  6063. l1a37:
  6064.         add     hl,hl           ; Shift result
  6065.         ex      de,hl
  6066.         adc     hl,hl           ; Treat as 32 bit number
  6067.         ex      de,hl
  6068.         exx
  6069.         add     hl,hl           ; Shift number
  6070.         exx
  6071.         jr      nc,l1a45
  6072.         add     hl,bc           ; Fix for carry
  6073.         jr      nc,l1a45
  6074.         inc     de
  6075. l1a45:
  6076.         dec     a
  6077.         jr      nz,l1a37        ; Loop on
  6078.         ret
  6079. ;
  6080. ; Function EOF(device):boolean (untyped)
  6081. ;
  6082. l1a49::
  6083.         call    l1a5d           ; Get size of file
  6084.         or      a
  6085.         sbc     hl,de           ; Test end
  6086.         ld      hl,FALSE
  6087.         ret     nz              ; Return FALSE if not
  6088.         inc     hl              ; Fix for TRUE
  6089.         ret
  6090. ;
  6091. ; Get record position of file
  6092. ; Function FILEPOS(file):integer
  6093. ; ENTRY Reg HL holds FIB
  6094. ; EXIT  Reg HL holds current record
  6095. ;
  6096. l1a55:
  6097.         call    l1a5d           ; Get size of file
  6098.         ex      de,hl           ; Into integer result
  6099.         ret
  6100. ;
  6101. ; Get record data of file
  6102. ; EXIT  Reg HL holds size of file
  6103. ;       Reg DE holds current record
  6104. ;       Reg BC holds record length
  6105. ;
  6106. l1a5a:
  6107.         ld      hl,(l00e2)      ; Load FIB
  6108. ;
  6109. ; Get size of file
  6110. ; Function FILESIZE(file):integer
  6111. ; ENTRY Reg HL holds FIB
  6112. ; EXIT  Reg HL holds size of file in terms of records
  6113. ;       Reg DE holds current record
  6114. ;       Reg BC holds length of record
  6115. ;
  6116. l1a5d:
  6117.         ld      de,FIB.rec
  6118.         add     hl,de           ; Point to records
  6119.         ld      e,(hl)          ; Get number of records
  6120.         inc     hl
  6121.         ld      d,(hl)
  6122.         inc     hl
  6123.         push    de
  6124.         ld      c,(hl)          ; Get record length
  6125.         inc     hl
  6126.         ld      b,(hl)
  6127.         inc     hl
  6128.         ld      e,(hl)          ; Get current record
  6129.         inc     hl
  6130.         ld      d,(hl)
  6131.         pop     hl
  6132.         ret
  6133. ;
  6134. ; Prepare untyped files
  6135. ; Procedure REWRITE(un_typed_file)
  6136. ; ENTRY Reg HL points to FIB
  6137. ;
  6138. l1a6f:
  6139.         db      skip
  6140. ;
  6141. ; Procedure RESET(un_typed_file)
  6142. ;
  6143. l1a70:
  6144.         xor     a
  6145.         ld      (l00e8),a       ; Save mode (0=RESET)
  6146.         call    l1ab0           ; Close open file
  6147.         ld      a,(l00d0)
  6148.         or      a               ; Test error
  6149.         ret     nz              ; Exit if so
  6150.         call    l1430           ; Fix FIB
  6151.         ld      a,(l00d0)
  6152.         or      a               ; Test error
  6153.         ret     nz              ; Exit if so
  6154.         ld      hl,(l00e2)      ; Get FIB
  6155.         ld      (hl),_.in+_.out ; Set flag
  6156.         push    hl
  6157.         ld      de,FIB.FCB
  6158.         add     hl,de           ; Point to FCB
  6159.         ex      de,hl
  6160.         ld      c,_filsiz
  6161.         call    BDOS            ; Get size of file
  6162.         pop     hl
  6163.         ld      de,FIB.FCB+_rrn
  6164.         add     hl,de           ; Point to size
  6165.         xor     a
  6166.         ld      c,(hl)          ; Get size
  6167.         ld      (hl),a          ; Reset size
  6168.         inc     hl
  6169.         ld      b,(hl)
  6170.         ld      (hl),a
  6171.         ld      de,FIB.rec-FIB.FCB-_rrn-1
  6172.         add     hl,de           ; Point to recird number
  6173.         ld      (hl),c          ; Set it
  6174.         inc     hl
  6175.         ld      (hl),b
  6176.         inc     hl
  6177.         ld      (hl),RecLng     ; Set standard record
  6178.         inc     hl
  6179.         ld      (hl),a
  6180.         inc     hl
  6181.         ld      (hl),a          ; Init current record
  6182.         inc     hl
  6183.         ld      (hl),a
  6184.         ret
  6185. ;
  6186. ; Close untyped file
  6187. ; ENTRY Reg HL holds FIB
  6188. ;
  6189. ; Procedure CLOSE(un_typed_file)
  6190. ;
  6191. l1ab0:
  6192.         ld      (l00e2),hl      ; Save FIB
  6193.         ld      a,(hl)          ; Get mode
  6194.         and     _.in+_.out      ; Test access
  6195.         ret     z               ; Nope
  6196.         jp      l1481           ; Close it
  6197. ;
  6198. ; Write block to untyped file
  6199. ; Procedure BLOCKWRITE(file,buffer,count)
  6200. ; ENTRY Reg HL holds number of records to be written
  6201. ;       On stack FIB and buffer
  6202. ;
  6203. l1aba:
  6204.         ld      a,_rndwr        ; Set function code
  6205.         jr      l1ac0
  6206. ;
  6207. ; Read block from untyped file
  6208. ; Procedure BLOCKREAD(file,buffer,count)
  6209. ; ENTRY Reg HL holds number of records to be read
  6210. ;       On stack FIB and buffer
  6211. ;
  6212. l1abe:
  6213.         ld      a,_rndrd        ; Set function code
  6214. l1ac0:
  6215.         ld      b,h             ; Copy count
  6216.         ld      c,l
  6217.         ld      hl,l00f0        ; Point to scratch
  6218.         ld      (l00e6),hl      ; Set for record
  6219.         pop     ix
  6220.         pop     de              ; Get buffer
  6221.         pop     hl              ; Get FIB
  6222.         push    ix
  6223.         push    bc
  6224.         call    l1afd           ; Execute block I/O
  6225.         pop     bc
  6226.         ld      a,(l00d0)
  6227.         or      a               ; Test error
  6228.         ret     nz              ; Exit if so
  6229.         ld      hl,(l00f0)
  6230.         sbc     hl,bc           ; Test all records processed
  6231.         ret     z               ; Yeap
  6232.         ld      a,(l00e9)       ; Get file function
  6233.         cp      _rndrd          ; Test read
  6234.         ld      a,_IllEOF
  6235.         jr      z,l1ae9
  6236.         ld      a,_WrErr
  6237. l1ae9:
  6238.         ld      (l00d0),a       ; Set error code accordingly
  6239.         ret
  6240. ;
  6241. ; Write block to untyped file
  6242. ; Procedure BLOCKWRITE(file,buffer,count,result)
  6243. ; ENTRY Reg HL points to result
  6244. ;       On stack FIB, buffer and number of records
  6245. ;
  6246. l1aed:
  6247.         ld      a,_rndwr        ; Set function
  6248.         jr      l1af3
  6249. ;
  6250. ; Rad block from untyped file
  6251. ; Procedure BLOCKREAD(file,buffer,count,result)
  6252. ; ENTRY Reg HL points to result
  6253. ;       On stack FIB, buffer and number of records
  6254. ;
  6255. l1af1:
  6256.         ld      a,_rndrd        ; Set function
  6257. l1af3:
  6258.         ld      (l00e6),hl      ; Save result pointer
  6259.         pop     ix
  6260.         pop     bc              ; Get count
  6261.         pop     de              ; Get buffer
  6262.         pop     hl              ; Get FIB
  6263.         push    ix
  6264. ;
  6265. ; Perform block IO
  6266. ; ENTRY Accu holds file function
  6267. ;       Reg HL holds FIB
  6268. ;       Reg DE holds buffer
  6269. ;
  6270. l1afd:
  6271.         ld      (l00e9),a       ; Save function
  6272.         ld      (l00e2),hl      ; Save FIB
  6273.         ld      a,(hl)          ; Get mode
  6274.         and     _.in+_.out      ; Test IO allowed
  6275.         jp      z,l18b0         ; Nope
  6276.         ld      hl,(l00e6)      ; Get record address
  6277.         xor     a
  6278.         ld      (hl),a          ; Clear record
  6279.         inc     hl
  6280.         ld      (hl),a
  6281. l1b10:
  6282.         ld      a,b
  6283.         or      c               ; Test all done
  6284.         jr      z,l1b4d         ; Yeap
  6285.         push    bc
  6286.         push    de
  6287.         ld      c,_setdma
  6288.         call    BDOS            ; Set disk buffer
  6289.         ld      hl,(l00e2)      ; Get back FIB
  6290.         ld      de,FIB.FCB
  6291.         add     hl,de           ; Point to FCB
  6292.         ex      de,hl
  6293.         ld      a,(l00e9)       ; Get file function
  6294.         ld      c,a
  6295.         call    BDOS            ; Execute I/O
  6296.         pop     de
  6297.         pop     bc
  6298.         or      a               ; Test result
  6299.         jr      nz,l1b4d        ; Not good
  6300.         push    de
  6301.         ld      hl,(l00e2)      ; Get FIB again
  6302.         ld      de,FIB.FCB+_rrn
  6303.         add     hl,de           ; Point to record
  6304.         inc     (hl)            ; Advance record
  6305.         jr      nz,l1b3c
  6306.         inc     hl
  6307.         inc     (hl)
  6308. l1b3c:
  6309.         pop     de
  6310.         ld      hl,RecLng
  6311.         add     hl,de           ; Advance buffer
  6312.         ex      de,hl
  6313.         ld      hl,(l00e6)
  6314.         inc     (hl)            ; Advance record count
  6315.         jr      nz,l1b4a
  6316.         inc     hl
  6317.         inc     (hl)
  6318. l1b4a:
  6319.         dec     bc              ; Count down requested length
  6320.         jr      l1b10
  6321. l1b4d:
  6322.         ld      hl,(l00e2)      ; Get FIB
  6323.         ld      de,FIB.FCB+_rrn
  6324.         add     hl,de           ; Point to last record
  6325.         ld      c,(hl)
  6326.         inc     hl
  6327.         ld      b,(hl)
  6328.         ld      de,FIB.cur-FIB.FCB-_rrn-1
  6329.         add     hl,de           ; Point to FIB record
  6330.         ld      (hl),c          ; Save record number
  6331.         inc     hl
  6332.         ld      (hl),b
  6333.         ld      de,-FIB.rec
  6334.         add     hl,de           ; Point to record
  6335.         ld      d,(hl)
  6336.         dec     hl
  6337.         ld      e,(hl)
  6338.         ex      de,hl
  6339.         or      a
  6340.         sbc     hl,bc           ; Test against last record
  6341.         ret     nc
  6342.         ex      de,hl
  6343.         ld      (hl),c          ; Save new max record
  6344.         inc     hl
  6345.         ld      (hl),b
  6346.         ret
  6347. ;
  6348. ; Procedure SEEK(file,record)
  6349. ; ENTRY Reg HL holds record seeked for
  6350. ;       FIB pushed onto stack
  6351. ;
  6352. l1b6f:
  6353.         pop     bc
  6354.         pop     de
  6355.         ld      (l00e2),de      ; Save FIB
  6356.         push    bc
  6357.         push    hl
  6358.         call    l1a5a           ; Get record data
  6359.         pop     de
  6360.         or      a
  6361.         sbc     hl,de           ; Test position
  6362.         jp      c,l1a26         ; Error if overflow
  6363.         ld      hl,(l00e2)      ; Get FIB
  6364.         ld      bc,FIB.cur
  6365.         add     hl,bc
  6366.         ld      (hl),e          ; Save new position
  6367.         inc     hl
  6368.         ld      (hl),d
  6369.         ld      bc,FIB.FCB+_rrn-FIB.cur-1
  6370.         add     hl,bc
  6371.         ld      (hl),e          ; Save in FCB, too
  6372.         inc     hl
  6373.         ld      (hl),d
  6374.         ret
  6375. ;
  6376. ; Delete file
  6377. ; Procedure ERASE(file)
  6378. ; ENTRY Reg HL holds FIB
  6379. ;
  6380. l1b93:
  6381.         call    l1c4c           ; Check legal FIB
  6382.         ret     nz              ; Nope
  6383.         ld      de,FIB.FCB
  6384.         add     hl,de           ; Point to FCB
  6385.         ex      de,hl
  6386.         ld      c,_delete
  6387.         call    BDOS            ; Delete file
  6388.         inc     a
  6389.         ret     nz
  6390.         jr      l1be4           ; Set error if unknown
  6391. ;
  6392. ; Rename file
  6393. ; Procedure RENAME(file,newname)
  6394. ; ENTRY FIB and name on stack
  6395. ;
  6396. l1ba5:
  6397.         pop     iy
  6398.         ld      hl,(l00d2)      ; Get top of memory for buffer
  6399.         ld      b,16            ; Set max
  6400.         call    l05e2           ; Assign string from stack
  6401.         xor     a
  6402.         ld      (de),a
  6403.         pop     hl              ; Load FIB
  6404.         push    iy
  6405.         call    l1c4c           ; Check legal FIB
  6406.         ret     nz              ; Nope
  6407.         push    hl
  6408.         call    l03f2           ; Parse file
  6409.         pop     hl
  6410.         push    hl
  6411.         ld      de,FIB.FCB+DIRlen
  6412.         add     hl,de           ; Point to 2nd FCB
  6413.         ex      de,hl
  6414.         ld      hl,l005c
  6415.         ld      bc,Fdrv+Fname+Fext
  6416.         ldir                    ; move new name
  6417.         pop     hl
  6418.         ld      de,FIB.FCB
  6419.         add     hl,de           ; Point to FCB
  6420.         push    hl
  6421.         ex      de,hl
  6422.         ld      c,_rename
  6423.         call    BDOS            ; Rename
  6424.         pop     de
  6425.         inc     a               ; Test success
  6426.         jr      z,l1be4         ; Nope
  6427.         ld      hl,l005c
  6428.         ld      bc,FCBlen
  6429.         ldir                    ; Unpack new file
  6430.         ret
  6431. l1be4:
  6432.         ld      a,_NoFile       ; Set error
  6433. l1be6:
  6434.         ld      (l00d0),a
  6435.         ret
  6436. ;
  6437. ; Perform executing new programs
  6438. ; Procedure EXECUTE(File)
  6439. ; ENTRY Reg HL points to FIB
  6440. ;
  6441. l1bea:
  6442.         db      skip
  6443. ;
  6444. ; Procedure CHAIN(File)
  6445. ;
  6446. l1beb:
  6447.         xor     a
  6448.         ld      (l00e8),a       ; Set mode (0=CHAIN)
  6449.         call    l1c4c           ; Test device ok
  6450.         ret     nz              ; Nope
  6451.         ld      a,(l00d8)       ; Test run mode
  6452.         or      a
  6453.         ld      a,_DirErr
  6454.         jr      z,l1be6         ; Must *NOT* be direct mode
  6455.         ld      hl,(l00e2)      ; Get FIB
  6456.         ld      de,FIB.FCB
  6457.         add     hl,de           ; Point to FCB
  6458.         ld      de,l005c
  6459.         ld      bc,FCBlen
  6460.         ldir                    ; move to standard FCB
  6461.         ld      de,l005c
  6462.         ld      c,_open
  6463.         call    BDOS            ; Open file
  6464.         inc     a
  6465.         jr      z,l1be4         ; File not found
  6466.         ld      hl,l1c33        ; Point to loader
  6467.         ld      de,l00b0
  6468.         ld      bc,l0019
  6469.         ldir                    ; move loader to temporry location
  6470.         ld      de,0x0100;TPA           ; Init loader address
  6471.         ld      a,(l00e8)       ; Test mode
  6472.         or      a
  6473.         jr      nz,l1c2d
  6474.         ld      de,(progstartaddr);(TPA+1)      ; Change address for CHAIN
  6475. l1c2d:
  6476.         ld      sp,0x0100;TPA           ; Get local stack
  6477.         jp      l00b0           ; Go load
  6478. ;
  6479. ; ############### Start of loader ###############
  6480. ;
  6481. ; Loader will be moved into 00B0H temporry loaction
  6482. ;
  6483. l1c33:
  6484.         disp    l00b0
  6485. _l1c33:
  6486.         push    de
  6487.         ld      c,_setdma
  6488.         call    BDOS            ; Set disk buffer
  6489.         ld      de,l005c
  6490.         ld      c,_rdseq
  6491.         call    BDOS            ; Read a code record
  6492.         pop     de
  6493.         ld      hl,RecLng
  6494.         add     hl,de           ; Bump address
  6495.         ex      de,hl
  6496.         ;or     a               ; Test more
  6497.         ;jr     z,_l1c33
  6498.          cp 128 ;EOF in NedoOS
  6499.          jr nz,_l1c33           ; Read was successfull
  6500.          ;jr $
  6501.         jr      0x0100;TPA              ; Start after loading
  6502. l0019   equ     $-_l1c33
  6503.         ent
  6504. ;
  6505. ; ################ End of loader ################
  6506. ;
  6507. ; Check legal device for file operation
  6508. ; ENTRY Reg HL points to FIB
  6509. ; EXIT  Zero flag set if legal device
  6510. ;       If illegal, IOerror 20H will be set
  6511. ;
  6512. l1c4c:
  6513.         ld      (l00e2),hl      ; Save FIB
  6514.         ld      a,(hl)          ; Get flag
  6515.         and     FIBtype         ; Mask it
  6516.         ret     z               ; 0000 menas file
  6517.         ld      a,_IllIO
  6518.         ld      (l00d0),a       ; Set error
  6519.         ret
  6520. ;
  6521. ; Load overlay file
  6522. ; ENTRY Reg HL holds record procedure starts with
  6523. ;       Reg DE holds number of records to be read
  6524. ;
  6525. ; Overlay call follows:
  6526. ;           2 Bytes hold last sector read
  6527. ;          11 Bytes NAME.EXT of file
  6528. ;       n*128 Bytes record(s)
  6529. ;
  6530. l1c59:
  6531.         ld      (l00e6),hl      ; Save record
  6532.         ld      (l00e8),de      ; Save record count
  6533.         ex      de,hl
  6534.         pop     hl
  6535.         ld      (l00e2),hl      ; Save caller
  6536.         ld      c,(hl)          ; Fetch last sector
  6537.         ld      (hl),e          ; Set new one
  6538.         inc     hl
  6539.         ld      b,(hl)
  6540.         ld      (hl),d
  6541.         ex      de,hl           ; Compare bew:old
  6542.         or      a
  6543.         sbc     hl,bc
  6544.         jr      z,l1cca         ; Overlay already in memory
  6545.         ex      de,hl
  6546.         inc     hl
  6547.         ld      de,l005c
  6548.         ld      a,(l00dc)       ; Get overlay drive
  6549.         ld      (de),a          ; Store into standard FCB
  6550.         inc     de
  6551.         ld      bc,Fname+Fext
  6552.         ldir                    ; move name to standard FCB
  6553.         ld      b,FCBlen-_ex
  6554.         xor     a
  6555. l1c82:
  6556.         ld      (de),a          ; Clear remainder of FCB
  6557.         inc     de
  6558.         djnz    l1c82
  6559.         push    hl              ; Save address of buffer
  6560.         ld      de,l005c
  6561.         ld      c,_open
  6562.         call    BDOS            ; Open file
  6563.         pop     de              ; Get back buffer address
  6564.         inc     a               ; Test success
  6565.         jr      z,l1cd2         ; Nope
  6566.         ld      hl,(l00e6)      ; Get start record
  6567.         ld      (l005c+_rrn),hl ; Set for random record
  6568.         ld      bc,(l00e8)      ; Get record count
  6569. l1c9d:
  6570.         push    bc
  6571.         push    de
  6572.         ld      c,_setdma
  6573.         call    BDOS            ; Set disk buffer
  6574.         ld      de,l005c
  6575.         ld      c,_rndrd
  6576.         call    BDOS            ; Read from file
  6577.         pop     de
  6578.         pop     bc
  6579.         or      a               ; Verify no error
  6580.         jr      nz,l1cd2        ; Error
  6581.         ld      hl,(l005c+_rrn)
  6582.         inc     hl              ; Bump record
  6583.         ld      (l005c+_rrn),hl
  6584.         ld      hl,RecLng
  6585.         add     hl,de           ; Get next address
  6586.         ex      de,hl
  6587.         dec     bc
  6588.         ld      a,b             ; Test done
  6589.         or      c
  6590.         jr      nz,l1c9d        ; Nope
  6591.         ld      de,l005c
  6592.         ld      c,_close
  6593.         call    BDOS            ; Close file
  6594. l1cca:
  6595.         ld      hl,(l00e2)      ; Get caller
  6596.         ld      de,2+Fname+Fext
  6597.         add     hl,de           ; Skip header
  6598.         jp      (hl)            ; Enter overlay
  6599. l1cd2:
  6600.         ld      ix,(l00e2)      ; Get caller's PC
  6601.         ld      a,_OVLerr
  6602.         jp      l2029           ; Abort
  6603. ;
  6604. ; Procedure OVRDRIVE(drive)
  6605. ; ENTRY Reg HL holds drive (1=A, 2=B, etc)
  6606. ;
  6607. l1cdb:
  6608.         call    l04c8           ; Get byte from integer
  6609.         cp      'P'-'@'+1       ; Test max
  6610.         ret     nc              ; Exit on range error
  6611.         ld      (l00dc),a       ; Set overlay drive
  6612.         ret
  6613. ;
  6614. ; Procedure NEW(pointer)
  6615. ; Procedure GETMEM(pointer,space)
  6616. ; ENTRY Reg HL holds space required
  6617. ;       Variable pointer on stack
  6618. ;
  6619. l1ce5:
  6620.         ld      (l00f0),hl      ; Save space required
  6621.         ex      de,hl
  6622.         pop     hl
  6623.         ex      (sp),hl
  6624.         ld      (l00f2),hl      ; Save address of variable
  6625.         inc     de
  6626.         inc     de
  6627.         inc     de
  6628.         ld      a,e
  6629.         and     -HeapLen        ; Get modulo 4
  6630.         ld      e,a
  6631.         ld      hl,l00de
  6632.         ld      (l00f8),hl      ; Init pointer
  6633.         ld      ix,(l00de)      ; Get pointer to 1st free address
  6634. l1cff:
  6635.         ld      l,(ix+HeapLOlen)
  6636.         ld      h,(ix+HeapHIlen)
  6637.         ld      a,l             ; Test assignment
  6638.         or      h
  6639.         jr      z,l1d51         ; Maybe free
  6640.         sbc     hl,de           ; Test gap
  6641.         jr      nc,l1d1c
  6642.         ld      l,(ix+HeapLOadr); Get next address
  6643.         ld      h,(ix+HeapHIadr)
  6644.         push    hl
  6645.         ld      (l00f8),ix      ; Save last address
  6646.         pop     ix              ; Copy chain
  6647.         jr      l1cff
  6648. l1d1c:
  6649.         jr      nz,l1d28        ; Not same gap length
  6650.         ld      e,(ix+HeapLOadr); Get address if so
  6651.         ld      d,(ix+HeapHIadr)
  6652.         push    ix
  6653.         jr      l1d43           ; Save state
  6654. l1d28:
  6655.         ld      c,l             ; Copy length
  6656.         ld      b,h
  6657.         ld      l,(ix+HeapLOadr); Get address
  6658.         ld      h,(ix+HeapHIadr)
  6659. l1d30:
  6660.         push    ix              ; Save pointer
  6661.         add     ix,de           ; Advance
  6662.         ld      (ix+HeapLOadr),l; Set start values
  6663.         ld      (ix+HeapHIadr),h
  6664.         ld      (ix+HeapLOlen),c
  6665.         ld      (ix+HeapHIlen),b
  6666.         push    ix
  6667.         pop     de              ; Copy pointer
  6668. l1d43:
  6669.         ld      hl,(l00f8)      ; Get pointer
  6670.         ld      (hl),e          ; Set new link
  6671.         inc     hl
  6672.         ld      (hl),d
  6673.         pop     de
  6674.         ld      hl,(l00f2)
  6675.         ld      (hl),e          ; Set into vriable
  6676.         inc     hl
  6677.         ld      (hl),d
  6678.         ret
  6679. l1d51:
  6680.         push    ix
  6681.         pop     hl
  6682.         add     hl,de
  6683.         ld      (l00c4),hl      ; Set new heap pointer
  6684.         ld      hl,(l00f0)      ; Get space
  6685.         ld      bc,HeapLen
  6686.         add     hl,bc           ; Get complete length
  6687.         push    ix
  6688.         pop     bc
  6689.         add     hl,bc
  6690.         jp      c,l1d75         ; Error if overlapping
  6691.         ld      bc,(l00c6)      ; Get recursion pointer
  6692.         sbc     hl,bc           ; Test against it
  6693.         ld      bc,0
  6694.         ld      hl,0
  6695.         jp      c,l1d30
  6696. ;
  6697. ; Heap error
  6698. ;
  6699. l1d75:
  6700.         ld      a,_HeapErr
  6701.         jp      l2027           ; Set error
  6702. ;
  6703. ; Procedure DISPOSE(pointer)
  6704. ; Procedure FREEMEM(pointer,space)
  6705. ; ENTRY Reg HL holds space
  6706. ;       Variable pointer on stack
  6707. ;
  6708. l1d7a:
  6709.         ex      de,hl           ; Save space
  6710.         pop     hl
  6711.         ex      (sp),hl         ; Get variable pointer
  6712.         ld      a,(hl)          ; Get dynamic pointer
  6713.         inc     hl
  6714.         ld      h,(hl)
  6715.         ld      l,a
  6716.         inc     de              ; Fix space
  6717.         inc     de
  6718.         inc     de
  6719.         ld      a,e
  6720.         and     -HeapLen        ; Get modulo 4
  6721.         ld      e,a
  6722.         ex      de,hl
  6723.         ld      (l00f0),hl      ; Save length
  6724.         ld      hl,(l00de)      ; Load pointer to free heap
  6725.         push    hl
  6726.         pop     ix
  6727.         or      a
  6728.         sbc     hl,de           ; Check pointer addresses
  6729.         jr      nc,l1de9
  6730. l1d97:
  6731.         ld      l,(ix+HeapLOadr); Get address
  6732.         ld      h,(ix+HeapHIadr)
  6733.         push    hl
  6734.         or      a
  6735.         sbc     hl,de           ; Compare
  6736.         jr      nc,l1da7
  6737.         pop     ix
  6738.         jr      l1d97
  6739. l1da7:
  6740.         pop     hl
  6741.         push    de
  6742.         pop     iy
  6743.         ld      bc,(l00f0)      ; Get length
  6744.         ld      (iy+HeapLOlen),c; Store it
  6745.         ld      (iy+HeapHIlen),b
  6746.         ld      (iy+HeapLOadr),l; Store address, too
  6747.         ld      (iy+HeapHIadr),h
  6748.         ld      (ix+HeapLOadr),e
  6749.         ld      (ix+HeapHIadr),d
  6750.         push    ix
  6751.         pop     hl
  6752.         ld      c,(ix+HeapLOlen); Get old length
  6753.         ld      b,(ix+HeapHIlen)
  6754.         call    l1e04           ; Compare
  6755.         jr      z,l1dd8         ; Match
  6756.         ld      e,(ix+HeapLOadr); Get address
  6757.         ld      d,(ix+HeapHIadr)
  6758.         push    de
  6759.         pop     ix
  6760. l1dd8:
  6761.         push    ix
  6762.         pop     hl
  6763.         ld      c,(ix+HeapLOlen)
  6764.         ld      b,(ix+HeapHIlen)
  6765.         ld      e,(ix+HeapLOadr)
  6766.         ld      d,(ix+HeapHIadr)
  6767.         jr      l1e04
  6768. l1de9:
  6769.         ld      hl,(l00de)      ; Get pointer to free heap
  6770.         ld      (l00de),de      ; Set new address
  6771.         push    de
  6772.         pop     ix
  6773.         ld      (ix+HeapLOadr),l; Set chain
  6774.         ld      (ix+HeapHIadr),h
  6775.         ld      bc,(l00f0)      ; Get length
  6776.         ld      (ix+HeapLOlen),c
  6777.         ld      (ix+HeapHIlen),b
  6778.         ex      de,hl
  6779. l1e04:
  6780.         add     hl,bc           ; Bump next
  6781.         or      a
  6782.         sbc     hl,de           ; Test same
  6783.         ret     nz
  6784.         push    de
  6785.         pop     iy              ; Copy pointer
  6786.         ld      hl,(l00c4)      ; Get heap pointer
  6787.         or      a
  6788.         sbc     hl,de           ; Test top found
  6789.         jr      z,l1e2f
  6790.         ld      a,(iy+HeapLOadr); Unpack address
  6791.         ld      (ix+HeapLOadr),a
  6792.         ld      a,(iy+HeapHIadr)
  6793.         ld      (ix+HeapHIadr),a
  6794.         ld      l,(iy+HeapLOlen)
  6795.         ld      h,(iy+HeapHIlen)
  6796.         add     hl,bc
  6797.         ld      (ix+HeapLOlen),l; Unpack new length
  6798.         ld      (ix+HeapHIlen),h
  6799.         xor     a
  6800.         ret
  6801. l1e2f:
  6802.         push    ix
  6803.         pop     hl
  6804.         ld      (l00c4),hl      ; Set new top heap pointer
  6805.         ld      b,HeapLen
  6806. l1e37:
  6807.         ld      (hl),0          ; Clear top
  6808.         inc     hl
  6809.         djnz    l1e37
  6810.         ret
  6811. ;
  6812. ; Get free memory
  6813. ; Function MEMAVAIL:integer
  6814. ; EXIT  Reg HL holds free memory in bytes
  6815. ;
  6816. l1e3d:
  6817.         call    l1e4b           ; Get memory
  6818.         ld      hl,(l00f4)      ; Get available memory
  6819.         ret
  6820. ;
  6821. ; Get max free memory
  6822. ; Function MAXAVAIL:integer
  6823. ; EXIT  Reg HL holds free memory in bytes
  6824. ;
  6825. l1e44:
  6826.         call    l1e4b           ; Get memory
  6827.         ld      hl,(l00f6)      ; Get max memory
  6828.         ret
  6829. ;
  6830. ; Get free memory
  6831. ;
  6832. l1e4b:
  6833.         ld      hl,0
  6834.         ld      (l00f4),hl      ; Init available memory
  6835.         ld      (l00f6),hl
  6836.         ld      ix,(l00de)      ; Get pointer to free heap
  6837. l1e58:
  6838.         ld      c,(ix+HeapLOlen)
  6839.         ld      b,(ix+HeapHIlen)
  6840.         ld      a,c
  6841.         or      b               ; Test end of chain
  6842.         jr      z,l1e80
  6843.         ld      hl,(l00f4)      ; Get old available memory
  6844.         add     hl,bc           ; Add length
  6845.         ld      (l00f4),hl
  6846.         ld      hl,(l00f6)      ; Get max
  6847.         or      a
  6848.         sbc     hl,bc           ; Check it
  6849.         jr      nc,l1e75
  6850.         ld      (l00f6),bc      ; Set new max
  6851. l1e75:
  6852.         ld      l,(ix+HeapLOadr); Get chain
  6853.         ld      h,(ix+HeapHIadr)
  6854.         push    hl
  6855.         pop     ix
  6856.         jr      l1e58           ; Loop
  6857. l1e80:
  6858.         ld      hl,(l00c6)      ; Get recursion pointer
  6859.         ld      bc,-5
  6860.         add     hl,bc           ; Build free address
  6861.         ld      de,(l00c4)      ; Get heap pointer
  6862.         or      a
  6863.         sbc     hl,de           ; Test any free
  6864.         ret     c
  6865.         ex      de,hl
  6866.         ld      hl,(l00f4)      ; Get available memory
  6867.         add     hl,de           ; Add gap
  6868.         ld      (l00f4),hl
  6869.         ld      hl,(l00f6)      ; Get max
  6870.         or      a
  6871.         sbc     hl,de           ; Subtract
  6872.         ret     nc
  6873.         ld      (l00f6),de      ; Set new
  6874.         ret
  6875. ;
  6876. ; Mark heap
  6877. ; Procedure MARK(pointer)
  6878. ; ENTRY Reg HL holds pointer
  6879. ;
  6880. l1ea3:
  6881.         ld      de,(l00c4)      ; Get heap pointer
  6882.         ld      (hl),e          ; Store into variable
  6883.         inc     hl
  6884.         ld      (hl),d
  6885.         ret
  6886. ;
  6887. ; Release heap
  6888. ; Procedure RELEASE(pointer)
  6889. ; ENTRY Reg HL holds pointer
  6890. ;
  6891. l1eab:
  6892.         ld      e,(hl)          ; Load heap from variable
  6893.         inc     hl
  6894.         ld      d,(hl)
  6895.         ex      de,hl
  6896. ;
  6897. ; Init heap
  6898. ; ENTRY Reg HL points to 1st free location
  6899. ;
  6900. l1eaf:
  6901.         ld      (l00c4),hl      ; Set heap pointer
  6902.         ld      (l00de),hl
  6903.         ld      b,HeapLen
  6904. l1eb7:
  6905.         ld      (hl),0          ; Clear 4 bytes
  6906.         inc     hl
  6907.         djnz    l1eb7
  6908.         ret
  6909. ;
  6910. ; Convert number to string
  6911. ; Procedure STR(real,string)
  6912. ; ENTRY Real pushed onto stack with formatting data
  6913. ;       Reg HL points to string
  6914. ;       Reg B holds length of string
  6915. ;
  6916. l1ebd:
  6917.         db      skip
  6918. ;
  6919. ; Procedure STR(integer,string)
  6920. ; ENTRY Integer pushed onto stack with digit count
  6921. ;       Reg HL points to string
  6922. ;       Reg B holds length of string
  6923. ;
  6924. l1ebe:
  6925.         xor     a
  6926.         ld      c,a             ; Save mode
  6927.         ld      (l00e8),hl      ; Save string
  6928.         xor     a
  6929.         ld      (hl),a          ; Init to empty string
  6930.         ld      (l00d0),a       ; Clear error
  6931.         ld      a,b
  6932.         ld      (l00ea),a       ; Save max length
  6933.         ld      hl,(l00e2)
  6934.         ld      (l00ed),hl      ; Save current FIB
  6935.         ld      hl,l1f46
  6936.         ld      (l00e2),hl      ; Set RAM device
  6937.         pop     hl              ; Get caller
  6938.         ld      (l00e4),hl
  6939.         pop     hl              ; Get digit count/comma places
  6940.         inc     c               ; Test mode
  6941.         dec     c
  6942.         jr      nz,l1ee6
  6943.         call    l1726           ; Get integer string
  6944.         jr      l1ee9
  6945. l1ee6:
  6946.         call    l1779           ; Get real string
  6947. l1ee9:
  6948.         ld      hl,(l00ed)
  6949.         ld      (l00e2),hl      ; Restore FIB
  6950.         ld      hl,(l00e4)      ; Get caller
  6951.         jp      (hl)
  6952. ;
  6953. ; Convert string to number
  6954. ; Procedure VAL(string,real,result)
  6955. ; ENTRY String and address of real pushed onto stack
  6956. ;       Reg HL points to result
  6957. ;
  6958. l1ef3:
  6959.         db      skip
  6960. ;
  6961. ; Procedure VAL(string,integer,result)
  6962. ; ENTRY String and address of integer pushed onto stack
  6963. ;       Reg HL points to result
  6964. ;
  6965. l1ef4:
  6966.         xor     a
  6967.         ld      (l00ec),a       ; Save mode
  6968.         ld      (l00e8),hl      ; Save result
  6969.         ld      hl,(l00e2)
  6970.         ld      (l00ed),hl      ; Save current FIB
  6971.         ld      hl,l1f46
  6972.         ld      (l00e2),hl      ; Set RAM FIB
  6973.         pop     hl
  6974.         ld      (l00e4),hl      ; Save caller
  6975.         pop     hl
  6976.         ld      (l00ea),hl      ; Save integer/real address
  6977.         ld      hl,l005c
  6978.         ld      b,1eh
  6979.         call    l05e2           ; Assign string from stack
  6980.         xor     a
  6981.         ld      (de),a
  6982.         ld      hl,(l00ea)      ; Get back variable pointer
  6983.         ld      a,(l00ec)       ; Test mode
  6984.         or      a
  6985.         jr      nz,l1f27
  6986.         call    l164e           ; Convert to integer
  6987.         jr      l1f2a
  6988. l1f27:
  6989.         call    l1672           ; Convert to real
  6990. l1f2a:
  6991.         ld      hl,l00d0
  6992.         ld      a,(hl)          ; Get IOResult
  6993.         ld      (hl),0          ; Clear
  6994.         or      a
  6995.         ld      h,a
  6996.         ld      l,a
  6997.         jr      z,l1f3d         ; Test error
  6998.         push    ix
  6999.         pop     hl              ; Get last address
  7000.         ld      de,l005c
  7001.         sbc     hl,de           ; Get relative string error
  7002. l1f3d:
  7003.         ex      de,hl
  7004.         ld      hl,(l00e8)      ; Point to result
  7005.         ld      (hl),e          ; Save error or success
  7006.         inc     hl
  7007.         ld      (hl),d
  7008.         jr      l1ee9           ; Exit
  7009. ;
  7010. ; FIB for RAM storage
  7011. ;
  7012. l1f46:
  7013.         db      _.in+_.out+RAMdevice
  7014.         db      0
  7015. ;
  7016. ; Procedure RANDOMIZE
  7017. ;
  7018. l1f48:
  7019.         ld      a,r             ; Get refresh counter
  7020.         ld      (l00c8+3),a     ; Set for random
  7021.         ret
  7022. ;
  7023. ; Fill variable with constant value
  7024. ; Procedure FILLCHAR(var,num,val)
  7025. ; ENTRY Reg HL holds value
  7026. ;       Count and variable address pushed onto stack
  7027. ;
  7028. l1f4e:
  7029.         ex      de,hl
  7030.         pop     ix
  7031.         pop     bc              ; Get count
  7032.         pop     hl              ; Get address
  7033.         ld      a,b
  7034.         or      c               ; Test count zero
  7035.         jr      z,l1f62         ; Skip if so
  7036.         ld      (hl),e          ; Store value
  7037.         dec     bc              ; Fix count
  7038.         ld      a,b
  7039.         or      c               ; Test count one
  7040.         jr      z,l1f62         ; Skip if so
  7041.         ld      d,h             ; Copy address
  7042.         ld      e,l
  7043.         inc     de
  7044. l1f60:
  7045.         ldir                    ; move value for fill
  7046. l1f62:
  7047.         jp      (ix)
  7048. ;
  7049. ; move variable to another
  7050. ; Procedure MOVE(var1,var2,len)
  7051. ; ENTRY Reg HL holds count
  7052. ;       Variables pushed onto stack
  7053. ;
  7054. l1f64:
  7055.         ld      b,h             ; Copy count
  7056.         ld      c,l
  7057.         pop     ix
  7058.         pop     de              ; Get 2nd var
  7059.         pop     hl              ; Get 1st one
  7060.         ld      a,b
  7061.         or      c
  7062.         jr      z,l1f62         ; Test zero length
  7063.         sbc     hl,de
  7064.         add     hl,de           ; Test overlapping
  7065.         jr      nc,l1f60        ; move up if so
  7066.         dec     bc
  7067.         add     hl,bc           ; Point to top
  7068.         ex      de,hl
  7069.         add     hl,bc
  7070.         ex      de,hl
  7071.         inc     bc
  7072.         lddr                    ; move down
  7073.         jp      (ix)
  7074. ;
  7075. ; Get string from OS command line
  7076. ; Function PARAMSTR(num):any_string
  7077. ; ENTRY Reg HL holds number of substring
  7078. ; EXIT  Selected string on stack
  7079. ;
  7080. l1f7d:
  7081.         ld      d,l             ; Get number
  7082.         inc     d
  7083.         dec     d
  7084.         jr      z,l1f85         ; Skip if none
  7085.         call    l1f9d
  7086. l1f85:
  7087.         pop     ix              ; Free stack
  7088.         ld      c,a             ; Get length of string
  7089.         ld      b,0
  7090.         cpl
  7091.         ld      l,a
  7092.         ld      h,-1
  7093.         add     hl,sp           ; Build address on stack
  7094.         ld      sp,hl
  7095.         ld      (hl),c          ; Store length
  7096.         inc     hl
  7097.         ex      de,hl
  7098.         inc     c               ; Test any selected
  7099.         dec     c
  7100.         jr      z,l1f99         ; Nope
  7101.         ldir                    ; Unpack it
  7102. l1f99:
  7103.         jp      (ix)
  7104. ;
  7105. ; Get number of parameters in OS command line
  7106. ; Function PARAMCOUNT:integer;
  7107. ;
  7108. l1f9b:
  7109.         ld      d,0             ; Set dummy selection
  7110. ;
  7111. ; Get parameters of OS command line
  7112. ; ENTRY Reg D holds number of substring selected
  7113. ; EXIT  Reg DE points to selected substring
  7114. ;       Accu   holds length of substring
  7115. ;       Reg HL holds index of substring
  7116. ;
  7117. l1f9d:
  7118.         ld      hl,l0080        ; Init pointer
  7119.         ;ld     a,MaxParams     ; Test parameter count
  7120.         ;ld     b,(hl)
  7121.         ;cp     b
  7122.         ;jr     nc,l1fa8
  7123.         ld      b,MaxParams     ; Truncate to max
  7124. ;l1fa8:
  7125.         ;inc    hl
  7126.         ld      c,0             ; Init count
  7127. l1fab:
  7128.         inc     b
  7129.         dec     b               ; Test end
  7130.         jr      z,l1fbc         ; Yeap
  7131.         ld      a,(hl)
  7132.         cp      ' '
  7133.         jr      z,l1fb8         ; Skip white spaces
  7134.         cp      tab
  7135.         jr      nz,l1fbc
  7136. l1fb8:
  7137.         inc     hl
  7138.         dec     b
  7139.         jr      l1fab
  7140. l1fbc:
  7141.         ld      e,l             ; Save pointer
  7142. l1fbd:
  7143.         inc     b
  7144.         dec     b               ; Test done
  7145.         jr      z,l1fce         ; Yeap
  7146.         ld      a,(hl)
  7147.         cp      ' '
  7148.         jr      z,l1fce         ; Find white space
  7149.         cp      tab
  7150.         jr      z,l1fce
  7151.         inc     hl
  7152.         dec     b
  7153.         jr      l1fbd
  7154. l1fce:
  7155.         ld      a,l
  7156.         sub     e               ; Test same position
  7157.         jr      z,l1fd6
  7158.         inc     c               ; Count up index
  7159.         dec     d               ; Test found
  7160.         jr      nz,l1fab
  7161. l1fd6:
  7162.         ld      l,c             ; Get selected or last index
  7163.         ld      h,0             ; Make pointer relative
  7164.         ld      d,h
  7165.         ret
  7166. ;
  7167. ; Procedure GOTOXY(x_val,y_val)
  7168. ; ENTRY Reg HL holds y_val
  7169. ;       x_val on stack
  7170. ;
  7171. l1fdb:
  7172.         pop     de
  7173.         pop     bc
  7174.         push    de
  7175.         dec     l               ; Fix row
  7176.         ld      h,c
  7177.         dec     h               ; Fix column
  7178.         jp      l02a2           ; Position cursor
  7179. ;
  7180. ; Function UPCASE(char):char
  7181. ; ENTRY Reg HL holds character
  7182. ; EXIT  Reg HL holds UPPER case character
  7183. ;
  7184. l1fe4:
  7185.         ld      a,l             ; Get into accu
  7186.         call    l04a6           ; Convert to upper case
  7187.         ld      l,a             ; Bring it back
  7188.         ret
  7189. ;
  7190. ; Execute BIOS function
  7191. ; Procedures    BIOS(func)
  7192. ;               BIOS(func,param)
  7193. ; Functions     BIOS(func):integer
  7194. ;               BIOS(func,param):integer
  7195. ;               BIOSHL(func,param):integer
  7196. ; ENTRY Reg DE holds BIOS function
  7197. ;       Reg BC holds optional parameter
  7198. ; EXIT  Accu and reg HL hold result
  7199. ;
  7200. l1fea:
  7201.         ld      hl,(OS+1)       ; Get base address
  7202.         add     hl,de           ; Make executable
  7203.         add     hl,de
  7204.         add     hl,de
  7205.         jp      (hl)            ; Execute
  7206. ;
  7207. ; Get IO result
  7208. ; Function IORESULT:integer
  7209. ; EXIT  Reg HL holds result
  7210. ;
  7211. l1ff1:
  7212.         ld      hl,l00d0        ; Point to result
  7213.         ld      a,(hl)          ; Get it
  7214.         ld      (hl),0          ; Clear after request
  7215.         ld      l,a
  7216.         ld      h,0
  7217.         ret
  7218. ;
  7219. ; Control C entry - entered via RST after each statement
  7220. ;
  7221. l1ffb:
  7222.         call    l0316           ; Test key pressed
  7223.         ld      a,h
  7224.         or      l
  7225.         ret     z               ; Nope
  7226.         ld      a,(l00dd)       ; Get $C mode
  7227.         push    af
  7228.         xor     a
  7229.         ld      (l00dd),a       ; Set $C-
  7230.         call    l0320           ; Read from keyboard
  7231.         pop     af
  7232.         ld      (l00dd),a       ; Reset $C mode
  7233.         ld      a,l
  7234.         cp      CtrlC           ; Test Control-C
  7235.         ret     nz              ; Nope
  7236.         pop     ix              ; Fetch PC
  7237. l2016:
  7238.         ld      de,_CBRK        ; Set CtrlC error
  7239.         jr      l202c           ; Enter error routine
  7240. ;
  7241. ; Check IOResult after IO operation
  7242. ; (May be turned off by {$I-})
  7243. ;
  7244. l201b:
  7245.         ld      a,(l00d0)       ; Test any error
  7246.         or      a
  7247.         ret     z               ; Nope
  7248.         pop     ix              ; Get caller
  7249.         ld      e,a             ; Save code
  7250.         ld      d,_IO           ; Set mode
  7251.         jr      l202c
  7252. l2027:
  7253.         pop     ix              ; Get caller
  7254. l2029:
  7255.         ld      e,a             ; Save code
  7256.         ld      d,_RT           ; Set mode
  7257. ;
  7258. ; Common error handler
  7259. ; ENTRY Reg D holds error mode
  7260. ;       Reg E holds error code
  7261. ;       Reg IX holds callers address
  7262. ;
  7263. l202c:
  7264.          ;jr $
  7265.         push    de
  7266.         call    l037a           ; Reset some things
  7267.         pop     de
  7268.         xor     a
  7269.         ld      (l00dd),a       ; Set $C- mode
  7270.         ld      hl,(l00ce)      ; Get current PC
  7271.         ld      a,h             ; Check zero
  7272.         or      l
  7273.         push    ix
  7274.         pop     hl
  7275.         ld      bc,(l00cc)      ; Get base PC
  7276.         sbc     hl,bc           ; Subtract for base
  7277.         ld      bc,TPhead
  7278.         add     hl,bc           ; Fix for 0100h start
  7279.         ld      (l00ce),hl      ; Set current PC
  7280.         or      a               ; Look for previous zero
  7281.         jr      nz,l2054        ; Nope
  7282.         push    de
  7283.         push    de
  7284.         push    hl
  7285.         call    l00d9           ; Do restart
  7286.         pop     de
  7287. l2054:
  7288.         ld      a,d
  7289.         or      a               ; Test user break
  7290.         jr      nz,l206c
  7291.         call    l0200           ; Tell control C
  7292.         db      '^C'
  7293.         db      cr,lf  
  7294.         db      'User break'
  7295.         db      null
  7296.         jr      l2097
  7297. l206c:
  7298.         dec     a               ; Test I/O error
  7299.         jr      nz,l207a
  7300.         call    l0200           ; Tell I/O error
  7301.         db      cr,lf  
  7302.         db      'I/O'
  7303.         db      null
  7304.         jr      l2088
  7305. l207a:
  7306.         call    l0200           ; Tell run time error
  7307.         db      cr,lf  
  7308.         db      'Run-time'
  7309.         db      null
  7310. l2088:
  7311.         call    l0200
  7312.         db      ' error '
  7313.         db      null
  7314.         ld      a,e
  7315.         call    l04b4           ; Print error byte
  7316. l2097:
  7317.         call    l0200           ; Tell current PC
  7318.         db      ', PC='
  7319.         db      null
  7320.         ld      hl,(l00ce)      ; Get current PC
  7321.         call    l04af           ; Print hex
  7322.         jr      l20bd           ; Abort
  7323. ;
  7324. ; Process memory error
  7325. ;
  7326. l20a8:
  7327.         call    l0200           ; Tell error
  7328.         db      'Not enough memory'
  7329.         db      null
  7330. ;
  7331. ; Error detected, tell abort and break
  7332. ;
  7333. l20bd:
  7334.         call    l0200           ; Tell it
  7335.         db      cr,lf  
  7336.         db      'Program aborted'
  7337.         db      cr,lf,null     
  7338. ;
  7339. ; Halt program
  7340. ;
  7341. l20d4:
  7342.         ld      a,(l00d8)       ; Test run mode
  7343.         or      a
  7344.         jp      z,l278e         ; Enter TP menue
  7345.         YIELDGETKEYLOOP
  7346.         jp      OS              ; Exit .COM file
  7347. ;
  7348. ; Restart after error
  7349. ;
  7350. l20de:
  7351.         pop     hl              ; Get PC
  7352.         pop     de              ; Clean stack
  7353.         pop     de
  7354.         jp      (hl)            ; Restart
  7355. ;
  7356. ;end of runtime library
  7357.  
  7358. ; %%%%%%%%%%%%%%%%%%%
  7359. ; %%% MENUE ENTRY %%%
  7360. ; %%%%%%%%%%%%%%%%%%%
  7361. ;
  7362. ; Enter here thru cold start
  7363. ;
  7364. l20e2:
  7365.         jp      l215e           ; Go to initializer
  7366. ;
  7367. ; Set up environment
  7368. ;
  7369. l20e5:
  7370.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)     ; Get top of memory
  7371.         pop     bc
  7372.         ld      sp,hl
  7373.         push    bc
  7374.         ld      de,-StkSpc
  7375.         add     hl,de           ; Allow some space
  7376.         ld      (l4548),hl      ; Set top of memory
  7377.         ld      hl,l7ad7        ; Get top of used memory
  7378.         ld      bc,256*0+0      ; No break, no interrupt
  7379.         call    l0364           ; Init pointers
  7380.         call    l030a           ; Give lead in sequence
  7381.         call    setlowvideo             ; Set low video
  7382.         jp      setnormvideo            ; Set normal video
  7383. ;
  7384. ; Init session and load work file if defined
  7385. ;
  7386. l2104:
  7387.         call    l20e5           ; Set up environment
  7388.         ld      a,(l4542)       ; Get compile flag
  7389.         push    af
  7390.         ld      a,(l4541)       ; Test error message file read
  7391.         or      a
  7392.         call    nz,l2da4        ; Yeap, read it
  7393.         call    l2d8f           ; Init session
  7394.         call    l2d4b           ; Test work file defined
  7395.         call    nz,l2506        ; Yeap, load file
  7396.         ld      a,(l44f3)       ; Get compiler mode
  7397.         dec     a
  7398.         jr      z,l2125         ; Compile to memory
  7399.         pop     af
  7400.         ld      (l4542),a       ; Reset compile flag
  7401. l2125:
  7402.         jp      l223b           ; Enter menue
  7403. ;
  7404. ; Give delimiter line
  7405. ;
  7406. l2128:
  7407.         call    l0200
  7408.         db      '---------------------------------------'
  7409.         db      cr,lf,null
  7410.         ret
  7411. ;
  7412. ; Give B blanks
  7413. ;
  7414. l2156:
  7415.         call    l0200           ; Just do it
  7416.         db      ' ',null
  7417.         djnz    l2156
  7418.         ret
  7419. ;
  7420. ; Come here after cold start
  7421. ;
  7422. l215e:
  7423.         ;OS_HIDEFROMPARENT
  7424.         ;ld e,6 ;textmode
  7425.         ;OS_SETGFX
  7426.        
  7427.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)     ; Fetch top of memory
  7428.         ld      bc,-MEMGAP
  7429.         add     hl,bc
  7430.         ld      (l44f6),hl      ; Set for available memory
  7431.         ld      c,_retdsk
  7432.         call    BDOS            ; Get logged disk (return L=A=current drive)
  7433.         inc     a
  7434.         ld      (l44f8),a       ; Save it
  7435.         call    l20e5           ; Set up environment
  7436.         call    l023e           ; Clear screen
  7437.         call    l2128           ; Give delimiter
  7438.         call    l0200           ; Tell what we are
  7439. l217d:
  7440.         db      'TURBO'
  7441.         db      ' Pascal system',null
  7442.         call    setlowvideo             ; Set low video
  7443.         ld      b,7
  7444.         call    l2156           ; Give blanks
  7445.         call    l0200           ; Tell version
  7446. ;
  7447.         db      'Version 3.00A'
  7448.         db      cr,lf,null
  7449.         ld      b,27
  7450.         call    l2156           ; Give blanks
  7451.         call    l0200           ; Tell type and copyright
  7452. ;
  7453.         db      'CP/M-80, Z80'
  7454.         db      cr,lf,cr,lf
  7455.         db      'Copyright (C) 1983,84,85   '
  7456.         db      null
  7457.         call    setnormvideo            ; Set normal video
  7458.         call    l0200
  7459. ;
  7460.         db      'BORLAND Inc.'
  7461.         db      cr,lf,null
  7462.         call    l2128           ; Give delimiter
  7463.         call    l0200           ; Tell type of terminal
  7464. ;
  7465.         db      lf
  7466.         db      'Terminal: '
  7467.         db      null
  7468.         ld      hl,l0153
  7469.         call    l01d0           ; Give string
  7470.         call    l0200           ; Ask for error messages to be included
  7471. ;
  7472.         db      cr,lf,lf,lf,lf
  7473.         db      'Include error messages'
  7474.         db      null
  7475.         call    l2d21           ; Ask for YES or NO
  7476.         ld      (l4541),a       ; Save result
  7477.         call    nz,l2da4        ; YES, read it
  7478.         call    l2d8f           ; Init session
  7479.         call    l227a           ; Display menue
  7480. ;
  7481. ; %%%%%%%%%%%%%%%%%%%&&&&&
  7482. ; %%% TURBO WARM START %%%
  7483. ; %%%%%%%%%%%%%%%%%%%&&&&&
  7484. ;
  7485. l223b:
  7486.         nop:ld sp,NEDOOSMEMTOP;ld       sp,(TPAtop)     ; Get top of stack
  7487.         ld      hl,l223b
  7488.         push    hl              ; Set return address
  7489.         call    l01fa           ; Indicate input requested
  7490. ;
  7491.         db      cr+MSB,lf+MSB,'>'+MSB
  7492.         db      null
  7493.         call    readfromkbd             ; Read character
  7494.         call    l04a6           ; Convert to upper case
  7495.         call    l01e1           ; Give new line
  7496.         ld      hl,l2460
  7497.         ld      de,l2472
  7498.         ld      b,MainLen
  7499.         call    l2450           ; Find command
  7500.         jr      c,l227a         ; Display menue if not found
  7501.         jp      (hl)            ; Execute command
  7502. ;
  7503. ; Input option string
  7504. ; On exit ^DE points to first non blank
  7505. ;
  7506. l2261:
  7507.         call    l0200           ; Tell what we want
  7508. ;
  7509.         db      ': '
  7510.         db      null
  7511.         call    l14e8           ; Get line
  7512.         call    l01e1           ; Give new line
  7513.         ld      de,l7ad7        ; Point to start of line
  7514. l2270:
  7515.         ld      a,(de)          ; Get character
  7516.         cp      eof             ; End on end of line
  7517.         ret     z
  7518.         cp      ' '             ; Skip blanks
  7519.         ret     nz
  7520.         inc     de
  7521.         jr      l2270
  7522. ;
  7523. ; Display menue
  7524. ;
  7525. l227a:
  7526.         call    l023e           ; Clear screen
  7527.         call    l01fa           ; Give some info
  7528. ;
  7529.         db      'L'+MSB,'ogged drive:',' '+MSB
  7530.         db      null
  7531.         ld      c,_retdsk
  7532.         call    BDOS            ; Fetch disk (return L=A=current drive)
  7533.         add     a,'A'           ; Make ASCII
  7534.         call    puttoconsole_a          ; Put to console
  7535.         call    l01fa           ; Tell work file
  7536. ;
  7537.         db      cr+MSB,lf+MSB,lf+MSB
  7538.         db      'W'+MSB,'ork file:',' '+MSB
  7539.         db      null
  7540.         call    l3135           ; Type it
  7541.         call    l01fa           ; Tell main file
  7542. ;
  7543.         db      cr+MSB,lf+MSB
  7544.         db      'M'+MSB,'ain file:',' '+MSB
  7545.         db      null
  7546.         ld      de,l44f9
  7547.         call    l2df8           ; Tell name of file
  7548.         call    l01fa           ; Give selection
  7549. ;
  7550.         db      cr+MSB,lf+MSB,lf+MSB
  7551.         db      'E'+MSB,'dit     '
  7552.         db      'C'+MSB,'ompile  '
  7553.         db      'R'+MSB,'un   '
  7554.         db      'S'+MSB,'ave'
  7555.         db      cr,lf,lf
  7556.         db      'e','X'+MSB,'ecute  '
  7557.         db      'D'+MSB,'ir      '
  7558.         db      'Q'+MSB,'uit  compiler '
  7559.         db      'O'+MSB,'ptions'
  7560.         db      cr,lf,lf
  7561.         db      'Text: '
  7562.         db      null
  7563.         ld      de,(l4544)      ; Get start of text
  7564.         ld      hl,(l4546)      ; Get end of text
  7565.         dec     hl
  7566.         call    l2338           ; Tell free bytes
  7567.         ld      de,(l4546)      ; Get end of text
  7568.         ld      hl,(l4548)      ; Get top of available memory
  7569. ;
  7570. ; Tell free memory
  7571. ; ENTRY Reg HL holds  end  address
  7572. ;       Reg DE holds start address
  7573. ;
  7574. l232e:
  7575.         call    l0200           ; Tell free memory
  7576. ;
  7577.         db      'Free: '
  7578.         db      null
  7579. ;
  7580. ; Print decimal free bytes and hex addresses
  7581. ; ENTRY Reg HL holds  end  address
  7582. ;       Reg DE holds start address
  7583. ;
  7584. l2338:
  7585.         push    hl
  7586.         push    de
  7587.         or      a
  7588.         sbc     hl,de           ; Calculate difference
  7589.         call    l2e5c           ; Print it
  7590.         call    l0200           ; Tell bytes
  7591. ;
  7592.         db      ' bytes ('
  7593.         db      null
  7594.         pop     hl              ; Get start address
  7595.         call    l04af           ; Print hex
  7596.         ld      a,'-'
  7597.         call    puttoconsole_a          ; Give delimiter
  7598.         pop     hl              ; Get end address
  7599.         call    l04af           ; Print hex
  7600.         ld      a,')'
  7601.         call    puttoconsole_a          ; Give closure
  7602.         jp      l01e1           ; Give new line
  7603. ;
  7604. ; Display arrow if compile selected
  7605. ;
  7606. l2361:
  7607.         dec     a               ; Test compile selected
  7608.         jr      nz,l2374        ; Nope, erase display
  7609.         call    l01fa
  7610. a2361:
  7611.         db      'compile -> '
  7612. la2361  equ     $-a2361
  7613.         db      null
  7614.         ret
  7615. l2374:
  7616.         ld      b,la2361
  7617.         jp      l2156           ; Give blanks
  7618. ;
  7619. ; ##############################
  7620. ; ### MAIN MENUE O - Options ###
  7621. ; ##############################
  7622. ;
  7623. l2379:
  7624.         ld      hl,l2379
  7625.         push    hl              ; Set return address
  7626.         call    l023e           ; Clear screen
  7627.         ld      a,(l44f3)       ; Get compile mode
  7628.         call    l2361           ; Display arrow
  7629.         call    l01fa
  7630.         db      'M'+MSB,'emory'
  7631.         db      cr,lf,null
  7632.         call    l2361           ; Display arrow
  7633.         call    l01fa
  7634.         db      'C'+MSB,'om-file'
  7635.         db      cr,lf,null
  7636.         call    l2361           ; Display arrow
  7637.         call    l01fa
  7638.         db      'c','H'+MSB,'n-file'
  7639.         db      cr,lf,lf,null
  7640.         ld      a,(l44f3)       ; Get compile mode
  7641.         cp      1               ; Test compile to memory
  7642.         jr      z,l2419         ; Yeap
  7643.         call    l01fa
  7644.         db      'S'+MSB,'tart address:',' '+MSB
  7645.         db      null
  7646.         ld      hl,(l44f4)      ; Get start address
  7647.         call    l04af           ; Print hex
  7648.         call    l01fa
  7649.         db      ' (min '
  7650.         db      null
  7651.         ld      hl,l20e2        ; Get start address
  7652.         call    l04af           ; Print hex
  7653.         call    l01fa
  7654.         db      ')'
  7655.         db      cr,lf
  7656.         db      'E'+MSB,'nd   address:',' '+MSB
  7657.         db      null
  7658.         ld      hl,(l44f6)      ; Get top of available memory
  7659.         call    l04af           ; Print hex
  7660.         call    l01fa
  7661.         db      ' (max '
  7662.         db      null
  7663.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  7664.         call    l04af           ; Print hex
  7665.         call    l01fa
  7666.         db      ')'
  7667.         db      cr,lf,lf,null
  7668. l2419:
  7669.         call    l01fa
  7670.         db      'F'+MSB,'ind run-time error  '
  7671.         db      'Q'+MSB,'uit'
  7672.         db      cr,lf,lf
  7673.         db      '>'+MSB
  7674.         db      null
  7675.         call    readfromkbd             ; Read character
  7676.         call    l04a6           ; Convert to upper case
  7677.         call    l01e1           ; Give new line
  7678.         ld      hl,l246b
  7679.         ld      de,l2488
  7680.         ld      b,SubLen
  7681.         call    l2450           ; Find command
  7682.         ret     c               ; Not found
  7683.         jp      (hl)            ; Execute
  7684. ;
  7685. ; Find character in list ^HL of length in reg B
  7686. ; Return address from table ^DE on success
  7687. ; Set C if not found
  7688. ;
  7689. l2450:
  7690.         cp      (hl)            ; Compare
  7691.         jr      z,l245a         ; Match
  7692.         inc     hl              ; Skip character
  7693.         inc     de              ; Skip address
  7694.         inc     de
  7695.         djnz    l2450           ; Go thru table
  7696.         scf                     ; Indicate no match
  7697.         ret
  7698. l245a:
  7699.         ex      de,hl
  7700.         ld      e,(hl)          ; Fetch address
  7701.         inc     hl
  7702.         ld      d,(hl)
  7703.         ex      de,hl
  7704.         ret
  7705. ;
  7706. l2460:
  7707.         db      'LWMECRSXDQO'
  7708. MainLen equ     $-l2460
  7709. l246b:
  7710.         db      'MCHSEFQ'
  7711. SubLen  equ     $-l246b
  7712. l2472:
  7713.         dw      l2cce           ; L - Log drive
  7714.         dw      l24c9           ; W - Work file
  7715.         dw      l249a           ; M - Main file
  7716.         dw      l2af8           ; E - Edit
  7717.         dw      l2827           ; C - Compile
  7718.         dw      l2a97           ; R - Run
  7719.         dw      l2639           ; S - Save
  7720.         dw      l2b2d           ; X - eXecute
  7721.         dw      l2b93           ; D - Directory
  7722.         dw      l2b24           ; Q - Quit
  7723.         dw      l2379           ; O - Options
  7724. l2488:
  7725.         dw      l2740           ; M - Compile Memory
  7726.         dw      l2744           ; C - Compile Com-file
  7727.         dw      l2748           ; H - Compile cHn-file
  7728.         dw      l2750           ; S - Start address
  7729.         dw      l276e           ; E - End address
  7730.         dw      l279b           ; F - Find run-time error
  7731.         dw      l2496           ; Q - Quit
  7732. ;
  7733. ; ##########################
  7734. ; ### SUB MENUE Q - Quit ###
  7735. ; ##########################
  7736. ;
  7737. l2496:
  7738.         pop     hl
  7739.         jp      l227a           ; Display menue
  7740. ;
  7741. ; ################################
  7742. ; ### MAIN MENUE M - Main file ###
  7743. ; ################################
  7744. ;
  7745. l249a:
  7746.         call    l0200
  7747.         db      cr,lf
  7748.         db      'Main file name'
  7749.         db      null
  7750.         call    l2d9f           ; Init a bit
  7751.         call    l2261           ; Input string
  7752.         ld      a,0
  7753.         ld      (l44f9+Fdrv),a  ; Set default drive
  7754.         ret     z
  7755.         call    l2d2a           ; Prepare .PAS file
  7756.         ld      de,l44f9        ; Point to main file
  7757.         ld      hl,l005c
  7758.         ld      bc,FCBlen
  7759.         ldir                    ; Unpack FCB
  7760.         ret
  7761. ;
  7762. ; ################################
  7763. ; ### MAIN MENUE W - Work file ###
  7764. ; ################################
  7765. ;
  7766. l24c9:
  7767.         ld      hl,l25bc
  7768.         ld      (l259d+1),hl    ; Redirect error
  7769.         call    l2601           ; Save work file
  7770.         call    l0200
  7771.         db      cr,lf
  7772.         db      'Work file name'
  7773.         db      null
  7774.         call    l2261           ; Input string
  7775.         ld      a,0
  7776.         ld      (l451d+Fdrv),a  ; Set no work file
  7777.         jr      nz,l24f6        ; Got input
  7778.         call    l2d8f           ; Init session
  7779.         jp      l223b           ; Enter menue
  7780. l24f6:
  7781.         call    l2d2a           ; Prepare .PAS file
  7782.         ld      de,l451d
  7783.         ld      hl,l005c
  7784.         ld      bc,FCBlen
  7785.         ldir                    ; Unpack work file
  7786.         jr      l250c           ; Init and load text file
  7787. ;
  7788. ; Init a bit and load wirk file into memory
  7789. ;
  7790. l2506:
  7791.         ld      hl,l25b7
  7792.         ld      (l259d+1),hl    ; Redirect error
  7793. l250c:
  7794.         ld      hl,l25eb
  7795.         ld      (l257c+1),hl    ; Set vector for file too big
  7796.         call    l2d8f           ; Init session
  7797.         ld      de,l451d
  7798. ;
  7799. ; Load text file
  7800. ; ENTRY Reg DE points to FCB
  7801. ; EXIT  Reg HL points to  end  of memory
  7802. ;
  7803. l2518:
  7804.         ld      hl,(l4544)      ; Get start of text
  7805.         ld      (l4460),hl      ; Set block start pointer
  7806.         ld      (l4462),hl      ; Set block end pointer
  7807.         ld      (l4450),hl      ; Set current memory pointer
  7808.         ld      (l4454),hl      ; Set block pointer
  7809.         ld      (l4458),hl      ; Set edit pointer
  7810.         ld      (curstartofpage),hl     ; Set start of screen
  7811.         ld      bc,(l4548)      ; Get top of available memory
  7812.         call    l253b           ; Load file
  7813.         ld      (hl),cr         ; Close last line
  7814.         inc     hl
  7815.         ld      (l4546),hl      ; Set end of text
  7816.         ret
  7817. ;
  7818. ; Load a file
  7819. ; ENTRY Reg BC holds last available address
  7820. ;       Reg DE holds FCB
  7821. ;       Reg HL holds start address
  7822. ; EXIT  Reg HL holds end address
  7823. ;
  7824. l253b:
  7825.         push    hl
  7826.         push    bc
  7827.         push    de
  7828.         call    l0200           ; Tell action
  7829.         db      cr,lf
  7830.         db      'Loading '
  7831.         db      null
  7832.         call    l2df8           ; Tell name of file
  7833.         ld      de,l005c
  7834.         call    l26dc           ; Clear FCB
  7835.         pop     hl
  7836.         ld      bc,l0024
  7837.         ldir
  7838.         ld      c,_open
  7839.         call    BDOS_with_FCB1          ; Open file
  7840. l2560:
  7841.         ;push   af
  7842.         ;ld     de,l7957
  7843.         ;ld     c,_setdma
  7844.         ;call   l7265           ; Set disk buffer
  7845.         ;pop    af
  7846.         pop     bc
  7847.         pop     hl
  7848.         inc     a               ; Test file found
  7849.         jr      z,l259d         ; Nope
  7850.         ld      (l7b6d),bc      ; Set last memory address
  7851. l2573:
  7852.         ld      bc,(l7b6d)      ; Get last memory address
  7853.         dec     b
  7854.         or      a
  7855.         sbc     hl,bc           ; Test room in memory
  7856.         add     hl,bc
  7857. l257c:
  7858.         jp      nc,a_DUMMY      ; Nope
  7859.         push    hl
  7860.          ld     de,l7957
  7861.          ld     c,_setdma
  7862.          call   l7265           ; Set disk buffer
  7863.          ;??? а как же de=fcb?
  7864.         ld      c,_rdseq
  7865.         call    BDOS_with_FCB1          ; Read record from file
  7866.         pop     hl
  7867.         ;or     a               ; Test end of file
  7868.         ;ret    nz              ; Yeap
  7869.          cp 128
  7870.          ret z ;EOF in NedoOS
  7871.         if 1==1
  7872. ;CP/M has eofs in the end of last sector?
  7873. ;do this by hand:
  7874.         or a
  7875.         jr z,load_noaddeofs ;full sector
  7876. ;a=128+bytes loaded
  7877.         neg
  7878. ;a=128-bytes loaded
  7879.         ld b,a
  7880.         ld de,l7957+127 ; Point to buffer end
  7881.         ld a,eof;-1
  7882.         ld (de),a
  7883.         dec de
  7884.         djnz $-2
  7885. load_noaddeofs
  7886.         endif
  7887.         ld      de,l7957        ; Point to buffer
  7888.         ld      b,RecLng
  7889. l258d:
  7890.          ;ld (hl),eof ;why there was not?
  7891.          ;inc hl
  7892.         ld      a,(de)          ; Scan for EOF
  7893.         cp      -1
  7894.          ;jr z,$
  7895.         ret     z
  7896.         and     NOMSB ;why???
  7897.         cp      eof
  7898.          ;jr z,$
  7899.         ret     z
  7900.          ;dec hl
  7901.         ld      (hl),a          ; Unpack data
  7902.         inc     hl
  7903.         inc     de
  7904.         djnz    l258d
  7905.         jr      l2573
  7906. l259d:
  7907.         jp      a_DUMMY         ; *** REDIRECTED ***
  7908. ;
  7909. ; Tell file not found
  7910. ;
  7911. l25a0:
  7912.         call    l0200
  7913.         db      cr,lf
  7914.         db      'File not found'
  7915.         db      null
  7916. l25b4:
  7917.         jp      l2e76           ; Get ESCape
  7918. ;
  7919. ; Redirected error if work file read error
  7920. ;
  7921. l25b7:
  7922.         call    l25a0           ; Tell file not found
  7923.         jr      l25ee
  7924. ;
  7925. ; Redirected error if work file not found
  7926. ;
  7927. l25bc:
  7928.         call    l0200
  7929.         db      cr,lf
  7930.         db      'New File'
  7931.         db      null
  7932.         inc     hl
  7933.         push    hl
  7934.         ld      hl,1000
  7935.         call    l021d           ; Delay one second
  7936.         pop     hl
  7937.         ret
  7938. ;
  7939. ; Tell file too big
  7940. ;
  7941. l25d4:
  7942.         ld      hl,(l4546)      ; Get end of text
  7943.         call    l0200
  7944.         db      cr,lf
  7945.         db      'File too big'
  7946.         db      null
  7947.         jr      l25b4
  7948. ;
  7949. ; Process file too big error
  7950. ;
  7951. l25eb:
  7952.         call    l25d4           ; Tell file too big
  7953. l25ee:
  7954.         xor     a
  7955.         ld      (l451d+Fdrv),a  ; Indicate no file
  7956.         jp      l223b           ; Enter menue
  7957. ;
  7958. ; Set extension .BAK
  7959. ;
  7960. l25f5:
  7961.         ld      hl,l005c+Fdrv+Fname
  7962.         ld      (hl),'B'
  7963.         inc     hl
  7964.         ld      (hl),'A'
  7965.         inc     hl
  7966.         ld      (hl),'K'
  7967.         ret
  7968. ;
  7969. ; Save work file on request
  7970. ;
  7971. l2601:
  7972.         db      skip
  7973. ;
  7974. ; Save work file on request
  7975. ;
  7976. l2602:
  7977.         xor     a
  7978.         ex      af,af'
  7979.         ld      a,(l447f)       ; Test text changed
  7980.         or      a
  7981.         ret     z               ; Nope
  7982.         ex      af,af'
  7983.         or      a               ; Test request
  7984.         jr      z,l2639         ; Save file if not
  7985.         call    l0200
  7986.         db      'Workfile '
  7987.         db      null
  7988.         call    l3135           ; Type name of file
  7989.         call    l0200
  7990.         db      ' not saved. Save'
  7991.         db      null
  7992.         xor     a
  7993.         ld      (l447f),a       ; Set no text changed
  7994.         call    l2d21           ; Ask for YES or NO
  7995.         ret     z               ; NO
  7996. ;
  7997. ; ###########################
  7998. ; ### MAIN MENUE S - Save ###
  7999. ; ###########################
  8000. ;
  8001. l2639:
  8002.         call    l2d50           ; Get file
  8003.         ld      hl,l451d
  8004.         push    hl
  8005.         ld      de,l005c
  8006.         ld      bc,FCBlen
  8007.         ldir                    ; Unpack file
  8008.         call    l0200           ; Tell action
  8009.         db      cr,lf
  8010.         db      'Saving '
  8011.         db      null
  8012.         ld      de,l005c
  8013.         call    l2df8           ; Tell name of file
  8014.         ld      hl,(l4546)      ; Get end of text
  8015.         dec     hl
  8016.         ld      (hl),eof        ; Close text
  8017.         call    l25f5           ; Set extension .BAK
  8018.         call    l26d9           ; Clear FCB
  8019.         ld      c,_delete
  8020.         call    l7265           ; Delete file
  8021.         ld      hl,l005c+Fdrv
  8022.         ld      de,l005c+DIRlen
  8023.         xor     a
  8024.         ld      (l447f),a       ; Set no text changed
  8025.         ld      (de),a
  8026.         inc     a
  8027.         ld      (l44f2),a       ; Set rename flag
  8028.         inc     de
  8029.         ld      bc,DIRlen-1
  8030.         ldir                    ; Unpack name
  8031.         pop     hl
  8032.         ld      de,l005c
  8033.         ld      bc,DIRlen
  8034.         ldir                    ; Get new file
  8035.         ld      c,_rename
  8036.         call    BDOS_with_FCB1          ; Rename it
  8037.         ld      hl,(l4544)      ; Get start of text
  8038. l2692:
  8039.         push    hl
  8040.         call    l26d9           ; Clear FCB
  8041.         ld      c,_make
  8042.         call    l7265           ; Create new file
  8043.         pop     hl
  8044.         inc     a
  8045.         jr      z,l26ed         ; Error creating file
  8046.         push    hl
  8047.         ld      de,l7957
  8048.         push    de
  8049.         ld      c,_setdma
  8050.         call    l7265           ; Set disk buffer
  8051.         pop     de
  8052.         pop     hl
  8053.         ld      b,RecLng        ; Set length of buffer
  8054. l26ad:
  8055.         ld      a,(hl)          ; Get from memory
  8056.         inc     hl
  8057. l26af:
  8058.         ld      (de),a          ; Put to buffer
  8059.         inc     de
  8060.         djnz    l26c6
  8061.         ld      b,a             ; Save last character
  8062.         push    bc
  8063.         push    hl
  8064.         ld      c,_wrseq
  8065.         call    BDOS_with_FCB1          ; Write record to file
  8066.         pop     hl
  8067.         pop     bc
  8068.         or      a               ; Test success
  8069.         jr      nz,l26fe        ; Nope, write error
  8070.         ld      de,l7957        ; Reset pointer
  8071.         ld      a,b             ; Get back last character
  8072.         ld      b,RecLng        ; Reset buffer length
  8073. l26c6:
  8074.         cp      eof             ; Test end of file
  8075.         jr      nz,l26ad        ; Nope, go on
  8076.         ld      a,b
  8077.         sub     RecLng          ; Test record boundary
  8078.         ld      a,eof
  8079.         jr      nz,l26af        ; Nope, write end
  8080.         ld      c,_close        ; Close file
  8081. ;
  8082. ; Do OS call with standard FCB
  8083. ;
  8084. BDOS_with_FCB1:
  8085.         ld      de,l005c
  8086.         jp      l7265           ; Do file call
  8087. ;
  8088. ; Clear FCB
  8089. ;
  8090. l26d9:
  8091.         ld      de,l005c
  8092. ;
  8093. ; Clear FCB ^DE
  8094. ;
  8095. l26dc:
  8096.         push    de
  8097.         ld      hl,_ex
  8098.         add     hl,de           ; Point to extent
  8099.         ld      (hl),0          ; Clear it
  8100.         ld      d,h
  8101.         ld      e,l
  8102.         inc     de
  8103.         ld      bc,FCBlen-_ex-1
  8104.         ldir                    ; Clear remainder
  8105.         pop     de
  8106.         ret
  8107. ;
  8108. ; Create file error
  8109. ;
  8110. l26ed:
  8111.         call    l0200           ; Tell error
  8112.         db      '  Directory'
  8113.         db      null
  8114.         jr      l2708
  8115. ;
  8116. ; Write file error
  8117. ;
  8118. l26fe:
  8119.         call    l0200           ; Tell error
  8120.         db      '  Disk'
  8121.         db      null
  8122. l2708:
  8123.         call    l0200
  8124.         db      ' full'
  8125.         db      null
  8126.         call    l2e76           ; Get ESCape
  8127.         call    l26d9           ; Clear FCB
  8128.         ld      c,_delete
  8129.         call    BDOS_with_FCB1          ; Delete file
  8130.         ld      a,(l44f2)       ; Test to be renamed
  8131.         or      a
  8132.         ret     z               ; Nope
  8133.         ld      (l447f),a       ; Set text changed
  8134.         ld      hl,l005c+Fdrv
  8135.         ld      de,l005c+DIRlen
  8136.         xor     a
  8137.         ld      (l44f2),a       ; Clear rename flag
  8138.         ld      (de),a          ; Clear name entry
  8139.         inc     de
  8140.         ld      bc,DIRlen-1
  8141.         ldir                    ; Unpack FCB
  8142.         call    l25f5           ; Set extension .BAK
  8143.         ld      c,_rename
  8144.         call    BDOS_with_FCB1          ; Rename file
  8145.         jp      l223b           ; Enter menue
  8146. ;
  8147. ; ####################################
  8148. ; ### SUB MENUE M - Compile Memory ###
  8149. ; ####################################
  8150. ;
  8151. l2740:
  8152.         ld      a,1             ; Set memory
  8153.         jr      l274a
  8154. ;
  8155. ; ######################################
  8156. ; ### SUB MENUE C - Compile Com-file ###
  8157. ; ######################################
  8158. ;
  8159. l2744:
  8160.         ld      a,2             ; Set .COM file
  8161.         jr      l274a
  8162. ;
  8163. ; ######################################
  8164. ; ### SUB MENUE H - Compile cHn-file ###
  8165. ; ######################################
  8166. ;
  8167. l2748:
  8168.         ld      a,3             ; Set .CHN file
  8169. l274a:
  8170.         ld      (l44f3),a       ; Set compile mode
  8171.         jp      l2d9f           ; Force compile
  8172. ;
  8173. ; ###################################
  8174. ; ### SUB MENUE S - Start address ###
  8175. ; ###################################
  8176. ;
  8177. l2750:
  8178.         call    l0200           ; Tell what we want
  8179.         db      'Start address'
  8180.         db      null
  8181.         call    l2261           ; Input string
  8182.         ld      hl,l20e2        ; Set default
  8183.         call    nz,l2dd9        ; Get new hex value
  8184.         ld      (l44f4),hl      ; Save new start address
  8185.         ret
  8186. ;
  8187. ; #################################
  8188. ; ### SUB MENUE E - End address ###
  8189. ; #################################
  8190. ;
  8191. l276e:
  8192.         call    l0200           ; Tell what we want
  8193.         db      'End address'
  8194.         db      null
  8195.         call    l2261           ; Input string
  8196.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  8197.         ld      bc,-MEMGAP
  8198.         add     hl,bc           ; Calculate default
  8199.         call    nz,l2dd9        ; Get new hex value
  8200.         ld      (l44f6),hl      ; Set top of available memory
  8201.         ret
  8202. ;
  8203. ; Exit memory resident program
  8204. ;
  8205. l278e:
  8206.         call    l20e5           ; Set up environment
  8207.         ld      hl,(l00ce)      ; Get current PC
  8208.         ld      a,h
  8209.         or      l
  8210.         jr      nz,l27b1        ; Process error
  8211.         jp      l223b           ; Enter menue
  8212. ;
  8213. ; #########################################
  8214. ; ### SUB MENUE F - Find run-time error ###
  8215. ; #########################################
  8216. ;
  8217. l279b:
  8218.         call    l0200           ; Tell what we want
  8219.         db      'Enter PC'
  8220.         db      null
  8221.         call    l2261           ; Input string
  8222.         ret     z               ; Empty
  8223.         call    l2dd9           ; Get hex PC
  8224.         ld      (l00ce),hl      ; Set current PC
  8225. l27b1:
  8226.         call    l01e1           ; Give new line
  8227.         call    l27d7           ; Load file into memory
  8228.         ld      hl,0
  8229.         ld      (l7904),hl      ; Clear address
  8230.         ld      a,2
  8231.         ld      (l7900),a       ; Set searching
  8232.         call    l0200           ; Tell searching
  8233.         db      cr,lf
  8234.         db      'Searching'
  8235.         db      null
  8236.         call    l2d9f           ; Force compile
  8237.         jp      l28d0           ; Go compile
  8238. ;
  8239. ; Load file into memory
  8240. ;
  8241. l27d7:
  8242.         call    l2d4b           ; Test work file defined
  8243.         call    z,l2d50         ; Get file if not
  8244.         call    l2d7a           ; Test main file here
  8245. l27e0:
  8246.         ld      hl,l451d
  8247.         jr      nz,l27ea        ; Got any file
  8248.         call    l2d50           ; Get file
  8249.         jr      l2808
  8250. l27ea:
  8251.         call    l2d7f           ; Test same files
  8252.         jr      z,l27e0         ; Yeap, get another one
  8253.         call    l2602           ; Save work file
  8254.         ld      hl,l25eb
  8255.         ld      (l257c+1),hl    ; Set vector for file too big
  8256.         ld      hl,l25b7
  8257.         ld      (l259d+1),hl    ; Set vector for read error
  8258.         ld      de,l44f9        ; Point to main file
  8259.         push    de
  8260.         call    l2518           ; Load text file
  8261.         ld      a,1
  8262.         pop     hl
  8263. l2808:
  8264.         ld      (l44f1),a       ; Re/Set file flag
  8265.         ld      de,l7933
  8266.         ld      bc,FCBlen
  8267.         ldir                    ; Unpack file
  8268.         xor     a
  8269.         ld      (l7900),a       ; Set compile to memory
  8270.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  8271.         ld      (l790a),hl      ; Set end of code
  8272. l281d:
  8273.         ld      hl,(l4546)      ; Get end of text
  8274.         ld      (hl),eof        ; Set end of file
  8275.         inc     hl
  8276.         ld      (l7904),hl      ; Set for code start address
  8277.         ret
  8278. ;
  8279. ; ##############################
  8280. ; ### MAIN MENUE C - Compile ###
  8281. ; ##############################
  8282. ;
  8283. l2827:
  8284.         call    l27d7           ; Load file into memory
  8285.         ld      a,(l44f3)       ; Get compile mode
  8286.         dec     a               ; Test compile to memory
  8287.         jp      z,l28aa         ; Yeap
  8288.         dec     a               ; Test compile to .COM file
  8289.         push    af
  8290.         jr      nz,l283c        ; Nope
  8291.         ld      a,'C'           ; Load .COM
  8292.         ld      hl,'O'+'M'*256
  8293.         jr      l2841
  8294. l283c:
  8295.         ld      a,'C'           ; Load .CHN
  8296.         ld      hl,'H'+'N'*256
  8297. l2841:
  8298.         ld      (l7933+Fdrv+Fname),a
  8299.         ld      (l7933+Fdrv+Fname+1),hl
  8300.         ld      a,1
  8301.         ld      (l7900),a       ; Set compile to file
  8302.         ld      hl,(l44f4)      ; Get start address of compiler
  8303.         ld      (l7904),hl      ; Save
  8304.         ld      hl,(l44f6)      ; Get top of available memory
  8305.         ld      (l790a),hl      ; Save also
  8306.         ld      de,l7933
  8307.         push    de
  8308.         call    l26dc           ; Clear FCB
  8309.         ld      c,_delete
  8310.         call    l7265           ; Delete file
  8311.         pop     de
  8312.         ld      c,_make
  8313.         call    l7265           ; Create new file
  8314.         inc     a               ; Test success
  8315.         jp      z,l2a5a         ; Nope, error
  8316.         pop     af              ; Get back .COM or .CHN
  8317.         ld      hl,0x0100;TPA
  8318.         jr      z,l2877         ; Got .COM
  8319.         ld      hl,(l7904)      ; Get code start address
  8320. l2877:
  8321.         ld      (l7902),hl      ; Save for current PC
  8322.         ex      de,hl
  8323. l287b:
  8324.         ld      hl,(l7904)      ; Get code start address
  8325.         scf
  8326.         sbc     hl,de           ; Test end reached
  8327.         jr      c,l28a9         ; Yeap
  8328.         ld      hl,(l7904)      ; Get code start address
  8329.         ld      (progstartaddr),hl;(TPA+1),hl   ; Set as start address
  8330.         push    de
  8331.         ld      c,_setdma
  8332.         call    l7265           ; Set disk buffer
  8333.         ld      c,_wrseq
  8334.         ld      de,l7933
  8335.         call    l7265           ; Write record to file
  8336.         pop     de
  8337.         ld      hl,l20e2
  8338.         ld      (progstartaddr),hl;(TPA+1),hl   ; Reset start address
  8339.         ;or     a               ; Test I/O success
  8340.         ;jp     nz,l2a5a        ; Error, disk full
  8341.         ld      hl,RecLng
  8342.         add     hl,de           ; Advance buffer
  8343.         ex      de,hl
  8344.         jr      l287b
  8345. l28a9:
  8346.         db      skip
  8347. l28aa:
  8348.         xor     a
  8349.         call    l0200           ; Tell compiling
  8350. ;
  8351.         db      cr,lf
  8352.         db      'Compiling '
  8353.         db      null
  8354.         ld      de,l7933
  8355.         or      a               ; Test compile to memory
  8356.         jr      z,l28cd         ; Yeap
  8357.         call    l0200           ; Indicate file
  8358. ;
  8359.         db      ' --> '
  8360.         db      null
  8361.         call    l2df8           ; Tell name of file
  8362. l28cd:
  8363.         call    l2d9f           ; Force compile
  8364. l28d0:
  8365.         call    l01e1           ; Give new line
  8366.         call    l454a           ; Compile
  8367.         ld      a,(l7901)       ; Get error code
  8368.         cp      _ABORT          ; Test abort
  8369.         jr      nz,l28fa        ; Nope
  8370.         call    l0200           ; Tell abortion
  8371. ;
  8372.         db      cr,lf,lf
  8373.         db      'Compilation aborted'
  8374.         db      null
  8375.         jp      l223b           ; Enter menue
  8376. l28fa:
  8377.         call    l0200           ; Tell lines
  8378.         db      ' lines'
  8379.         db      cr,lf,lf,null
  8380.         ld      a,(l7901)       ; Get error code
  8381.         or      a               ; Test any error
  8382.         jp      nz,l2970        ; Yeap
  8383.         ld      a,(l7900)       ; Get compile flag
  8384.         cp      2               ; Test searching
  8385.         jr      nz,l292a        ; Nope
  8386.         call    l2a7a           ; Tell error position
  8387.         call    l0200
  8388.         db      'not found'
  8389.         db      cr,lf,null
  8390.         jp      l223b           ; Re-enter menue
  8391. l292a:
  8392.         or      a               ; Test compile to memory
  8393.         jr      z,l293a         ; Yeap
  8394.         ld      hl,(l7904)      ; Get code start address
  8395.         ld      de,l20e2        ; Get start of application
  8396.         or      a
  8397.         sbc     hl,de
  8398.         add     hl,de
  8399.         call    nz,l232e        ; Tell free
  8400. l293a:
  8401.         call    l0200
  8402.         db      'Code: '
  8403.         db      null
  8404.         ld      de,(l7904)      ; Get code start address
  8405.         ld      hl,(l7906)      ; Get code end address
  8406.         push    hl
  8407.         dec     hl
  8408.         call    l2338           ; Tell free bytes
  8409.         pop     de
  8410.         ld      hl,(l7908)      ; Get start of data
  8411.         push    hl
  8412.         call    l232e           ; Tell free
  8413.         pop     de
  8414.         inc     de
  8415.         ld      hl,(l790a)      ; Get end of code
  8416.         call    l0200
  8417.         db      'Data: '
  8418.         db      null
  8419.         call    l2338           ; Tell free bytes
  8420.         ld      a,-1
  8421.         ld      (l4542),a       ; Set no compile
  8422.         ret
  8423. ;
  8424. ; Process compiler error
  8425. ;
  8426. l2970:
  8427.         cp      _DskFull        ; Test disk error
  8428.         jp      nc,l2a5a        ; Error, disk full
  8429.         cp      _FndRTerr       ; Test run-time error found
  8430.         jr      nc,l29ec        ; Yeap
  8431.         ld      b,a             ; Save error number
  8432.         call    l0200           ; Tell error
  8433.         db      'Error '
  8434.         db      null
  8435.         ld      h,0
  8436.         ld      l,b             ; Build 16 bit number
  8437.         push    bc
  8438.         call    l2e61           ; Print it
  8439.         pop     bc
  8440.         ld      a,(l4541)       ; Test error message file read
  8441.         or      a
  8442.         jr      z,l29f8         ; No message file
  8443.         ld      hl,(l429e)      ; Get base of message file
  8444. l2995:
  8445.         ld      a,(hl)          ; Get character
  8446.         cp      eof             ; Test end of message
  8447.         jr      z,l29f8         ; Yeap
  8448.         cp      ' '             ; Test control
  8449.         jr      c,l29ad         ; Yeap, skip it
  8450.         sub     '0'             ; Build number - always two digits
  8451.         ld      c,a
  8452.         add     a,a
  8453.         add     a,a
  8454.         add     a,c
  8455.         add     a,a
  8456.         inc     hl
  8457.         add     a,(hl)          ; Combine number
  8458.         sub     '0'             ; Fix it
  8459.         inc     hl
  8460.         cp      b               ; Test message found
  8461.         jr      z,l29b6         ; Got it
  8462. l29ad:
  8463.         ld      a,(hl)
  8464.         inc     hl
  8465.         cp      cr              ; Skip to end of line
  8466.         jr      nz,l29ad
  8467.         inc     hl
  8468.         jr      l2995           ; Try next line
  8469. l29b6:
  8470.         call    l0200           ; Tell result
  8471. ;
  8472.         db      ': '
  8473.         db      null
  8474. l29bc:
  8475.         ld      a,(hl)          ; Get character
  8476.         cp      cr              ; Test end of text
  8477.         jr      z,l29f8         ; That's all
  8478.         cp      ' '             ; Test combined message
  8479.         jr      nc,l29e6        ; Nope
  8480.         ld      de,(l429e)      ; Get base of message file
  8481. l29c9:
  8482.         ld      a,(de)          ; Get character
  8483.         inc     de
  8484.         cp      ' '             ; Test printable
  8485.         jr      nc,l29dd        ; Yeap, skip it
  8486.         cp      (hl)            ; Test extension found
  8487.         jr      nz,l29dd        ; Nope
  8488. l29d2:
  8489.         ld      a,(de)          ; Get from extended part
  8490.         cp      cr              ; Test end of line
  8491.         jr      z,l29e9         ; Yeap
  8492.         call    puttoconsole_a          ; Put substring to console
  8493.         inc     de
  8494.         jr      l29d2
  8495. l29dd:
  8496.         ld      a,(de)
  8497.         inc     de
  8498.         cp      cr              ; Skip this line
  8499.         jr      nz,l29dd
  8500.         inc     de
  8501.         jr      l29c9
  8502. l29e6:
  8503.         call    puttoconsole_a          ; Put to console
  8504. l29e9:
  8505.         inc     hl
  8506.         jr      l29bc           ; Loop on
  8507. ;
  8508. ; Got position of run-time error
  8509. ;
  8510. l29ec:
  8511.         call    l2a7a           ; Tell error position
  8512.         call    l0200
  8513.         db      'found'
  8514.         db      null
  8515. l29f8:
  8516.         xor     a
  8517.         ld      (l44f1),a       ; Clear file flag
  8518.         ld      a,(l790e)       ; Test read from memory
  8519.         or      a
  8520.         jr      z,l2a41         ; Nope
  8521.         ld      a,'.'
  8522.         call    puttoconsole_a          ; Put to console
  8523.         call    l2602           ; Save work file
  8524.         ld      de,l451d
  8525.         ld      hl,l790f
  8526.         ld      bc,Fdrv+Fname+Fext
  8527.         ldir                    ; Copy include file
  8528.         call    l2506           ; Load it
  8529.         call    l0200
  8530.         db      cr,lf
  8531.         db      'Error found in above include file'
  8532.         db      null
  8533.         jr      l2a51
  8534. l2a41:
  8535.         call    l2d7a           ; Test main file here
  8536.         jr      z,l2a51         ; Nope
  8537.         ld      de,l451d
  8538.         ld      hl,l44f9        ; Point to main file
  8539.         ld      bc,Fdrv+Fname+Fext
  8540.         ldir                    ; Copy file
  8541. l2a51:
  8542.         call    l2e76           ; Get ESCape
  8543.         ld      hl,(l790c)      ; Fetch current editor address
  8544.         jp      l2afe           ; And fall into edit
  8545. ;
  8546. ; Process disk full
  8547. ;
  8548. l2a5a:
  8549.         call    l0200           ; Tell error
  8550. ;
  8551.         db      'Disk or directory full'
  8552.         db      null
  8553.         call    l2e76           ; Get ESCape
  8554.         jp      l223b           ; Enter menue
  8555. ;
  8556. ; Tell error position message
  8557. ;
  8558. l2a7a:
  8559.         call    l0200
  8560.         db      'Run-time error position '
  8561.         db      null
  8562.         ret
  8563. ;
  8564. ; ##########################
  8565. ; ### MAIN MENUE R - Run ###
  8566. ; ##########################
  8567. ;
  8568. l2a97:
  8569.         ld      a,(l4542)       ; Get compile flag
  8570.         or      a
  8571.         call    z,l2827         ; Compile before run
  8572.         ld      a,(l44f3)       ; Get compile flag
  8573.         dec     a
  8574.         jr      z,l2adf         ; Got to memory
  8575.         dec     a
  8576.         ret     nz              ; Skip chain
  8577.         call    l2b33           ; Load overlay file
  8578.         ret     z               ; Not found
  8579.         call    l2d7a           ; Test main file here
  8580.         ld      hl,l451d
  8581.         jr      z,l2ab5         ; Nope
  8582.         ld      hl,l44f9        ; Point to main file
  8583. l2ab5:
  8584.         ld      de,l7933
  8585.         ld      bc,Fdrv+Fname+Fext
  8586.         ldir                    ; Unpack FCB
  8587.         ld      a,'C'           ; Set .COM
  8588.         ld      hl,'O'+'M'*256
  8589.         ld      (l7933+Fdrv+Fname),a
  8590.         ld      (l7933+Fdrv+Fname+1),hl
  8591.         ld      de,l7933
  8592.         call    l26dc           ; Clear FCB
  8593.         push    de
  8594.         ld      c,_open
  8595.         call    l7265           ; Open file
  8596.         pop     hl
  8597.         inc     a               ; Test file here
  8598.         jp      z,l2104         ; Nope, init session
  8599.         ld      de,l42a0        ; Set dummy parameter
  8600.         jp      l2b7a           ; Prepare overlay
  8601. l2adf:
  8602.         ld      (l0080),a       ; Clear parameter
  8603.         call    l281d           ; Set text and code pointer
  8604.         call    l0200           ; Tell running
  8605.         db      cr,lf
  8606.         db      'Running'
  8607.         db      cr,lf,null
  8608.         ld      hl,(l7904)      ; Get code start address
  8609.         jp      (hl)            ; And go
  8610. ;
  8611. ; ###########################
  8612. ; ### MAIN MENUE E - Edit ###
  8613. ; ###########################
  8614. ;
  8615. l2af8:
  8616.         call    l2d50           ; Get file
  8617.         ld      hl,-1           ; Set zero offset
  8618. l2afe:
  8619.         push    hl
  8620.         ld      hl,(l00a6+1)
  8621.         ld      (l421e),hl      ; Change I/O
  8622.         ld      hl,l4214
  8623.         ld      (l00a6+1),hl
  8624.         pop     hl
  8625.         jp      l2e91           ; Go edit
  8626. ;
  8627. ; Control: EXIT EDITOR
  8628. ;
  8629. l2b0f:
  8630.         call    l3e40           ; Sample character
  8631.         ld      hl,(l0169)      ; Get screen lines
  8632.         dec     l               ; Fix row
  8633.         ld      h,0             ; Set column
  8634.         call    l02a2           ; Position cursor
  8635.         ld      hl,(l421e)
  8636.         ld      (l00a6+1),hl    ; Reset I/O
  8637.         jp      l223b
  8638. ;
  8639. ; ###########################
  8640. ; ### MAIN MENUE Q - Quit ###
  8641. ; ###########################
  8642. ;
  8643. l2b24:
  8644.         call    l2601           ; Save work file
  8645.         call    l0310           ; Give lead out sequence
  8646.         jp      OS              ; Exit to OS
  8647. ;
  8648. ; ##############################
  8649. ; ### MAIN MENUE X - eXecute ###
  8650. ; ##############################
  8651. ;
  8652. l2b2d:
  8653.         call    l2b33           ; Load overlay file
  8654.         ret     z               ; Not found
  8655.         jr      l2b5a           ; Go
  8656. ;
  8657. ; Load overlay file
  8658. ; Z set says not found
  8659. ;
  8660. l2b33:
  8661.         call    l2601           ; Save work file
  8662.         ld      de,l217d        ; Set name
  8663.         ld      a,'O'
  8664.         ld      hl,'V'+'R'*256
  8665.         call    l2e20           ; Prepare .OVR file
  8666.         ret     z
  8667.         ld      de,a_OVLADR-RecLng
  8668. l2b45:
  8669.         ld      hl,RecLng
  8670.         add     hl,de           ; Build disk buffer address
  8671.         push    hl
  8672.         ex      de,hl
  8673.         ld      c,_setdma
  8674.         call    BDOS            ; Set disk buffer
  8675.         ld      c,_rdseq
  8676.         call    BDOS_with_FCB1          ; Read record
  8677.         pop     de
  8678.         ;or     a               ; Test end of file
  8679.         ;jr     z,l2b45         ; Nope, loop on
  8680.          cp 128 ;EOF in NedoOS
  8681.          jr nz,l2b45            ; Read was successfull
  8682.         ret
  8683. ;
  8684. ; Execute file
  8685. ;
  8686. l2b5a:
  8687.         call    l0200           ; Tell program
  8688.         db      cr,lf
  8689.         db      'Program'
  8690.         db      null
  8691.         call    l2261           ; Input string
  8692.         jp      z,l2104         ; No input
  8693.         ld      a,'C'
  8694.         ld      hl,'O'+'M'*256
  8695.         call    l2e20           ; Prepare .COM file
  8696.         jr      z,l2b5a         ; Not there, retry
  8697.         ld      hl,l005c
  8698. l2b7a:
  8699.         push    de              ; Set argument pointer
  8700.         push    hl              ; Set FCB
  8701.         ld      a,(l44f8)
  8702.         push    af              ; Set logged disk
  8703.         ld      hl,l03ee
  8704.         push    hl              ; Set parse file routine
  8705.         ld      hl,l00f4
  8706.         push    hl              ; Set available memory
  8707.         ld      hl,l4450
  8708.         push    hl              ; Set current memory pointer
  8709.         ld      hl,l2104
  8710.         push    hl              ; Set return address
  8711.         jp      a_OVLADR                ; Execute overlay
  8712. ;
  8713. ; ################################
  8714. ; ### MAIN MENUE D - Directory ###
  8715. ; ################################
  8716. fcbmask
  8717.         db 0
  8718.         db "???????????"
  8719.         ds FCB_sz-11-1
  8720. fcbmask_filename=fcbmask+FCB_FNAME
  8721. ;
  8722. l2b93:
  8723.         call    l0200
  8724.         db      'Dir mask'
  8725.         db      null
  8726.         call    l2261           ; Input string
  8727.         call    l03ee           ; Parse file
  8728.         ld      c,_retdsk
  8729.         call    l7265           ; Return current disk (return L=A=current drive)
  8730.         push    af
  8731.         push    af
  8732.         ld      a,(l005c)       ; Get disk
  8733.         or      a               ; Test default
  8734.         jr      z,l2bbb         ; Yeap
  8735.         pop     hl              ; Clean stack
  8736.         dec     a
  8737.         ld      e,a
  8738.         push    af              ; Set new disk
  8739.         ;ld     c,_seldsk
  8740.         ;call   l7265           ; Select disk
  8741. l2bbb:
  8742.         pop     af
  8743.         add     a,'A'           ; Make disk ASCII
  8744.         ld      (l2c8d),a       ; Save disk
  8745.         ;ld     de,l7957
  8746.         ;ld     c,_setdma
  8747.         ;call   l7265           ; Set disk buffer
  8748.         ld      de,0            ; Clear flag and count
  8749.         ld      c,_srcfrs
  8750. l2bce:
  8751.         push    de
  8752.          push bc
  8753.          ld     de,l7957
  8754.          ld     c,_setdma
  8755.          call   l7265           ; Set disk buffer
  8756.          pop bc
  8757.          ld de,fcbmask
  8758.         call    BDOS_with_FCB1          ; Search for file
  8759.         pop     de
  8760.         ld      c,a
  8761.         inc     a               ; Test valid one
  8762.         jr      z,l2c29         ; Nope
  8763.         ld      a,c
  8764.         add     a,a             ; Result *32
  8765.         add     a,a
  8766.         add     a,a
  8767.         add     a,a
  8768.         add     a,a
  8769.         ld      c,a
  8770.         ld      b,0
  8771.         ld      hl,l7957+_SYS
  8772.         add     hl,bc           ; Point to SYS bit
  8773.         bit     7,(hl)          ; Test set
  8774.         jr      nz,l2c25        ; Yeap, skip display
  8775.         ld      d,-1            ; Set any found flag
  8776.         ld      hl,l7957
  8777.         add     hl,bc           ; Point to entry
  8778.         inc     e               ; Test first file
  8779.         dec     e
  8780.         jr      nz,l2bff        ; Nope
  8781.         ld      a,(l0168)       ; Get screen columns
  8782.         dec     a
  8783.         ld      e,-1
  8784. l2bf8:
  8785.         inc     e
  8786.         sub     Dirlng          ; Calculate files per line
  8787.         jr      nc,l2bf8
  8788.         jr      l2c05
  8789. l2bff:
  8790.         call    l0200
  8791. ;
  8792.         db      ': '
  8793.         db      null
  8794. l2c05:
  8795.         ld      b,Fname+Fext    ; Set length
  8796. l2c07:
  8797.         inc     hl
  8798.         ld      a,(hl)
  8799.         and     NOMSB           ; Strip off offset
  8800.         call    puttoconsole_a          ; Put to console
  8801.         ld      a,b
  8802.         cp      Fext+1          ; Test extension
  8803.         ld      a,' '
  8804.         call    z,puttoconsole_a                ; Put blank to console if so
  8805.         djnz    l2c07
  8806.         dec     e               ; Test remainder in line
  8807.         jr      z,l2c22         ; Nope
  8808.         ld      a,' '
  8809.         call    puttoconsole_a          ; Put to console
  8810.         jr      l2c25
  8811. l2c22:
  8812.         call    l01e1           ; Give new line
  8813. l2c25:
  8814.         ld      c,_srcnxt       ; Search next
  8815.         jr      l2bce
  8816. l2c29:
  8817.         inc     e               ; Test any file left
  8818.         dec     e
  8819.         call    nz,l01e1        ; Give new line if so
  8820.         inc     d               ; Test any file found
  8821.         jr      z,l2c3e         ; Yeap
  8822.         call    l0200           ; Else tell it
  8823. ;
  8824.         db      'No file'
  8825.         db      cr,lf,null
  8826. l2c3e:
  8827.         call    l01e1           ; Give new line
  8828. ;
  8829. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8830. ; !!! FOLLOWING IS ERRONEOUS ON CP/M 3.x !!!
  8831. ; !!! USES BDOS FUNCTION 46 ON CP/M 3.x  !!!
  8832. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8833. ;
  8834.         ld      c,_getdpb
  8835.         call    BDOS            ; Fetch disk parameter block
  8836.         push    hl
  8837.         pop     ix              ; Copy it
  8838.         ld      a,(ix+3)        ; Get block mask
  8839.         inc     a               ; Fix
  8840.         rra                     ; DIV 8 (1-> 1k, 2->2k etc.)
  8841.         rra
  8842.         rra
  8843.         and     DPBMASK         ; Mask it
  8844.         ld      (l7b71),a       ; Save block size
  8845.         ld      l,(ix+5)        ; Fetch block count
  8846.         ld      h,(ix+6)
  8847.         ld      (l7b6f),hl      ; Save it
  8848.         inc     hl              ; Fix
  8849.         call    l2cc6           ; Build size in bytes
  8850.         push    hl              ; Save it
  8851. ;
  8852. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8853. ; !!! THE ALLOCATION VECTOR MAY BE FOUND IN ANOTHER !!!
  8854. ; !!! MEMORY BANK RUNNING CP/M 3.X.                 !!!
  8855. ; !!! THE NEXT CALCULATION MAY BE WRONG THEREFORE   !!!
  8856. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8857. ;
  8858.         ld      c,_getalv
  8859.         call    BDOS            ; Get allocation vector
  8860.         ex      de,hl
  8861.         ld      hl,(l7b6f)      ; Get block count
  8862.         ld      bc,0
  8863.         call    l2ca5           ; Get free blocks
  8864.         ld      h,b
  8865.         ld      l,c
  8866.         call    l2cc6           ; Build size in bytes
  8867.         call    l0200           ; Tell size
  8868. ;
  8869.         db      'Bytes Remaining On '
  8870. l2c8d:
  8871.         db      'X: '
  8872.         db      null
  8873.         ex      de,hl
  8874.         pop     hl              ; Get back total size
  8875.         or      a
  8876.         sbc     hl,de           ; Calculate free bytes
  8877.         call    l2e61           ; Print number
  8878.         ld      a,'k'
  8879.         call    puttoconsole_a          ; Put to console
  8880.         pop     af              ; Get back selected disk
  8881.         ld      e,a
  8882.        ret
  8883.         ;ld     c,_seldsk
  8884.         ;jp     l7265           ; Select disk
  8885. ;
  8886. ; BC holds resulting block count
  8887. ; DE holds allocation vector
  8888. ; HL holds block count
  8889. ;
  8890. ; BC holds free blocks
  8891. ;
  8892. l2ca5:
  8893.         push    bc
  8894.         ld      bc,-8
  8895.         add     hl,bc           ; Fix block count
  8896.         pop     bc
  8897.         ld      a,h             ; Get hi
  8898.         or      a
  8899.         ld      a,(de)
  8900.         jp      p,l2cb8
  8901. l2cb1:
  8902.         inc     l
  8903.         jr      z,l2cbd         ; Done, calculate free blocks
  8904.         or      a
  8905.         rra
  8906.         jr      l2cb1
  8907. l2cb8:
  8908.         call    l2cbd           ; Calculate free blocks from bits
  8909.         jr      l2ca5
  8910. ;
  8911. ; Calculate free blocks in reg BC from vector in Accu
  8912. ;
  8913. l2cbd:
  8914.         inc     de              ; Advance allocation vector
  8915. l2cbe:
  8916.         or      a               ; Test end of bit stream
  8917.         ret     z               ; Yeap
  8918.         rra                     ; Get resulting bit
  8919.         jr      nc,l2cbe        ; Not set
  8920.         inc     bc              ; Advance block count
  8921.         jr      l2cbe
  8922. ;
  8923. ; Build bytes in blocks
  8924. ;
  8925. l2cc6:
  8926.         ld      a,(l7b71)       ; Get block size
  8927. l2cc9:
  8928.         rra                     ; Get bit
  8929.         ret     c               ; Got it
  8930.         add     hl,hl           ; Double byte count
  8931.         jr      l2cc9
  8932. ;
  8933. ; ################################
  8934. ; ### MAIN MENUE L - Log drive ###
  8935. ; ################################
  8936. ;
  8937. l2cce:
  8938.         call    l0200           ; Tell what we expect
  8939. ;
  8940.         db      'New drive'
  8941.         db      null
  8942.         call    l2261           ; Input string
  8943.         ld      a,(de)
  8944.         cp      eof             ; Test empty input
  8945.         jr      nz,l2ce8        ; Nope
  8946.         ld      a,(DU)          ; Get from caller
  8947.         jr      l2cf1
  8948. l2ce8:
  8949.         call    l04a6           ; Convert to upper case
  8950.         sub     'A'             ; Verify in range
  8951.         ret     c
  8952.         cp      'P'-'A'+1
  8953.         ret     nc
  8954. l2cf1:
  8955.         if 1==1
  8956.         ret
  8957.         else
  8958.         push    af
  8959.         ld      c,_resdsk
  8960.         call    l7265           ; Reset disk system
  8961.         pop     af
  8962.         ld      (DU),a          ; Set new disk
  8963.         ld      e,a
  8964.         ld      c,_seldsk
  8965.         jp      l7265           ; Select disk
  8966.         endif
  8967. ;
  8968. ; Ask for YES or NO - Z set is NO
  8969. ;
  8970. l2d01:
  8971.         call    l0200           ; Tell what we does expect
  8972. ;
  8973.         db      ' (Y/N)? '
  8974.         db      null
  8975. l2d0d:
  8976.         call    readfromkbd             ; Read character
  8977.         call    l04a6           ; Convert to upper case
  8978.         cp      'Y'             ; Test YES
  8979.         jr      z,l2d1b
  8980.         cp      'N'             ; Test NO
  8981.         jr      nz,l2d0d
  8982. l2d1b:
  8983.         call    puttoconsole_a          ; Put to console
  8984.         sub     'N'
  8985.         ret
  8986. ;
  8987. ; Get response Y or N - Z set is NO
  8988. ;
  8989. l2d21:
  8990.         call    l2d01           ; Ask for YES or NO
  8991.         push    af
  8992.         call    l01e1           ; Give new line
  8993.         pop     af
  8994.         ret
  8995. ;
  8996. ; Build file <name>.PAS
  8997. ;
  8998. l2d2a:
  8999.         ld      a,'P'           ; Set .PAS
  9000.         ld      hl,'A'+'S'*256
  9001. l2d2f:
  9002.         ld      (l005c+Fdrv+Fname),a
  9003.         ld      (l005c+Fdrv+Fname+1),hl
  9004.         ld      c,0             ; Set no wild card
  9005.         call    l0406           ; Parse file
  9006.         ld      a,(l005c)       ; Test drive given
  9007.         or      a
  9008.         ret     nz              ; Yeap
  9009.         push    de
  9010.         ld      c,_retdsk
  9011.         call    l7265           ; Return current disk (return L=A=current drive)
  9012.         inc     a
  9013.         ld      (l005c),a       ; Set disk
  9014.         pop     de
  9015.         ret
  9016. ;
  9017. ; Test work file defined - Z set says no
  9018. ;
  9019. l2d4b:
  9020.         ld      a,(l451d+Fdrv)  ; Fetch name
  9021.         or      a
  9022.         ret
  9023. ;
  9024. ; Get file
  9025. ;
  9026. l2d50:
  9027.         call    l2d4b           ; Test work file defined
  9028.         jr      nz,l2d6f        ; Yeap
  9029.         call    l2d7a           ; Test main file defined
  9030.         jr      nz,l2d5f        ; Yeap
  9031.         call    l24c9           ; Get work file
  9032.         jr      l2d6f
  9033. l2d5f:
  9034.         ld      de,l451d
  9035.         ld      hl,l44f9        ; Point to main file
  9036.         ld      bc,l0024
  9037.         ldir
  9038.         ld      a,1
  9039.         ld      (l44f1),a       ; Set file flag
  9040. l2d6f:
  9041.         ld      a,(l44f1)       ; Test file flag
  9042.         or      a
  9043.         ret     z               ; No file
  9044.         call    l2602           ; Save work file
  9045.         jp      l2506
  9046. ;
  9047. ; Test main file defined - Z set says no
  9048. ;
  9049. l2d7a:
  9050.         ld      a,(l44f9+Fdrv)  ; Fetch name
  9051.         or      a
  9052.         ret
  9053. ;
  9054. ; Compare main and work file - Z says same
  9055. ;
  9056. l2d7f:
  9057.         ld      de,l451d        ; Point to work file
  9058.         ld      hl,l44f9        ; Point to main file
  9059.         ld      b,Fdrv+Fname+Fext
  9060. l2d87:
  9061.         ld      a,(de)
  9062.         sub     (hl)            ; Compare
  9063.         ret     nz              ; Not same
  9064.         inc     de
  9065.         inc     hl
  9066.         djnz    l2d87
  9067.         ret
  9068. ;
  9069. ; Init session
  9070. ;
  9071. l2d8f:
  9072.         ld      hl,(l4544)      ; Get start of text
  9073.         ld      (hl),' '        ; Clear it
  9074.         inc     hl
  9075.         ld      (l4546),hl      ; Save pointer
  9076.         xor     a
  9077.         ld      (l447f),a       ; Clear text change flag
  9078.         ld      (l44f1),a       ; Clear file flag
  9079. l2d9f:
  9080.         xor     a
  9081.         ld      (l4542),a       ; Force compile
  9082.         ret
  9083. ;
  9084. ; Read error message file
  9085. ;
  9086. l2da4:
  9087.         ld      hl,(l429e)      ; Get base of message file
  9088.         ld      (l4544),hl      ; Set as start of text
  9089.         ld      de,l217d        ; Point to filename
  9090.         ld      a,'M'
  9091.         ld      hl,'S'+'G'*256
  9092.         call    l2e20           ; Prepare .MSG file
  9093.         ld      (l4541),a       ; Set error message file read
  9094.         call    z,l2e76         ; Get ESCape
  9095.         jr      z,l2dcf
  9096.         ld      hl,l25a0
  9097.         ld      (l259d+1),hl    ; Set vector for file not found
  9098.         ld      hl,l25d4
  9099.         ld      (l257c+1),hl    ; Set vector for file too big
  9100.         ld      de,l005c
  9101.         call    l2518           ; Load text file
  9102. l2dcf:
  9103.         ld      hl,(l4546)      ; Get end of text
  9104.         ld      (hl),eof
  9105.         inc     hl
  9106.         ld      (l4544),hl      ; Set start of text
  9107.         ret
  9108. ;
  9109. ; Convert string ^DE to hex number in reg HL
  9110. ;
  9111. l2dd9:
  9112.         ld      hl,0            ; Init result
  9113. l2ddc:
  9114.         ld      a,(de)          ; Get character
  9115.         call    l04a6           ; Convert to upper case
  9116.         sub     '0'             ; Strip off offset
  9117.         ret     c               ; Out of range
  9118.         cp      9+1             ; Test decimal
  9119.         jr      c,l2def         ; Yeap
  9120.         sub     'A'-'0'-10      ; Fix for hex
  9121.         cp      10              ; Verify correct range
  9122.         ret     c
  9123.         cp      15+1
  9124.         ret     nc
  9125. l2def:
  9126.         add     hl,hl           ; Old * 16
  9127.         add     hl,hl
  9128.         add     hl,hl
  9129.         add     hl,hl
  9130.         or      l
  9131.         ld      l,a             ; Insert digit
  9132.         inc     de
  9133.         jr      l2ddc
  9134. ;
  9135. ; Tell name of file ^DE
  9136. ;
  9137. l2df8:
  9138.         inc     de
  9139.         ld      a,(de)          ; Get name
  9140.         dec     de
  9141.         or      a               ; Test defined
  9142.         ret     z               ; Nope
  9143.         ld      a,(de)          ; Get drive
  9144.         add     a,'A'-1
  9145.         cp      'A'-1           ; Test default drive
  9146.         call    nz,puttoconsole_a       ; Put to console if not
  9147.         ld      a,':'
  9148.         call    nz,puttoconsole_a       ; Give delimiter
  9149.         ld      b,Fname+Fext    ; Set length
  9150. l2e0c:
  9151.         inc     de
  9152.         ld      a,(de)          ; Get character
  9153.         and     NOMSB           ; Strip off attribute
  9154.         cp      ' '             ; Test blank
  9155.         call    nz,puttoconsole_a       ; Put to console if not
  9156.         ld      a,b
  9157.         cp      Fext+1          ; Test extension follows
  9158.         ld      a,'.'
  9159.         call    z,puttoconsole_a                ; Put delimiter to console if so
  9160.         djnz    l2e0c
  9161.         ret
  9162. ;
  9163. ; Prepare file ^DE with extensin in A,L,H
  9164. ; Z set if file not found
  9165. ;
  9166. l2e20:
  9167.         call    l2d2f           ; Parse file and build extension
  9168.         ld      hl,l005c
  9169.         call    l2e51           ; Open file
  9170.         ret     nz              ; Got it
  9171.         ld      a,(l44f8)       ; Get logged disk
  9172.         cp      (hl)            ; Test same drive
  9173.         ld      (hl),a          ; Set logged one
  9174.         call    nz,l2e51        ; Open file if different drives
  9175.         ret     nz
  9176.         ld      a,'A'-'@'
  9177.         cp      (hl)            ; Test base drive
  9178.         ld      (hl),a          ; Force it
  9179.         call    nz,l2e51        ; Open file if not base
  9180.         ret     nz              ; Got it
  9181.         ld      (hl),0          ; Set default drive
  9182.         ex      de,hl           ; And tell error
  9183. ;
  9184. ; Tell file ^DE not found
  9185. ;
  9186. l2e3e:
  9187.         call    l2df8           ; Tell name of file
  9188.         call    l0200           ; Tell not found
  9189. ;
  9190.         db      ' not found'
  9191.         db      null
  9192.         xor     a
  9193.         ret
  9194. ;
  9195. ; Open standard file - Z set says not found
  9196. ;
  9197. l2e51:
  9198.         push    de
  9199.         push    hl
  9200.         ld      c,_open
  9201.         call    BDOS_with_FCB1          ; Open file
  9202.         pop     hl
  9203.         pop     de
  9204.         inc     a               ; Fix result
  9205.         ret
  9206. ;
  9207. ; Print integer in reg HL fixed sized
  9208. ;
  9209. l2e5c:
  9210.         ld      de,-5           ; Set size
  9211.         jr      l2e64
  9212. ;
  9213. ; Print integer number in reg HL
  9214. ;
  9215. l2e61:
  9216.         ld      de,-1           ; Set no size
  9217. l2e64:
  9218.         push    ix
  9219.         push    iy
  9220.         push    hl
  9221.         push    de
  9222.         call    l149b           ; Set standard device
  9223.         pop     hl
  9224.         call    l1726           ; Write integer
  9225.         pop     iy
  9226.         pop     ix
  9227.         ret
  9228. ;
  9229. ; Get ESCape character
  9230. ;
  9231. l2e76:
  9232.         push    af
  9233.         call    l0200           ; Tell it
  9234. ;
  9235.         db      '. Press <ESC>'
  9236.         db      null
  9237. l2e88:
  9238.         call    readfromkbd             ; Read character
  9239.         jp      l0128           ; &PATCH&: Test special keys
  9240.         nop
  9241. l2e8f:
  9242.         pop     af
  9243.         ret
  9244. ;
  9245. ; %%%%%%%%%%%%%%%%%%%%
  9246. ; %%% EDITOR PART %%%%
  9247. ; %%%%%%%%%%%%%%%%%%%%
  9248. ;
  9249. l2e91:
  9250.         push    hl
  9251.         ld      de,256*lf+cr
  9252.         ld      hl,(l4546)      ; Get end of text
  9253.         ld      (hl),d          ; Close line
  9254.         dec     hl
  9255.         ld      (hl),e
  9256.         ld      (l7b74+_LinLen),de
  9257.         xor     a
  9258.         ld      (l4474),a       ; Clear change flag
  9259.         inc     a
  9260.         ld      (l4475),a       ; Init row
  9261.         ld      hl,l43de
  9262.         ld      (l7b72),hl      ; Init pointer to all delimiters
  9263.         ld      iy,l446c
  9264.         call    l023e           ; Clear screen
  9265.         pop     de              ; Get offset
  9266.         inc     de              ; Fix it
  9267.         ld      hl,(l4544)      ; Get start of text
  9268.         add     hl,de           ; Add to offset
  9269.         call    l33a9
  9270. l2ebd:
  9271.         ld      a,(l4482)       ; Get control character count
  9272.         dec     a
  9273.         jr      z,l2ed5         ; Got one
  9274.         ld      hl,256*0+0
  9275.         call    l02a2           ; Set cursor to control position
  9276.         ld      a,(l4482)       ; Get control character count
  9277.         add     a,a             ; Double it
  9278.         ld      b,a             ; For count
  9279.         ld      a,' '
  9280. l2ed0:
  9281.         call    puttoconsole_a          ; Blank control characters
  9282.         djnz    l2ed0
  9283. l2ed5:
  9284.         call    l3b96
  9285.         call    l2ff7           ; Give status
  9286.         call    l2f3a           ; Get character
  9287.         jr      nc,l2f0e        ; No control
  9288.         jr      z,l2ebd
  9289.         ld      hl,l2ebd
  9290.         ld      a,d
  9291.         cp      (HIGH MMSB)-1   ; Test special address
  9292.         jr      c,l2ef4         ; Nope
  9293.         ld      (l447f),a       ; Set text changed
  9294.         and     NOMSB
  9295.         ld      d,a
  9296.         xor     a
  9297.         ld      (l4542),a       ; Force compile
  9298. l2ef4:
  9299.         push    hl              ; Set return address
  9300.         push    de              ; Save control address
  9301.         ld      hl,l4456+1
  9302.         ld      de,l445a+1
  9303.         ld      bc,l0008
  9304.         lddr                    ; Save a bit
  9305.         ret
  9306. ;
  9307. ; Control: CONTROL PREFIX
  9308. ;
  9309. l2f02::
  9310.         call    l2f8a           ; Get character
  9311.         ld      (iy+22),3
  9312.         call    l4271           ; Get character
  9313.         jr      l2f16
  9314. l2f0e:
  9315.         ld      (l447f),a       ; Re/Set text changed
  9316.         ld      hl,l4542
  9317.         ld      (hl),0          ; Force compile
  9318. l2f16:
  9319.         ld      hl,(l4452)      ; Get current edit pointer
  9320.         ld      de,l7b74+_LinLen-2
  9321.         call    cmp_hl_de               ; Compare HL:DE
  9322.         jr      nc,l2ebd        ; Line too long
  9323.         bit     0,(iy+6)        ; Test insert
  9324.         push    af
  9325.         call    z,l41eb         ; Yeap, so make room
  9326.         pop     af
  9327.         ld      (hl),a          ; Store character
  9328.         inc     hl              ; Bump buffer
  9329.         push    hl
  9330.         call    l4197
  9331.         pop     hl
  9332.         ld      (l4452),hl      ; Set current edit pointer
  9333.         call    l3fe7 ;set column?
  9334.         jp      l2ebd
  9335. ;
  9336. ; Get character
  9337. ; C set indicates control
  9338. ;
  9339. l2f3a:
  9340.         call    l4271           ; Get character
  9341.         cp      '~'+1           ; Test printable range
  9342.         jr      nc,l2f44        ; Nope
  9343.         cp      ' '             ; Test once again
  9344.         ret     nc
  9345. l2f44:
  9346.         ld      hl,l4482        ; Point to control character count
  9347.         ld      (hl),1          ; Init count
  9348.         inc     hl
  9349.         ld      (hl),a          ; Save control
  9350. l2f4b:
  9351.         ;push   hl
  9352.         ;ld     hl,l4482        ; Point to control character count
  9353.         ;ld     de,l42a1
  9354.         ;ld     b,11111111b
  9355.         ;call   l2fc1           ; Find control
  9356.         ;pop    hl
  9357.         ;or     a               ; Test found
  9358.         ;jr     nz,l2f6b        ; Yeap
  9359.         push    hl
  9360.         ld      hl,l4482        ; Point to control character count
  9361.         ld      de,l4369
  9362.         ;ld     b,00011111b
  9363.         ld      b,11111111b
  9364.         call    l2fc1           ; Find control
  9365.         pop     hl
  9366.         or      a               ; Test found
  9367.         scf
  9368.         ret     z               ; Nope
  9369. l2f6b:
  9370.         dec     a               ; Test all found
  9371.         jr      z,l2f78         ; Nope
  9372.         ld      hl,l43f4
  9373.         add     hl,bc           ; Go into table
  9374.         add     hl,bc
  9375.         ld      e,(hl)          ; Fetch address
  9376.         inc     hl
  9377.         ld      d,(hl)
  9378.         scf                     ; Set result
  9379.         ret
  9380. l2f78:
  9381.         call    l2f8a           ; Get character
  9382.         push    af
  9383.         call    l4271           ; Get character
  9384.         inc     (iy+22)
  9385.         inc     hl
  9386.         ld      (hl),a
  9387.         pop     af
  9388.         call    z,l2f8a         ; Get character
  9389.         jr      l2f4b
  9390. ;
  9391. ; Get character
  9392. ;
  9393. l2f8a:
  9394.         call    l4232           ; Poll character from input
  9395.         call    l428f           ; Test look ahead buffer empty
  9396.         ret     nz              ; Nope
  9397.         push    hl
  9398.         ld      hl,256*0+0
  9399.         call    l02a2           ; Position cursor
  9400.         ld      hl,l4482        ; Point to control character count
  9401.         ld      a,(hl)          ; Get length
  9402. l2f9c:
  9403.         push    af
  9404.         inc     hl
  9405.         ld      a,(hl)          ; Get character
  9406.         call    l2fa8           ; Dispaly as control
  9407.         pop     af
  9408.         dec     a
  9409.         jr      nz,l2f9c
  9410.         pop     hl
  9411.         ret
  9412. ;
  9413. ; Display character in Accu
  9414. ;
  9415. l2fa8:
  9416.         push    af
  9417.         call    l3cec           ; Make normal video
  9418.         pop     af
  9419.         cp      ' '             ; Test control
  9420.         jp      nc,puttoconsole_a       ; Put to console if not
  9421.         push    af
  9422.         push    af
  9423.         ld      a,'^'
  9424.         call    puttoconsole_a          ; Indicate control
  9425.         pop     af
  9426.         add     a,'@'
  9427.         call    puttoconsole_a          ; Put to console as ASCII
  9428.         pop     af
  9429.         ret
  9430. ;
  9431. ; ^HL points to key sequence searched for in list ^DE with mask in reg B
  9432. ; Accu= 0 says not found
  9433. ; Accu= 1 says part found
  9434. ; Accu=-1 says found
  9435. ;
  9436. l2fc1:
  9437.         ld      c,-1            ; Init index
  9438.         push    bc
  9439.         push    hl
  9440. l2fc5:
  9441.         pop     hl
  9442.         pop     bc
  9443.         ld      a,(de)          ; Get length from list
  9444.         inc     de
  9445.         or      a               ; Test end
  9446.         ret     z               ; Yeap
  9447.         inc     c               ; Advance index
  9448.         push    bc
  9449.         push    hl
  9450.         ld      c,(hl)          ; Get length from input
  9451.         sub     c               ; Get difference
  9452.         inc     hl
  9453.         jr      nc,l2fd7        ; In range
  9454.         add     a,c             ; Else fix it
  9455.         ld      c,a
  9456.         jr      l2ff0           ; Go adjust
  9457. l2fd7:
  9458.         push    af
  9459. l2fd8:
  9460.         ld      a,(de)          ; Get from list
  9461.         sub     (hl)            ; Compare
  9462.         and     b               ; Set mask
  9463.         jr      nz,l2fed        ; No match
  9464.         inc     de
  9465.         inc     hl
  9466.         dec     c
  9467.         jr      nz,l2fd8
  9468.         pop     af
  9469.         pop     hl
  9470.         pop     bc
  9471.         ld      b,0
  9472.         ld      a,-1
  9473.         ret     z               ; Got exact length
  9474.         ld      a,1             ; Fix for partial success
  9475.         ret
  9476. l2fed:
  9477.         pop     af
  9478.         add     a,c
  9479.         ld      c,a
  9480. l2ff0:
  9481.         ld      b,0
  9482.         ex      de,hl
  9483.         add     hl,bc
  9484.         ex      de,hl
  9485.         jr      l2fc5
  9486. ;
  9487. ; Give editor status
  9488. ;
  9489. l2ff7:
  9490.         call    l4232           ; Poll character from input
  9491.         call    l428f           ; Test look ahead buffer empty
  9492.         ret     nz              ; Nope
  9493.         ld      hl,l4474
  9494.         ld      a,(hl)          ; Test status changed
  9495.         or      a
  9496.         jr      nz,l3078        ; No change
  9497.         ld      (hl),-1         ; Reset it
  9498.         ld      hl,256*0+0
  9499.         ld      (l4476),hl
  9500.         xor     a
  9501.         ld      (l4478),a
  9502.         call    l02a2           ; Position cursor
  9503.         call    l3c12           ; Clear line
  9504.         call    l3cdf           ; Set low video
  9505.         ld      a,(l0168)       ; Get screen columns
  9506.         cp      MINWID          ; Test room for filename
  9507.         jr      c,l302a         ; Nope
  9508.         ld      hl,256*42+0
  9509.         call    l02a2           ; Position cursor
  9510.         call    l3135           ; Type work file
  9511. l302a:
  9512.         ld      hl,256*6+0
  9513.         call    l420e           ; Position cursor and tell line
  9514.         db      'Line '
  9515.         db      null
  9516.         ld      hl,256*16+0
  9517.         call    l420e           ; Position cursor and tell column
  9518.         db      'Col '
  9519.         db      null
  9520.         ld      hl,256*24+0
  9521.         ld      a,(l4472)       ; Get insert mode
  9522.         or      a
  9523.         jr      nz,l305a        ; Overwrite
  9524.         call    l420e           ; Position cursor and tell insert
  9525.         db      'Insert    '
  9526.         db      null
  9527.         jr      l3068
  9528. l305a:
  9529.         call    l420e           ; Position cursor and tell overwrite
  9530.         db      'Overwrite '
  9531.         db      null
  9532. l3068:
  9533.         ld      a,(l4479)       ; Get tabulate state
  9534.         or      a
  9535.         jr      nz,l3078
  9536.         call    l4211
  9537.         db      'Indent'
  9538.         db      null
  9539. l3078:
  9540.         ld      a,(l446c) ;xscroll???
  9541.         add     a,(iy+4)        ; Add column
  9542.         inc     a
  9543.         ld      hl,(l4478)
  9544.         cp      l
  9545.         jr      z,l309b
  9546.         ld      (l4478),a
  9547.         push    af
  9548.         ld      hl,256*20+0
  9549.         call    l02a2           ; Position cursor
  9550.         call    l3cdf           ; Set low video
  9551.         pop     af
  9552.         ld      l,a
  9553.         ld      h,0
  9554.         ld      a,3             ; Set number of digits
  9555.         call    l30ec           ; Give count
  9556. l309b:
  9557.         ld      de,(l4476)
  9558.         ld      hl,(l4450)      ; Get current memory pointer
  9559.         call    cmp_hl_de               ; Compare HL:DE
  9560.         jp      z,l37a4         ; Same, set edit cursor
  9561.         call    l37a4           ; Set edit cursor
  9562.         ld      de,(l4544)      ; Get start of text
  9563.         ld      hl,(l4450)      ; Get current memory pointer
  9564.         or      a
  9565.         sbc     hl,de           ; Get relative position
  9566.         ld      c,l
  9567.         ld      b,h
  9568.         ex      de,hl
  9569.         ld      de,1
  9570.         ld      a,c
  9571.         or      b               ; Test any
  9572.         jr      z,l30d3         ; Nope
  9573. l30bf:
  9574.         ld      a,lf
  9575.         inc     de
  9576.         cpir                    ; Find new line
  9577.         jp      po,l30d3        ; Got it
  9578.         dec     e
  9579.         inc     e
  9580.         call    z,l4232         ; Poll character from input
  9581.         call    l428f           ; Test look ahead buffer empty
  9582.         jr      nz,l30e9        ; Nope
  9583.         jr      l30bf
  9584. l30d3:
  9585.         ld      hl,256*11+0
  9586.         push    de
  9587.         call    l02a2           ; Position cursor
  9588.         call    l3cdf           ; Set low video
  9589.         pop     hl
  9590.         ld      a,5             ; Set number of digits
  9591.         call    l30ec           ; Give count
  9592.         ld      hl,(l4450)      ; Get current memory pointer
  9593.         ld      (l4476),hl
  9594. l30e9:
  9595.         jp      l37a4           ; Set edit cursor
  9596. ;
  9597. ; Print fixed format integer
  9598. ; ENTRY Reg HL holds number to be printed
  9599. ;       Accu holds decimal places
  9600. ;
  9601. l30ec:
  9602.         push    af
  9603.         ld      b,0             ; Clear count
  9604.         call    l30fe           ; Print number
  9605.         pop     af
  9606.         add     a,b             ; Test all digits typed
  9607.         ret     z               ; Yeap
  9608.         ld      b,a
  9609.         ld      a,' '
  9610. l30f8:
  9611.         call    puttoconsole_a          ; Fill remainder with blanks
  9612.         djnz    l30f8
  9613.         ret
  9614. ;
  9615. ; Print decimal number
  9616. ; ENTRY Reg HL holds number
  9617. ;       Reg B  holds places
  9618. ;
  9619. l30fe:
  9620.         ld      a,h
  9621.         or      l               ; Test zero output
  9622.         ld      a,'0'
  9623.         jr      z,l3131         ; Yeap, print it
  9624.         ld      de,10000
  9625.         call    l311f           ; Get ten thousands
  9626.         ld      de,1000
  9627.         call    l311f           ; Get thousands
  9628.         ld      de,100
  9629.         call    l311f           ; Get hundreds
  9630.         ld      de,10
  9631.         call    l311f           ; Get tens
  9632.         ld      de,1            ; Finally units
  9633. ;
  9634. ; Print modulo
  9635. ; ENTRY Reg HL holds number
  9636. ;       Reg DE holds divisor
  9637. ;       Reg B  holds places
  9638. ; EXIT  Reg HL fixed
  9639. ;       Reg B  decremented if digit is printed
  9640. ;
  9641. l311f:
  9642.         xor     a               ; Clear digit
  9643. l3120:
  9644.         sbc     hl,de           ; Divide
  9645.         jr      c,l3127
  9646.         inc     a               ; Bump digit
  9647.         jr      l3120
  9648. l3127:
  9649.         add     hl,de           ; Make remainder positive
  9650.         add     a,'0'           ; Make ASCII
  9651.         cp      '0'             ; Test zero
  9652.         jr      nz,l3131
  9653.         inc     b               ; Test leading zero
  9654.         dec     b
  9655.         ret     z               ; Suppress it
  9656. l3131:
  9657.         dec     b               ; Fix count
  9658.         jp      puttoconsole_a          ; Put to console
  9659. ;
  9660. ; Type work file
  9661. ;
  9662. l3135:
  9663.         ld      de,l451d
  9664.         jp      l2df8           ; Tell name of file
  9665. ;
  9666. ; Get string for search and file function
  9667. ; ENTRY Reg DE points to line buffer
  9668. ;       Byte 0 holds max characters
  9669. ;       Byte 1 holds resulting length
  9670. ;
  9671. l313b:
  9672.         call    l0200           ; Indicate input
  9673. ;
  9674.         db      ': '
  9675.         db      null
  9676.         ex      de,hl
  9677.         push    hl
  9678.         pop     ix              ; Copy buffer
  9679.         inc     hl
  9680.         ld      d,(hl)
  9681.         ld      (hl),0
  9682.         inc     hl
  9683. l314a:
  9684.         res     _LB,(iy+_Video) ; Disable video
  9685.         push    de
  9686.         push    hl
  9687.         call    l2f3a           ; Get character
  9688.         pop     hl
  9689.         pop     de
  9690.         set     _LB,(iy+_Video) ; Allow video
  9691.         jr      nc,l31b9        ; No control
  9692.         jr      nz,l3165
  9693.         ld      a,(l4483)       ; Get character
  9694.         call    l3ef6           ; Test function cancelled
  9695.         jr      l314a
  9696. l3165:
  9697.         ld      a,c
  9698.         cp      0
  9699.         jr      nz,l316d
  9700.         ld      (hl),1ah
  9701.         ret
  9702. l316d:
  9703.         cp      3
  9704.         jr      nz,l317c
  9705.         ld      a,(ix+1)
  9706.         cp      d
  9707.         jr      nc,l314a
  9708.         inc     (ix+1)
  9709.         jr      l31c6
  9710. l317c:
  9711.         cp      5
  9712.         jr      nz,l3190
  9713. l3180:
  9714.         ld      a,(ix+1)
  9715.         cp      d
  9716.         jr      z,l314a
  9717.         ld      a,(hl)          ; Get character
  9718.         call    l2fa8           ; Display as control
  9719.         inc     hl
  9720.         inc     (ix+1)
  9721.         jr      l3180
  9722. l3190:
  9723.         cp      4
  9724.         jr      nz,l319b
  9725. l3194:
  9726.         call    l31d7
  9727.         jr      nz,l3194
  9728.         jr      l314a
  9729. l319b:
  9730.         cp      '-'
  9731.         jr      nz,l31a4
  9732.         call    l4271           ; Get character
  9733.         jr      l31b9
  9734. l31a4:
  9735.         cp      1bh
  9736.         jr      z,l31b4
  9737.         cp      1ch
  9738.         jr      z,l31b4
  9739.         cp      1
  9740.         jr      z,l31b4
  9741.         cp      2
  9742.         jr      nz,l314a
  9743. l31b4:
  9744.         call    l31d7
  9745. l31b7:
  9746.         jr      l314a
  9747. l31b9:
  9748.         ld      e,a
  9749.         ld      a,(ix+1)
  9750.         cp      (ix+0)
  9751.         jr      nc,l314a
  9752.         inc     (ix+1)
  9753.         ld      (hl),e
  9754. l31c6:
  9755.         ld      a,(hl)          ; Get character
  9756.         inc     hl
  9757.         call    l2fa8           ; Display as control
  9758.         ld      a,(ix+1)
  9759.         cp      d
  9760.         jr      c,l31b7
  9761.         ld      d,(ix+1)
  9762.         jp      l31b7
  9763. l31d7:
  9764.         ld      a,(ix+1)
  9765.         or      a
  9766.         ret     z
  9767.         dec     (ix+1)
  9768.         dec     hl
  9769.         ld      a,(hl)
  9770.         cp      ' '
  9771.         call    c,l31e6
  9772. l31e6:
  9773.         call    l4211
  9774.         db      bs+MSB,' '+MSB,bs+MSB
  9775.         db      null
  9776.         ld      a,0ffh
  9777.         or      a
  9778.         ret
  9779. ;
  9780. ; Control: FIND STRING
  9781. ;
  9782. l31f1:
  9783.         xor     a
  9784.         ld      (l447e),a       ; Set find flag
  9785.         call    l31fd           ; Get string searched for
  9786.         call    l3220           ; Get options
  9787.         jr      l3252           ; Enter process
  9788. ;
  9789. ; Get string searched for
  9790. ;
  9791. l31fd:
  9792.         call    l3e04           ; Tell what we want
  9793.         db      'Find'
  9794.         db      null
  9795.         ld      de,l4490        ; Point to buffer
  9796. l3208:
  9797.         jp      l313b           ; Get search string
  9798. ;
  9799. ; Get string to be replaced
  9800. ;
  9801. l320b:
  9802.         call    l3e07           ; Tell what we want
  9803.         db      'Replace with'
  9804.         db      null
  9805.         ld      de,l44b1        ; Point to buffer
  9806.         jr      l3208           ; Get replace string
  9807. ;
  9808. ; Get options
  9809. ;
  9810. l3220:
  9811.         call    l3e07           ; Tell what we want
  9812.         db      'Options'
  9813.         db      null
  9814.         ld      de,l44d2        ; Get buffer
  9815.         call    l313b           ; Get search string
  9816.         ld      a,(l0168)       ; Get screen columns
  9817.         ld      h,a
  9818.         dec     h               ; Fix column
  9819.         ld      l,0             ; Set row
  9820.         jp      l02a2           ; Position cursor
  9821. ;
  9822. ; Control: FIND AND REPLACE STRING
  9823. ;
  9824. l323b:
  9825.         ld      a,-1
  9826.         ld      (l447e),a       ; Set replace flag
  9827.         call    l31fd           ; Get string searched for
  9828.         call    l320b           ; Get replace string
  9829.         call    l3220           ; Get options
  9830.         jr      l3252           ; Enter process
  9831. ;
  9832. ; Control: REPEAT LAST SEARCH
  9833. ;
  9834. l324b:
  9835.         call    l2f8a           ; Get character
  9836.         ld      (iy+22),3       ; Init count
  9837. l3252:
  9838.         call    l3e40           ; Sample character
  9839.         call    l3e23           ; Find last non blank
  9840.         inc     hl
  9841.         ld      de,(l4452)      ; Get current edit pointer
  9842.         call    l4191           ; Find min
  9843.         ld      de,l7b74
  9844.         or      a
  9845.         sbc     hl,de           ; Subtract base
  9846.         ld      de,(l4450)      ; Get current memory pointer
  9847.         add     hl,de           ; Add for real address
  9848.         ld      (l4488),hl      ; Set end
  9849.         ld      de,0            ; Clear counter
  9850.         ld      hl,l44d2+1      ; Init buffer
  9851.         ld      b,(hl)          ; Fetch length
  9852.         ld      (iy+17),0       ; Clear flag
  9853.         inc     b               ; Test any in buffer
  9854.         dec     b
  9855.         jr      z,l32c0         ; Nope
  9856. l327d:
  9857.         inc     hl
  9858.         ld      a,(hl)          ; Get character
  9859.         cp      '0'             ; Test possible count
  9860.         jr      c,l3293         ; Nope
  9861.         cp      '9'+1
  9862.         jr      nc,l3293
  9863.         call    l3426
  9864.         sub     '0'
  9865.         add     a,e             ; Add digit to count
  9866.         ld      e,a
  9867.         jr      nc,l32be
  9868.         inc     d               ; Remember carry
  9869.         jr      l32be
  9870. l3293:
  9871.         call    l04a6           ; Convert to upper case
  9872.         cp      'W'             ; Test whole word search
  9873.         jr      nz,l329e
  9874.         set     _W,(iy+17)
  9875. l329e:
  9876.         cp      'U'             ; Test ignore case
  9877.         jr      nz,l32a6
  9878.         set     _U,(iy+17)
  9879. l32a6:
  9880.         cp      'N'             ; Test no request
  9881.         jr      nz,l32ae
  9882.         set     _N,(iy+17)
  9883. l32ae:
  9884.         cp      'G'             ; Test global
  9885.         jr      nz,l32b6
  9886.         set     _G,(iy+17)
  9887. l32b6:
  9888.         cp      'B'             ; Test backwards
  9889.         jr      nz,l32be
  9890.         set     _B,(iy+17)
  9891. l32be:
  9892.         djnz    l327d
  9893. l32c0:
  9894.         ld      a,e             ; Test loop count
  9895.         or      d
  9896.         jr      nz,l32c7        ; Yeap
  9897.         ld      de,1            ; Set default
  9898. l32c7:
  9899.         ld      (l448a),de      ; Save loop count
  9900.         ld      hl,(l4544)      ; Get start of text
  9901.         ld      a,(l447d)       ; Get option flags
  9902.         bit     _B,a            ; Test backwards
  9903.         jr      z,l32d8         ; Nope
  9904.         ld      hl,(l4546)      ; Get end of text
  9905. l32d8:
  9906.         bit     _G,a            ; Test global search
  9907.         jr      nz,l32df        ; Yeap
  9908.         ld      hl,(l4488)      ; Get end of search pointer
  9909. l32df:
  9910.         ld      (l4488),hl      ; Set end of search pointer
  9911.         bit     _B,(iy+17)      ; Test backwards
  9912.         jr      nz,l32f5        ; Yeap
  9913.         ld      de,(l4546)      ; Get end of text
  9914.         dec     de
  9915.         call    cmp_hl_de               ; Compare HL:DE
  9916.         jp      nc,l3380
  9917.         jr      l32fb
  9918. l32f5:
  9919.         call    l3bee           ; Fix to start of line
  9920.         jp      c,l3380
  9921. l32fb:
  9922.         ld      de,l4492
  9923.         ld      a,(l4491)
  9924.         ld      b,a
  9925.         bit     _B,(iy+17)      ; Test backwards
  9926.         jr      z,l330e         ; Nope
  9927.         dec     a
  9928.         add     a,e
  9929.         ld      e,a
  9930.         jr      nc,l330e
  9931.         inc     d
  9932. l330e:
  9933.         bit     _W,(iy+17)      ; Test whole word search
  9934.         jr      z,l3323         ; Nope
  9935.         push    de
  9936.         push    hl
  9937.         call    l33fb
  9938.         ld      a,(hl)
  9939.         pop     hl
  9940.         pop     de
  9941.         jr      c,l3323
  9942.         call    l33e4
  9943.         jr      c,l3377
  9944. l3323:
  9945.         dec     b
  9946.         inc     b
  9947.         jr      z,l332e
  9948. l3327:
  9949.         call    l340f
  9950.         jr      nz,l3377
  9951.         djnz    l3364
  9952. l332e:
  9953.         bit     _W,(iy+17)      ; Test whole word search
  9954.         jr      z,l3341         ; Nope
  9955.         push    hl
  9956.         call    l3406
  9957.         ld      a,(hl)
  9958.         pop     hl
  9959.         jr      c,l3341
  9960.         call    l33e4
  9961.         jr      c,l3377
  9962. l3341:
  9963.         bit     _B,(iy+17)      ; Test backwards
  9964.         call    z,l3bdd         ; Nope
  9965.         ld      a,(l447e)       ; Get find flag
  9966.         or      a
  9967.         call    nz,l3430        ; Replace selected
  9968.         bit     _G,(iy+17)      ; Test global search
  9969. l3353:
  9970.         jr      nz,l32df
  9971.         ld      bc,(l448a)      ; Get loop count
  9972.         dec     bc              ; Decrement
  9973.         ld      (l448a),bc
  9974.         ld      a,b
  9975.         or      c
  9976.         jr      nz,l3353
  9977.         jr      l33a9
  9978. l3364:
  9979.         push    de
  9980.         call    l3406
  9981.         pop     de
  9982.         jr      c,l3380
  9983.         bit     _B,(iy+17)      ; Test backwards
  9984.         jr      z,l3374         ; Nope
  9985.         dec     de
  9986.         jr      l3327
  9987. l3374:
  9988.         inc     de
  9989.         jr      l3327
  9990. l3377:
  9991.         ld      hl,(l4488)      ; Get end of search pointer
  9992.         call    l3406
  9993.         jp      nc,l32df
  9994. l3380:
  9995.         call    l33d6
  9996.         call    l33a9
  9997.         bit     _G,(iy+17)      ; Test global search
  9998.         ret     nz
  9999.         call    l3e04
  10000.         db      'Search string not found'
  10001.         db      null
  10002.         jp      l3f12
  10003. ;status line???
  10004. l33a9:
  10005.         call    l33af
  10006.         jp      l3d2c           ; Restore line
  10007. l33af:
  10008.         ld      de,(l4546)      ; Get end of text
  10009.         dec     de
  10010.         call    cmp_hl_de               ; Compare HL:DE
  10011.         jr      c,l33ba ;hl<de
  10012.         ex      de,hl
  10013. l33ba:
  10014.         push    hl
  10015.         push    hl
  10016.         call    l3bf5           ; Get previous EOL
  10017.         ld      (l4450),hl      ; Set current memory pointer
  10018.         or      a
  10019.         ex      de,hl
  10020.         pop     hl
  10021.         sbc     hl,de
  10022.         ld      de,l7b74
  10023.         add     hl,de
  10024.         ld      (l4452),hl      ; Set current edit pointer
  10025.         call    l3fe7 ;set column?
  10026.         call    l401f
  10027.         pop     hl
  10028.         ret
  10029. l33d6:
  10030.         ld      de,(l4544)      ; Get start of text
  10031.         call    l4191           ; Find min
  10032.         ld      hl,(l4546)      ; Get end of text
  10033.         dec     hl
  10034.         jp      l4191           ; Find min
  10035. l33e4:
  10036.         cp      '0'
  10037.         jr      c,l33f9
  10038.         cp      ':'
  10039.         ret     c
  10040.         cp      'A'
  10041.         jr      c,l33f9
  10042.         cp      5bh
  10043.         ret     c
  10044.         cp      61h
  10045.         jr      c,l33f9
  10046.         cp      7bh
  10047.         ret     c
  10048. l33f9:
  10049.         or      a
  10050.         ret
  10051. l33fb:
  10052.         bit     _B,(iy+17)      ; Test backwards
  10053.         jr      z,l340c         ; Nope
  10054. l3401:
  10055.         call    l3bdd
  10056.         ccf
  10057.         ret
  10058. l3406:
  10059.         bit     _B,(iy+17)      ; Test backwards
  10060.         jr      z,l3401         ; Nope
  10061. l340c:
  10062.         jp      l3bee           ; Fix to start of line
  10063. l340f:
  10064.         ld      a,(de)
  10065.         cp      1
  10066.         ret     z
  10067.         cp      (hl)
  10068.         ret     z
  10069.         bit     _U,(iy+17)      ; Test ignore case
  10070.         jr      z,l3424         ; Yeap
  10071.         call    l33e4
  10072.         jr      nc,l3424
  10073.         xor     (hl)
  10074.         and     0dfh
  10075.         ret
  10076. l3424:
  10077.         cp      (hl)
  10078.         ret
  10079. l3426:
  10080.         push    hl
  10081.         ld      l,e
  10082.         ld      h,d
  10083.         add     hl,hl
  10084.         add     hl,hl
  10085.         add     hl,de
  10086.         add     hl,hl
  10087.         ex      de,hl
  10088.         pop     hl
  10089.         ret
  10090. l3430:
  10091.         push    hl
  10092.         call    l428f           ; Test look ahead buffer empty
  10093.         jr      z,l343c         ; Yeap
  10094.         bit     _N,(iy+17)      ; Test no request
  10095.         jr      nz,l349d        ; Yeap
  10096. l343c:
  10097.         call    l33a9
  10098.         call    l3b96
  10099.         bit     _N,(iy+17)      ; Test no request
  10100.         jr      nz,l349d        ; Yeap
  10101.         call    l3e07
  10102.         db      'Replace (','Y'+MSB,'/','N'+MSB,'): '
  10103.         db      null
  10104. l345b:
  10105.         ld      l,(iy+5)        ; Get row
  10106.         ld      h,(iy+4)        ; Get column
  10107.         call    l02a2           ; Position cursor
  10108.         ld      bc,l07d0
  10109. l3467:
  10110.         call    l4232           ; Poll character from input
  10111.         call    l428f           ; Test look ahead buffer empty
  10112.         jr      nz,l348c        ; Nope
  10113.         dec     bc
  10114.         ld      a,c
  10115.         or      b
  10116.         jr      nz,l3467
  10117.         ld      hl,256*15+0
  10118.         call    l02a2           ; Position cursor
  10119.         ld      bc,l07d0
  10120. l347d:
  10121.         call    l4232           ; Poll character from input
  10122.         call    l428f           ; Test look ahead buffer empty
  10123.         jr      nz,l348c        ; Nope
  10124.         dec     bc
  10125.         ld      a,c
  10126.         or      b
  10127.         jr      nz,l347d
  10128.         jr      l345b
  10129. l348c:
  10130.         call    l4271           ; Get character
  10131.         call    l3ef6           ; Test function cancelled
  10132.         call    l04a6           ; Convert to upper case
  10133.         cp      'Y'
  10134.         jr      z,l349d
  10135.         cp      19h
  10136.         jr      nz,l34eb
  10137. l349d:
  10138.         set     0,(iy+19)
  10139.         xor     a
  10140.         ld      (l4542),a       ; Force compile
  10141.         ld      a,(l44b2)
  10142.         ld      c,a
  10143.         ld      b,0
  10144.         pop     hl
  10145.         push    hl
  10146.         push    bc
  10147.         ld      a,(l4491)
  10148.         sub     c
  10149.         ld      c,a
  10150.         push    af
  10151.         jr      nc,l34b7
  10152.         dec     b
  10153. l34b7:
  10154.         bit     _B,(iy+17)      ; Test backwards
  10155.         jr      nz,l34c0        ; Yeap
  10156.         ld      hl,(l4488)      ; Get end of search pointer
  10157. l34c0:
  10158.         pop     af
  10159.         push    hl
  10160.         call    nz,l3f18
  10161.         pop     de
  10162.         pop     bc
  10163.         ld      a,b
  10164.         or      c
  10165.         jr      z,l34d0
  10166.         ld      hl,l44b3
  10167.         ldir
  10168. l34d0:
  10169.         call    l428f           ; Test look ahead buffer empty
  10170.         push    af
  10171.         call    nz,l4147        ; Nope, so reset row
  10172.         pop     af
  10173.         jr      nz,l34e2        ; Eas not empty
  10174.         push    de
  10175.         call    l3d2c           ; Restore line
  10176.         call    l4139
  10177.         pop     de
  10178. l34e2:
  10179.         bit     _B,(iy+17)      ; Test backwards
  10180.         jr      nz,l34eb        ; Yeap
  10181.         pop     hl
  10182.         ex      de,hl
  10183.         ret
  10184. l34eb:
  10185.         pop     hl
  10186.         ret
  10187. ;
  10188. ; Control: WRITE BLOCK TO FILE
  10189. ;
  10190. l34ed:
  10191.         bit     0,(iy+20)       ; Test block set
  10192.         ret     nz              ; Nope
  10193.         call    l3e40           ; Sample character
  10194.         call    l3d2c           ; Restore line
  10195.         ld      hl,(l4460)      ; Get block start pointer
  10196.         ld      de,(l4462)      ; Get block end pointer
  10197.         call    cmp_hl_de               ; Compare HL:DE
  10198.         ret     nc              ; Start >= end
  10199.         call    l363c
  10200.         call    l3d2c           ; Restore line
  10201. l3509:
  10202.         call    l3e04           ; Tell what we want
  10203.         db      'Write block to file'
  10204.         db      null
  10205.         call    l3566           ; Get name of file
  10206.         ret     z
  10207.         call    l2d2a           ; Prepare .PAS file
  10208.         ld      c,_open
  10209.         call    BDOS_with_FCB1          ; Open file
  10210.         inc     a               ; Test file already exist
  10211.         jr      z,l3551         ; Nope
  10212.         call    l3e07
  10213.         db      'Overwrite old '
  10214.         db      null
  10215.         ld      de,l005c
  10216.         call    l2df8           ; Tell name of file
  10217.         call    l2d01           ; Ask for YES or NO
  10218.         jr      z,l3509         ; No
  10219.         ld      c,_delete
  10220.         call    BDOS_with_FCB1          ; Delete file
  10221. l3551:
  10222.         ld      hl,(l4462)      ; Get block end pointer
  10223.         ld      a,(hl)          ; Save character
  10224.         push    af
  10225.         push    hl
  10226.         ld      (hl),eof        ; Set end of file
  10227.         call    l3e0d           ; Set cursor
  10228.         ld      hl,(l4460)      ; Get block start pointer
  10229.         call    l2692           ; Save block to file
  10230.         pop     hl
  10231.         pop     af
  10232.         ld      (hl),a          ; Restore character
  10233.         ret
  10234. ;
  10235. ; Get name of file
  10236. ;
  10237. l3566:
  10238.         ld      de,l44df
  10239.         call    l313b           ; Get filename
  10240.         ld      de,l44df+2
  10241.         ld      a,(de)
  10242.         cp      eof             ; Test empty name
  10243.         ret
  10244. ;
  10245. ; Control: READ BLOCK FROM FILE
  10246. ;
  10247. l3573:
  10248.         call    l3e04           ; Tell what we want
  10249.         db      'Read block from file'
  10250.         db      null
  10251.         call    l3566           ; Get name of file
  10252.         ret     z
  10253.         call    l2d2a           ; Prepare .PAS file
  10254.         ld      c,_open
  10255.         call    BDOS_with_FCB1          ; Open file
  10256.         inc     a               ; Test success
  10257.         jr      nz,l35a8        ; Yeap
  10258.         call    l3e0d           ; Set cursor
  10259.         ld      de,l005c
  10260.         call    l2e3e           ; Tell not found
  10261.         call    l3f12
  10262.         jr      l3573
  10263. l35a8:
  10264.         res     0,(iy+20)       ; Mark block
  10265.         call    l363c
  10266.         ld      hl,(l4546)      ; Get end of text
  10267.         ld      de,(l4548)      ; Get top of available memory
  10268.         ld      bc,l00fe
  10269.         add     hl,bc           ; Build top
  10270.         or      a
  10271.         sbc     hl,de           ; Calculate size
  10272.         push    hl
  10273.         ld      b,h
  10274.         ld      c,l
  10275.         ld      hl,(l448c)
  10276.         scf
  10277.         call    l3f18
  10278.         pop     de
  10279.         ld      hl,l35dd        ; Set return address
  10280.         push    hl
  10281.         ld      hl,(l448c)
  10282.         push    hl
  10283.         xor     a
  10284.         sbc     hl,de
  10285.         push    hl
  10286.         ld      hl,l35f1
  10287.         ld      (l257c+1),hl    ; Redirect load error
  10288.         jp      l2560           ; Load the block
  10289. ;
  10290. ; Process end of read
  10291. ;
  10292. l35dd:
  10293.         ld      (l4462),hl      ; Set block end pointer
  10294.         ex      de,hl
  10295.         ld      hl,(l448c)
  10296.         ld      (l4460),hl      ; Set block start pointer
  10297. l35e7:
  10298.         ld      hl,(l7b6d)      ; Get last memory address
  10299.         or      a
  10300.         sbc     hl,de           ; Build difference
  10301.         ld      b,h
  10302.         ld      c,l
  10303.         jr      l3612
  10304. ;
  10305. ; Redirected load error
  10306. ;
  10307. l35f1:
  10308.         ld      de,(l448c)
  10309.         call    l35e7
  10310.         jp      l3ed9
  10311. ;
  10312. ; Control: MOVE BLOCK
  10313. ;
  10314. l35fb:
  10315.         call    l363c
  10316.         jp      nc,l3d2c        ; Restore line
  10317.         call    l3687
  10318.         ld      hl,(l448c)
  10319.         ld      de,(l4460)      ; Get block start pointer
  10320.         ld      (l4460),hl      ; Set block start pointer
  10321.         add     hl,bc
  10322.         ld      (l4462),hl      ; Set block end pointer
  10323. l3612:
  10324.         ex      de,hl
  10325.         or      a
  10326.         call    l3f18
  10327.         ld      hl,(l4460)      ; Get block start pointer
  10328.         call    l33a9
  10329.         jp      l3762
  10330. ;
  10331. ; Control: COPY BLOCK
  10332. ;
  10333. l3620:
  10334.         call    l363c
  10335.         jp      nc,l3d2c        ; Restore line
  10336.         call    l3687
  10337.         ld      hl,(l448c)
  10338.         ld      (l4460),hl      ; Set block start pointer
  10339.         add     hl,bc
  10340.         ld      (l4462),hl      ; Set block end pointer
  10341.         call    l401f
  10342.         call    l3d2c           ; Restore line
  10343.         jp      l3762
  10344. ;
  10345. ;
  10346. ;
  10347. l363c:
  10348.         bit     0,(iy+20)       ; Test block set
  10349.         jr      z,l3644         ; Yeap
  10350.         xor     a
  10351.         ret
  10352. l3644:
  10353.         call    l3e23           ; Find last non blank
  10354.         inc     hl
  10355.         ld      de,(l4452)      ; Get current edit pointer
  10356.         push    de
  10357.         call    l4191           ; Find min
  10358.         ex      de,hl
  10359.         call    l3e44           ; Sample character
  10360.         pop     hl
  10361.         ld      de,l7b74
  10362.         or      a
  10363.         sbc     hl,de           ; Subtract base
  10364.         ld      de,(l4450)      ; Get current memory pointer
  10365.         add     hl,de           ; Build real pointer
  10366.         ld      (l448c),hl
  10367.         push    hl
  10368.         ld      de,(l4460)      ; Get block start pointer
  10369.         inc     de
  10370.         call    cmp_hl_de               ; Compare HL:DE
  10371.         ld      de,(l4462)      ; Get block end pointer
  10372.         jr      c,l367a         ; HL < Start_Of_Block
  10373.         call    cmp_hl_de               ; Compare HL:DE
  10374.         jr      nc,l367a        ; HL >= End_Of_Block
  10375.         or      a
  10376.         jr      l3685
  10377. l367a:
  10378.         ld      hl,(l4460)      ; Get block start pointer
  10379.         or      a
  10380.         sbc     hl,de
  10381.         ld      (l448e),hl
  10382.         ld      c,l
  10383.         ld      b,h
  10384. l3685:
  10385.         pop     hl
  10386.         ret
  10387. ;
  10388. ;
  10389. ;
  10390. l3687:
  10391.         call    l3f18
  10392.         ld      bc,(l448e)
  10393.         ld      a,c             ; Negate value
  10394.         cpl
  10395.         ld      c,a
  10396.         ld      a,b
  10397.         cpl
  10398.         ld      b,a
  10399.         inc     bc
  10400.         ld      de,(l448c)
  10401.         ld      hl,(l4460)      ; Get block start pointer
  10402.         push    bc
  10403.         ldir
  10404.         pop     bc
  10405.         ret
  10406. ;
  10407. ; Control: DELETE BLOCK
  10408. ;
  10409. l36a1:
  10410.         bit     0,(iy+20)       ; Test block set
  10411.         ret     nz              ; Nope
  10412.         call    l3e40           ; Sample character
  10413.         ld      hl,(l4460)      ; Get block start pointer
  10414.         call    l3bf5           ; Get previous EOL
  10415.         ld      (l4450),hl      ; Set current memory pointer
  10416.         ld      hl,(l4454)      ; Get block pointer
  10417.         ld      de,(l4460)      ; Get block start pointer
  10418.         inc     de
  10419.         call    cmp_hl_de               ; Compare HL:DE
  10420.         jr      c,l36ce         ; HL < Start_Of_Block
  10421.         ld      de,(l4462)      ; Get block end pointer
  10422.         call    cmp_hl_de               ; Compare HL:DE
  10423.         jr      nc,l36ce        ; HL >= End_Of_Block
  10424.         ld      hl,(l4450)      ; Get current memory pointer
  10425.         ld      (l4454),hl      ; Set block pointer
  10426. l36ce:
  10427.         ld      hl,(l4462)      ; Get block end pointer
  10428.         ld      de,(l4460)      ; Get block start pointer
  10429.         or      a
  10430.         sbc     hl,de
  10431.         jp      c,l3d2c         ; Restore line if End < Start
  10432.         ld      c,l
  10433.         ld      b,h
  10434.         ex      de,hl
  10435.         push    hl
  10436.         push    bc
  10437.         push    af
  10438.         call    l401f
  10439.         pop     af
  10440.         pop     bc
  10441.         pop     hl
  10442.         call    l3f18
  10443.         ld      hl,(l4450)      ; Get current memory pointer
  10444.         ld      (l4460),hl      ; Set block start pointer
  10445.         ld      (l4462),hl      ; Set block end pointer
  10446.         call    l3d2c           ; Restore line
  10447.         jp      l3762
  10448. ;
  10449. ; Control: TOGGLE BLOCK DISPLAY
  10450. ;
  10451. l36f9:
  10452.         ld      hl,l4480        ; Point to block mark
  10453.         call    l3796           ; Toggle block bit
  10454.         jp      l3762
  10455. ;
  10456. ; Control: MARK END OF BLOCK
  10457. ;
  10458. l3702:
  10459.         ld      hl,(l4452)      ; Get current edit pointer
  10460.         ld      (l4466),hl      ; Set for end of block
  10461.         ld      hl,(l4450)      ; Get current memory pointer
  10462.         ld      (l4462),hl      ; Set block end pointer
  10463.         bit     1,(iy+1)        ; Test end block
  10464.         set     1,(iy+1)
  10465. l3716:
  10466.         ex      af,af'
  10467.         bit     0,(iy+20)       ; Test previous block set
  10468.         res     0,(iy+20)       ; Set now
  10469.         jr      nz,l3762        ; Was not set
  10470.         ex      af,af'
  10471.         jr      z,l3762         ; Prevous was also not set
  10472.         jr      l374e
  10473. ;
  10474. ; Control: MARK BEGIN OF BLOCK
  10475. ;
  10476. l3726:
  10477.         ld      hl,(l4452)      ; Get current edit pointer
  10478.         ld      (l4464),hl      ; Save address
  10479.         ld      hl,(l4450)      ; Get current memory pointer
  10480.         ld      (l4460),hl      ; Set block start pointer
  10481.         bit     0,(iy+1)        ; Test start block
  10482.         set     0,(iy+1)
  10483.         jr      l3716
  10484. ;
  10485. ; Control: BEGIN OF BLOCK
  10486. ;
  10487. l373c:
  10488.         call    l3e40           ; Sample character
  10489.         ld      hl,(l4460)      ; Get block start pointer
  10490.         jp      l33a9
  10491. ;
  10492. ; Control: END OF BLOCK
  10493. ;
  10494. l3745:
  10495.         call    l3e40           ; Sample character
  10496.         ld      hl,(l4462)      ; Get block end pointer
  10497.         jp      l33a9
  10498. ;
  10499. ;
  10500. ;
  10501. l374e:
  10502.         ld      h,0             ; Set left column
  10503.         call    l37a7           ; Set editor cursor
  10504.         ld      hl,l7b74        ; Load base address
  10505.         set     0,(iy+16)
  10506.         call    l3c1a
  10507.         res     0,(iy+16)
  10508.         ret
  10509. ;
  10510. ;
  10511. ;
  10512. l3762:
  10513.         call    l374e
  10514.         jp      l4147           ; Reset row
  10515. ;
  10516. ; Control: END OF TEXT
  10517. ;
  10518. l3768:
  10519.         call    l3e40           ; Sample character
  10520.         ld      hl,(l4546)      ; Get end of text
  10521.         jp      l33a9
  10522. ;
  10523. ; Control: LINE LEFT
  10524. ;
  10525. l3771:
  10526.         ld      hl,l7b74        ; Set start of line
  10527.         ld      (l4452),hl      ; Set current edit pointer
  10528.         jp      l3fe7 ;set column?
  10529. ;
  10530. ; Control: LINE RIGHT
  10531. ;
  10532. l377a:
  10533.         call    l3e23           ; Find last non blank
  10534.         inc     hl
  10535.         ld      de,l7b74+_LinLen
  10536.         call    cmp_hl_de               ; Compare HL:DE
  10537.         jr      c,l3789
  10538.         ld      hl,l7b74+_LinLen-1
  10539. l3789:
  10540.         ld      (l4452),hl      ; Set current edit pointer
  10541.         jp      l3fe7 ;set column?
  10542. ;
  10543. ; Control: TOGGLE INSERT/OVERWRITE
  10544. ;
  10545. l378f:
  10546.         ld      (iy+8),0        ; Set no change
  10547.         ld      hl,l4472        ; Point to insert mode
  10548. ;
  10549. ; Toggle status bit ^HL
  10550. ;
  10551. l3796:
  10552.         ld      a,(hl)          ; Get value
  10553.         xor     1               ; Toggle bit
  10554.         ld      (hl),a
  10555.         ret
  10556. ;
  10557. ; Control: TOGGLE TABULATE
  10558. ;
  10559. l379b:
  10560.         ld      (iy+8),0        ; Set no change
  10561.         ld      hl,l4479
  10562.         jr      l3796           ; Toggle tabulate bit
  10563. ;
  10564. ; Set current edit cursor
  10565. ;
  10566. l37a4:
  10567.         ld      h,(iy+4)        ; Get column
  10568. ;
  10569. ; Set editor cursor to current row
  10570. ; ENTRY Reg H holds column position
  10571. ;
  10572. l37a7:
  10573.         ld      l,(iy+5)        ; Get row
  10574.         jp      l02a2           ; Position cursor
  10575. ;
  10576. ; Control: LINE DOWN
  10577. ;
  10578. l37ad:
  10579.         ld      hl,(l4450)      ; Get current memory pointer
  10580.         call    findnexteol             ; Find next end of line
  10581.         ret     c               ; Out of text
  10582.         call    l3e40           ; Sample character
  10583.         ld      hl,(l4450)      ; Get current memory pointer
  10584.         call    findnexteol             ; Find next end of line
  10585. l37bd:
  10586.         ld      (l4450),hl      ; Set current memory pointer
  10587.         res     0,(iy+14)
  10588.         set     0,(iy+21)
  10589.         call    l401f
  10590.         res     0,(iy+21)
  10591.         jp      l3d2c           ; Restore line
  10592. ;
  10593. ; Control: LINE UP
  10594. ;
  10595. l37d2:
  10596.         ld      hl,(l4450)      ; Get current memory pointer
  10597.         call    findprevline            ; Find previous line
  10598.         ret     c               ; Below start of text
  10599.         push    hl
  10600.         call    l3e40           ; Sample character
  10601.         pop     hl
  10602.         jr      l37bd
  10603. ;
  10604. ; Control: SCROLL UP
  10605. ;
  10606. l37e0:
  10607.         ld      hl,(curstartofpage)     ; Get start of screen
  10608.         ld      de,(l4544)      ; Get start of text
  10609.         call    cmp_hl_de               ; Compare HL:DE
  10610.         ret     z
  10611.         call    l3e40           ; Sample character
  10612.         ld      b,0
  10613.         ld      hl,(l4450)      ; Get current memory pointer
  10614. l37f3:
  10615.         ld      de,(curstartofpage)     ; Get start of screen
  10616.         call    cmp_hl_de               ; Compare HL:DE
  10617.         jr      z,l3802         ; Match
  10618.         call    findprevline            ; Find previous line
  10619.         inc     b
  10620.         jr      l37f3
  10621. l3802:
  10622.         ld      de,(l4450)      ; Get current memory pointer
  10623.         ld      (l4450),hl      ; Set current memory pointer
  10624.         ex      de,hl
  10625.         ld      a,(l0169)       ; Get screen lines
  10626.         sub     3               ; Less status
  10627.         cp      b
  10628.         jr      nz,l3815
  10629.         call    findprevline            ; Find previous line
  10630. l3815:
  10631.         push    hl
  10632.         ld      hl,(l4450)      ; Get current memory pointer
  10633.         call    findprevline            ; Find previous line
  10634.         call    l37bd
  10635.         pop     hl
  10636. l3820:
  10637.         jr      l37bd
  10638. ;
  10639. ; Control: SCROLL DOWN
  10640. ;
  10641. l3822:
  10642.         call    l3e40           ; Sample character
  10643.         ld      hl,(l4450)      ; Get current memory pointer
  10644.         push    hl
  10645.         ld      hl,(curstartofpage)     ; Get start of screen
  10646.         ld      a,(l0169)       ; Get screen lines
  10647.         sub     2               ; Less status
  10648.         ld      b,a
  10649. l3832:
  10650.         call    findnexteol             ; Find next end of line
  10651.         djnz    l3832
  10652.         push    af
  10653.         call    l37bd
  10654.         pop     af
  10655.         pop     hl
  10656.         jr      c,l3820
  10657.         ld      de,(curstartofpage)     ; Get start of screen
  10658.         call    cmp_hl_de               ; Compare HL:DE
  10659.         jr      nc,l3820        ; HL >= Start_Of_Screen
  10660.         call    findnexteol             ; Find next end of line
  10661.         jr      l3820
  10662. ;
  10663. ; Control: BOTTOM OF SCREEN
  10664. ;
  10665. l384d:
  10666.         ld      hl,(curstartofpage)     ; Get start of screen
  10667.         ld      de,(l4450)      ; Get current memory pointer
  10668.         call    cmp_hl_de               ; Compare HL:DE
  10669.         ret     z               ; Same
  10670.         push    hl
  10671.         call    l3e40           ; Sample character
  10672.         pop     hl
  10673.         jr      l3820
  10674. ;
  10675. ; Control: TOP OF SCREEN
  10676. ;
  10677. l385f:
  10678.         call    l3e40           ; Sample character
  10679.         ld      hl,(curstartofpage)     ; Get start of screen
  10680.         ld      a,(l0169)       ; Get screen lines
  10681.         sub     3               ; Less status
  10682.         ld      b,a
  10683. l386b:
  10684.         call    findnexteol             ; Find next end of line
  10685.         djnz    l386b
  10686.         jr      l3820
  10687. ;
  10688. ; Control: PAGE DOWN
  10689. ;
  10690. l3872:
  10691.         call    l3e40           ; Sample character
  10692.         ld      a,(l0169)       ; Get screen lines
  10693.         sub     2               ; Less status
  10694.         ld      c,a
  10695.         ld      b,a
  10696.         ld      hl,(curstartofpage)     ; Get start of screen
  10697. l387f:
  10698.         call    findnexteol             ; Find next end of line
  10699.         djnz    l387f
  10700.         ld      (curstartofpage),hl     ; Set start of screen
  10701.         ld      b,c
  10702.         ld      hl,(l4450)      ; Get current memory pointer
  10703. l388b:
  10704.         call    findnexteol             ; Find next end of line
  10705.         djnz    l388b
  10706. l3890:
  10707.         ld      (l4450),hl      ; Set current memory pointer
  10708.         call    l401f
  10709.         call    l4147           ; Reset row
  10710.         jp      l3d2c           ; Restore line
  10711. ;
  10712. ; Control: PAGE UP
  10713. ;
  10714. l389c:
  10715.         call    l3e40           ; Sample character
  10716.         ld      a,(l0169)       ; Get screen lines
  10717.         sub     2               ; Less status
  10718.         ld      b,a
  10719.         ld      c,a
  10720.         ld      hl,(curstartofpage)     ; Get start of screen
  10721. l38a9:
  10722.         call    findprevline            ; Find previous line
  10723.         djnz    l38a9
  10724.         ld      (curstartofpage),hl     ; Set start of screen
  10725.         ld      b,c
  10726.         ld      hl,(l4450)      ; Get current memory pointer
  10727. l38b5:
  10728.         call    findprevline            ; Find previous line n-times
  10729.         djnz    l38b5
  10730.         jr      l3890
  10731. ;
  10732. ; Control: BEGIN OF TEXT
  10733. ;
  10734. l38bc:
  10735.         ld      hl,(curstartofpage)     ; Get start of screen
  10736.         ld      de,(l4544)      ; Get start of text
  10737.         call    cmp_hl_de               ; Compare HL:DE
  10738.         jr      z,l38cb         ; Same
  10739.         call    l4147           ; Reset row
  10740. l38cb:
  10741.         call    l3e40           ; Sample character
  10742.         ld      hl,(l4544)      ; Get start of text
  10743.         ld      (l4450),hl      ; Set current memory pointer
  10744.         ld      (curstartofpage),hl     ; Set start of screen
  10745.         call    l401f
  10746.         call    l3d2c           ; Restore line
  10747.         ld      hl,l7b74
  10748.         ld      (l4452),hl      ; Init edit pointer
  10749.         jp      l3fe7 ;set column?
  10750. ;
  10751. ; Control: NEW LINE
  10752. ;
  10753. l38e6:
  10754.         bit     0,(iy+6)        ; Test insert
  10755.         jr      z,l38f2         ; New line
  10756.         call    l37ad           ; Line down
  10757.         jp      l3771           ; Goto start of line
  10758. l38f2:
  10759.         set     0,(iy+19)
  10760.         xor     a
  10761.         ld      (l4542),a       ; Force compile
  10762.         ld      a,lf
  10763.         call    puttoconsole_a          ; Put new line to console
  10764.         call    l3918
  10765.         call    l37a4           ; Set edit cursor
  10766.         bit     0,(iy+13)       ; Test auto tab
  10767.         ret     nz              ; Yeap
  10768.         call    l3a6b           ; Position to previous line
  10769.         ret     c               ; Below start of text
  10770.         ld      de,l43f2
  10771.         call    l412e           ; Find blank
  10772.         jp      c,l3a72         ; Yeap, insert tab
  10773.         ret
  10774. ;
  10775. ;
  10776. ;
  10777. l3918:
  10778.         call    l3950
  10779.         ld      hl,(l4450)      ; Get current memory pointer
  10780.         push    hl
  10781.         call    l3d2c           ; Restore line
  10782.         call    l3e40           ; Sample character
  10783.         pop     hl
  10784.         call    findnexteol             ; Find next end of line
  10785.         ld      (l4450),hl      ; Set current memory pointer
  10786.         ld      hl,l7b74
  10787. l392f:
  10788.         ld      (l4452),hl      ; Set current edit pointer
  10789.         call    l3fe7 ;set column?
  10790.         call    l401f
  10791.         jp      l3d2c           ; Restore line
  10792. ;
  10793. ; Control: INSERT LINE
  10794. ;
  10795. l393b::
  10796.         call    l3950
  10797.         call    l0200
  10798.         db      cr,lf,null
  10799.         ld      hl,(l4450)      ; Get current memory pointer
  10800.         call    findnexteol             ; Find next end of line
  10801.         call    l3c1a
  10802.         jp      l3d2c           ; Restore line
  10803. ;
  10804. ;
  10805. ;
  10806. l3950:
  10807.         call    l3e40           ; Sample character
  10808.         ld      a,(l01ae)       ; Test insert line implemented
  10809.         or      a
  10810.         push    af
  10811.         call    nz,l0262        ; Yeap: insert line
  10812.         pop     af
  10813.         call    z,l4139         ; Nope
  10814.         call    l3e23           ; Find last non blank
  10815.         inc     hl              ; Skip
  10816.         ld      de,(l4452)      ; Get current edit pointer
  10817.         call    l4191           ; Find min
  10818.         ld      de,l7b74
  10819.         or      a
  10820.         sbc     hl,de           ; Subtract base
  10821. l3970:
  10822.         ex      de,hl
  10823.         ld      hl,(l4450)      ; Get current memory pointer
  10824.         add     hl,de           ; Add offset
  10825.         push    hl
  10826.         scf
  10827.         ld      bc,-2
  10828.         call    l3f18
  10829.         pop     hl
  10830.         ld      (hl),cr         ; Close line
  10831.         inc     hl
  10832.         ld      (hl),lf
  10833.         ret
  10834. ;
  10835. ; Control: CURSOR LEFT
  10836. ;
  10837. l3984:
  10838.         ld      hl,(l4452)      ; Get current edit pointer
  10839.         call    l3c02           ; move character left
  10840.         ret     c               ; Not possible
  10841. l398b:
  10842.         ld      (l4452),hl      ; Set current edit pointer
  10843.         jp      l3fe7 ;set column?
  10844. ;
  10845. ; Control: CURSOR RIGHT
  10846. ;
  10847. l3991:
  10848.         ld      hl,(l4452)      ; Get current edit pointer
  10849.         call    l3be8           ; move character right
  10850.         ret     nc              ; Out off limit
  10851.         jr      l398b           ; Save new position
  10852. ;
  10853. ; Control: LAST CURSOR POSITION
  10854. ;
  10855. l399a:
  10856.         call    l3e40           ; Sample character
  10857.         ld      hl,(l4458)      ; Get edit pointer
  10858.         call    l3bf5           ; Get previous EOL
  10859.         ld      (l4450),hl      ; Set current memory pointer
  10860.         ld      hl,(l445a)
  10861.         jp      l392f
  10862. ;
  10863. ; Control: MARK SINGLE WORD
  10864. ;
  10865. l39ac:
  10866.         call    l3a0b           ; Word right
  10867.         call    l39ea           ; Word left
  10868.         ld      hl,(l4452)      ; Get current edit pointer
  10869. l39b5:
  10870.         call    l412a           ; Find delimiter
  10871.         jr      c,l39bf         ; Yeap
  10872.         call    l3be8           ; move character right
  10873.         jr      c,l39b5         ; Still in limit
  10874. l39bf:
  10875.         ld      (l4452),hl      ; Set current edit pointer
  10876.         call    l3702           ; Mark end
  10877.         call    l39ea           ; Word left
  10878.         jp      l3726           ; Mark start
  10879. ;
  10880. ;
  10881. ;
  10882. l39cb:
  10883.         ld      hl,(l4450)      ; Get current memory pointer
  10884.         call    findprevline            ; Find previous line
  10885.         jr      c,l3a05         ; Below start
  10886.         push    hl
  10887.         call    l3e40           ; Sample character
  10888.         pop     hl
  10889.         ld      (l4450),hl      ; Set current memory pointer
  10890.         res     0,(iy+14)
  10891.         call    l401f
  10892.         call    l3d2c           ; Restore line
  10893.         call    l3e23           ; Find last non blank
  10894.         jr      l3a01
  10895. ;
  10896. ; Control: WORD LEFT
  10897. ;
  10898. l39ea:
  10899.         ld      hl,(l4452)      ; Get current edit pointer
  10900. l39ed:
  10901.         call    l3c02           ; move character left
  10902.         jr      c,l39cb         ; At beginning of line
  10903.         call    l412a           ; Find delimiter
  10904.         jr      c,l39ed         ; Yeap
  10905. l39f7:
  10906.         call    l3c02           ; move character left
  10907.         jr      c,l3a01         ; At beginning of line
  10908.         call    l412a           ; Find delimiter
  10909.         jr      nc,l39f7        ; Nope
  10910. l3a01:
  10911.         inc     hl
  10912. l3a02:
  10913.         ld      (l4452),hl      ; Set current edit pointer
  10914. l3a05:
  10915.         ld      hl,(l4452)      ; Get current edit pointer
  10916.         jp      l3fe7 ;set column?
  10917. ;
  10918. ; Control: WORD RIGHT
  10919. ;
  10920. l3a0b:
  10921.         call    l3e23           ; Find last non blank
  10922.         ld      de,(l4452)      ; Get current edit pointer
  10923.         push    de
  10924.         xor     a
  10925.         sbc     hl,de
  10926.         jr      nc,l3a19
  10927.         inc     a
  10928. l3a19:
  10929.         ld      (l7b71),a       ; Set direction flag
  10930.         pop     hl
  10931. l3a1d:
  10932.         dec     hl
  10933. l3a1e:
  10934.         call    l3be8           ; move character right
  10935.         jr      c,l3a4e         ; Still in limit
  10936. l3a23:
  10937.         ld      hl,(l4450)      ; Get current memory pointer
  10938.         call    findnexteol             ; Find next end of line
  10939.         ret     c               ; Out of text
  10940.         call    l3e40           ; Sample character
  10941.         ld      hl,(l4450)      ; Get current memory pointer
  10942.         call    findnexteol             ; Find next end of line
  10943.         ld      (l4450),hl      ; Set current memory pointer
  10944.         res     0,(iy+14)
  10945.         call    l401f
  10946.         call    l3d2c           ; Restore line
  10947.         ld      hl,l7b74
  10948.         ld      (l4452),hl      ; Init current edit pointer
  10949.         call    l412a           ; Find delimiter
  10950.         jr      c,l3a1d         ; Yeap
  10951.         jp      l3fe7 ;set column?
  10952. l3a4e:
  10953.         call    l412a           ; Find delimiter
  10954.         jr      nc,l3a1e        ; Nope
  10955. l3a53:
  10956.         call    l3be8           ; move character right
  10957.         jr      c,l3a64         ; Still in limit
  10958.         ld      a,(l7b71)       ; Get direction
  10959.         or      a
  10960.         jr      nz,l3a23
  10961.         call    l3e23           ; Find last non blank
  10962.         inc     hl              ; Skip
  10963.         jr      l3a02
  10964. l3a64:
  10965.         call    l412a           ; Find delimiter
  10966.         jr      c,l3a53         ; Yeap
  10967.         jr      l3a02
  10968. ;
  10969. ; Position to previous line
  10970. ; EXIT  Reg HL points to line
  10971. ;       Carry set if below start of text
  10972. ;
  10973. l3a6b:
  10974.         ld      hl,(l4450)      ; Get current memory pointer
  10975.         call    findprevline            ; Find previous line
  10976.         ret
  10977. ;
  10978. ; Control: TABULATE
  10979. ;
  10980. l3a72:
  10981.         call    l3a6b           ; Position to previous line
  10982.         ret     c               ; Below start of text
  10983.         ld      a,(l4471)       ; Get row
  10984.         push    af              ; Save it
  10985.         ld      hl,(l4452)      ; Get current edit pointer
  10986.         ld      (l4468),hl      ; Save it
  10987.         res     0,(iy+7)        ; Disable video
  10988.         call    l3e40           ; Sample character
  10989.         ld      hl,(l4450)      ; Get current memory pointer
  10990.         push    hl
  10991.         call    findprevline            ; Find previous line
  10992.         ld      (l4450),hl      ; Set current memory pointer
  10993.         call    l3d2c           ; Restore line
  10994.         ld      hl,l43f2
  10995.         ld      (l7b72),hl      ; Set pointer to reduced delimiters
  10996.         call    l3a0b           ; Word right
  10997.         ld      hl,l43de
  10998.         ld      (l7b72),hl      ; Reset pointer to delimiters
  10999.         pop     hl
  11000.         pop     af
  11001.         ld      (l4471),a       ; Reset row
  11002.         ld      (l4450),hl      ; Reset current memory pointer
  11003.         call    l3d2c           ; Restore line
  11004.         set     0,(iy+7)        ; Enable video
  11005.         bit     0,(iy+6)        ; Test insert
  11006.         jp      nz,l374e        ; Nope
  11007.         ld      hl,(l4452)      ; Get current edit pointer
  11008.         ld      de,(l4468)      ; Get back previous pointer
  11009.         sbc     hl,de           ; Get difference
  11010.         ret     c               ; Nothing to clear
  11011.         ret     z
  11012.         ex      de,hl           ; Get length
  11013. l3ac5:
  11014.         push    de
  11015.         call    l41eb           ; Make room
  11016.         ld      (hl),' '        ; Insert blank
  11017.         pop     de
  11018.         dec     e
  11019.         jr      nz,l3ac5
  11020.         jp      l374e
  11021. ;
  11022. ; Control: DELETE TO END OF LINE
  11023. ;
  11024. l3ad2:
  11025.         ld      hl,(l4452)      ; Get current edit pointer
  11026.         push    hl
  11027.         call    l3fc5
  11028.         pop     hl
  11029.         push    hl
  11030.         ld      de,l7b74+_LinLen-1
  11031. l3ade:
  11032.         ld      (hl),' '        ; Clear character
  11033.         call    cmp_hl_de               ; Compare HL:DE
  11034.         jr      z,l3ae8         ; Match
  11035.         inc     hl              ; Advance
  11036.         jr      l3ade
  11037. l3ae8:
  11038.         pop     hl
  11039.         jp      l4197
  11040. ;
  11041. ; Control: DELETE LINE
  11042. ;
  11043. l3aec::
  11044.         ld      hl,l7b74
  11045.         ld      (l4452),hl      ; Set current edit pointer
  11046.         call    l3fe7 ;set column?
  11047.         call    l3ad2           ; Delete to end of line
  11048.         call    l3e40           ; Sample character
  11049.         ld      hl,(l4450)      ; Get current memory pointer
  11050.         push    hl
  11051.         push    hl
  11052.         call    findnexteol             ; Find next end of line
  11053.         pop     de
  11054.         jr      c,l3b10         ; Out of text
  11055.         or      a
  11056.         sbc     hl,de           ; Fet length
  11057.         ld      c,l
  11058.         ld      b,h
  11059.         pop     hl
  11060.         jp      nz,l3b26
  11061.         ret
  11062. l3b10:
  11063.         pop     hl
  11064.         jp      l3d2c           ; Restore line
  11065. l3b14:
  11066.         call    l3e44           ; Sample character
  11067.         ld      hl,(l4450)      ; Get current memory pointer
  11068.         call    findnexteol             ; Find next end of line
  11069.         jp      c,l3d2c         ; Restore line if out of text
  11070.         dec     hl
  11071.         dec     hl
  11072.         ld      bc,2
  11073.         or      a
  11074. l3b26:
  11075.         call    l3f18
  11076.         ld      a,(l01b4)       ; Test delete line implemented
  11077.         or      a
  11078.         jr      z,l3b3c         ; Nope
  11079.         call    l0259           ; Delete line
  11080.         ld      a,(l0169)       ; Get screen lines
  11081.         dec     a
  11082.         call    l3bbc
  11083.         jp      l3d2c           ; Restore line
  11084. l3b3c:
  11085.         call    l4139
  11086.         jp      l3d2c           ; Restore line
  11087. ;
  11088. ; Control: DELETE RIGHT WORD
  11089. ;
  11090. l3b42:
  11091.         call    l3e23           ; Find last non blank
  11092.         ld      de,(l4452)      ; Get current edit pointer
  11093.         call    cmp_hl_de               ; Compare HL:DE
  11094.         ex      de,hl
  11095.         jr      c,l3b14         ; HL<DE
  11096.         ld      a,(hl)
  11097.         cp      ' '             ; Test blank
  11098.         jr      z,l3b8c
  11099.         call    l412a           ; Find delimiter
  11100.         jr      c,l3b83         ; Yeap
  11101. l3b59:
  11102.         call    l4173
  11103.         call    l412a           ; Find delimiter
  11104.         jr      c,l3b86         ; Yeap
  11105.         jr      l3b59
  11106. ;
  11107. ;
  11108. ;
  11109. l3b63:
  11110.         ld      hl,(l4450)      ; Get current memory pointer
  11111.         call    findprevline            ; Find previous line
  11112.         ret     c               ; Below start of text
  11113.         call    l37d2           ; Line up
  11114.         call    l377a           ; Line right
  11115.         jp      l3b42           ; Delete right word
  11116. ;
  11117. ; Control: DELETE RIGHT CHARACTER
  11118. ;
  11119. l3b73:
  11120.         ld      hl,(l4452)      ; Get current edit pointer
  11121.         jr      l3b83           ; Go delete
  11122. ;
  11123. ; Control: DELETE LEFT CHARACTER
  11124. ;
  11125. l3b78:
  11126.         ld      hl,(l4452)      ; Get current edit pointer
  11127.         call    l3c02           ; move character left
  11128.         jr      c,l3b63         ; Beginning of line
  11129.         ld      (l4452),hl      ; Set current edit pointer
  11130. l3b83:
  11131.         call    l4173
  11132. l3b86:
  11133.         call    l3fe7 ;set column?
  11134.         jp      l4197
  11135. l3b8c:
  11136.         call    l4173
  11137.         ld      a,(hl)
  11138.         cp      ' '             ; Test blank
  11139.         jr      z,l3b8c         ; Skip them
  11140.         jr      l3b86
  11141. ;
  11142. ;
  11143. ;
  11144. l3b96:
  11145.         call    l428f           ; Test look ahead buffer empty
  11146.         jp      nz,l37a4        ; Nope, set edit cursor
  11147.         call    l3bac
  11148.         jr      nc,l3b96
  11149.         jp      l37a4           ; Set edit cursor
  11150. ;
  11151. ;
  11152. ;
  11153. l3ba4:
  11154.         call    l3bac
  11155.         jr      nc,l3ba4
  11156.         jp      l37a4           ; Set edit cursor
  11157. ;
  11158. ; ????????????????????????????????????????????
  11159. ; EXIT  Carry set if row same as screen height
  11160. ;
  11161. l3bac:
  11162.         ld      a,(l4475)       ; Get current row
  11163.         ld      hl,l0169        ; Get screen lines
  11164.         cp      (hl)            ; Compare
  11165.         scf
  11166.         ret     z               ; Same, so exit
  11167.         inc     (iy+9)          ; Bump row
  11168.         cp      (iy+5)          ; Test aginst row
  11169.         ret     z
  11170. ;
  11171. ;
  11172. ;
  11173. l3bbc:
  11174.         ld      h,0             ; Set column
  11175.         ld      l,a             ; Get row
  11176.         push    af
  11177.         call    l02a2           ; Position cursor
  11178.         pop     af
  11179.         ld      hl,(curstartofpage)     ; Get start of screen
  11180.         ld      b,a
  11181. l3bc8:
  11182.         dec     b
  11183.         jr      z,l3bd8
  11184.         call    findnexteol             ; Find next end of line
  11185.         jr      nc,l3bc8
  11186.         call    l3cec           ; Make normal video
  11187.         call    l3c12           ; Clear line
  11188.         xor     a
  11189.         ret
  11190. l3bd8:
  11191.         call    l3c1a
  11192.         xor     a
  11193.         ret
  11194. ;
  11195. ;
  11196. ;
  11197. l3bdd:
  11198.         inc     hl
  11199.         ld      de,(l4546)      ; Get end of text
  11200. ;
  11201. ; Compare addresses
  11202. ; ENTRY Regs HL and DE hold addresses
  11203. ; EXIT  Zero  set if HL=DE
  11204. ;       Carry set if HL<DE
  11205. ;
  11206. cmp_hl_de:
  11207.         push    hl
  11208.         or      a
  11209.         sbc     hl,de           ; Compare
  11210.         pop     hl
  11211.         ret
  11212. ;
  11213. ; move pointer right
  11214. ; ENTRY Reg HL holds pointer
  11215. ; EXIT  Carry reset if pointer ou of limit
  11216. ;
  11217. l3be8:
  11218.         inc     hl              ; Point to next
  11219.         ld      de,l7b74+_LinLen-2
  11220.         jr      cmp_hl_de               ; Compare HL:DE
  11221. ;
  11222. ; Fix to start of line
  11223. ; ENTRY Reg HL holds text pointer
  11224. ; EXIT  Reg HL decremented by 1
  11225. ;       Carry set if HL < Start_of_Text
  11226. ;
  11227. l3bee:
  11228.         dec     hl
  11229.         ld      de,(l4544)      ; Get start of text
  11230.         jr      cmp_hl_de               ; Compare HL:DE
  11231. ;
  11232. ; Find EOL of previous line
  11233. ; ENTRY Reg HL holds current pointer
  11234. ; EXIT  Reg HL points to previous end
  11235. ;
  11236. l3bf5:
  11237.         ld      a,lf
  11238. l3bf7:
  11239.         call    l3bee           ; Fix to start of line
  11240.         ret     z               ; Got it
  11241.         jr      c,l3c00         ; Here before start
  11242.         cp      (hl)            ; Find new line
  11243.         jr      nz,l3bf7        ; Nope
  11244. l3c00:
  11245.         inc     hl              ; Adjust pointer
  11246.         ret
  11247. ;
  11248. ; move pointer left
  11249. ; ENTRY Reg HL holds pointer
  11250. ; EXIT  Carry set if pointer out of limit
  11251. ;
  11252. l3c02:
  11253.         dec     hl              ; Get previous
  11254.         ld      de,l7b74        ; Init pointer
  11255.         jr      cmp_hl_de               ; Compare HL:DE
  11256. ;
  11257. ;
  11258. ;
  11259. l3c08:
  11260.         cp      cr              ; Test return
  11261.         ret     nz              ; Nope
  11262.         ld      a,(hl)
  11263.         call    l3bdd
  11264.         ret     nc
  11265.         jr      l3c08
  11266. ;
  11267. ; Clear line
  11268. ;
  11269. l3c12:
  11270.         ld      a,(l0168)       ; Get screen columns
  11271.         dec     a
  11272.         ld      b,a
  11273. l3c17:
  11274.         jp      l3cf9           ; Clear to end of line
  11275. ;
  11276. ;
  11277. ;
  11278. l3c1a:
  11279.         call    l3ca1
  11280.         call    l3cc0
  11281.         ld      a,(l446c) ;xscroll???
  11282.         ld      b,a
  11283.         or      a
  11284.         jr      z,l3c36
  11285. l3c27:
  11286.         ld      a,(hl)
  11287.         call    l3bdd
  11288.         jr      nc,l3c12        ; Clear line
  11289.         call    l3c08
  11290.         cp      lf              ; Test new line
  11291.         jr      z,l3c12         ; Clear line if so
  11292.         djnz    l3c27 ;skip xscroll chars???
  11293. l3c36:
  11294.         ld      a,(l0168)       ; Get screen columns
  11295.         dec     a
  11296.         ld      b,a
  11297.         bit     0,(iy+16)
  11298.         jr      z,l3c5e
  11299. l3c41:
  11300.         call    l3ca1
  11301.         call    l3cc0
  11302.         push    hl
  11303.         call    l3e23           ; Find last non blank
  11304.         ld      de,(l4452)      ; Get current edit pointer
  11305.         call    l4191           ; Find min
  11306.         ex      de,hl           ; Change to max
  11307.         inc     hl
  11308.         ld      (l4486),hl
  11309.         ex      de,hl
  11310.         pop     hl
  11311.         call    cmp_hl_de               ; Compare HL:DE
  11312.         jr      nc,l3c89        ; Clear if HL>=DE
  11313. l3c5e:
  11314.         call    l3ca1
  11315.         call    l3cc0
  11316.         ld      de,(l4486)
  11317.         call    cmp_hl_de               ; Compare HL:DE
  11318.         jr      z,l3c89         ; Clear if same
  11319.         ld      a,(hl)
  11320.         call    l3bdd
  11321.         jr      nc,l3c17        ; Clear line
  11322.         call    l3c08
  11323.         cp      lf              ; Test end of line
  11324.         jr      z,l3c17         ; Clear on new line
  11325.         call    l3c8b           ; Process control character
  11326.         djnz    l3c5e
  11327. l3c7f:
  11328.         ld      a,(hl)
  11329.         call    l3bdd
  11330.         jr      nc,l3c89        ; Clear line
  11331.         cp      lf              ; Test new line
  11332.         jr      nz,l3c7f
  11333. l3c89:
  11334.         jr      l3c17           ; Clear line
  11335. ;
  11336. ; Process control character
  11337. ;
  11338. l3c8b:
  11339.         cp      ' '             ; Test control character
  11340.         jr      nc,l3c96        ; Nope
  11341.         add     a,'@'           ; Make ASCII
  11342.         push    af
  11343.         call    l3c99           ; Select video
  11344.         pop     af
  11345. l3c96:
  11346.         jp      puttoconsole_a          ; Put to console
  11347. ;
  11348. ; Select video
  11349. ;
  11350. l3c99:
  11351.         ld      a,(l00e0)       ; Get video mode
  11352.         or      a
  11353.         jr      z,l3cec         ; Make normal video
  11354.         jr      l3cdf           ; Set low video
  11355. ;
  11356. ;
  11357. ;
  11358. l3ca1:
  11359.         bit     0,(iy+16)
  11360.         ret     z
  11361.         bit     0,(iy+20)       ; Test block set
  11362.         jr      nz,l3cec        ; Nope, make normal video
  11363.         ld      de,(l4464)      ; Get block start address
  11364.         call    cmp_hl_de               ; Compare HL:DE
  11365.         jr      c,l3cec         ; Make normal video
  11366.         ld      de,(l4466)      ; Get end of block pointer
  11367.         call    cmp_hl_de               ; Compare HL:DE
  11368.         jr      c,l3cdf         ; Set low video
  11369.         jr      l3cec           ; Make normal video
  11370. ;
  11371. ;
  11372. ;
  11373. l3cc0:
  11374.         bit     0,(iy+16)
  11375.         ret     nz
  11376.         bit     0,(iy+20)       ; Test block set
  11377.         jr      nz,l3cec        ; Nope, make normal video
  11378.         ld      de,(l4460)      ; Get block start pointer
  11379.         call    cmp_hl_de               ; Compare HL:DE
  11380.         jr      c,l3cec         ; Make normal video
  11381.         ld      de,(l4462)      ; Get block end pointer
  11382.         call    cmp_hl_de               ; Compare HL:DE
  11383.         jr      z,l3cec         ; Make normal video
  11384.         jr      nc,l3cec        ; Make normal video
  11385. ;
  11386. ; Set low video
  11387. ;
  11388. l3cdf:
  11389.         ld      a,(l00e0)       ; Get video mode
  11390.         or      a               ; Test enabled
  11391.         ret     z               ; Nope
  11392.         bit     0,(iy+7)        ; Test selected
  11393.         ret     z               ; Nope
  11394.         jp      setlowvideo             ; Set low video
  11395. ;
  11396. ; Set normal video
  11397. ;
  11398. l3cec:
  11399.         ld      a,(l00e0)       ; Get video mode
  11400.         or      a               ; Test enabled
  11401.         ret     nz              ; Yeap
  11402.         bit     0,(iy+7)        ; Test selected
  11403.         ret     z               ; Nope
  11404.         jp      setnormvideo            ; Set normal video
  11405. ;
  11406. ; Clear to end of line
  11407. ; ENTRY Reg B holds column position
  11408. ;
  11409. l3cf9:
  11410.         inc     b               ; Test position
  11411.         dec     b
  11412.         ret     z               ; Ignore left margin
  11413.         ld      a,(l01bc)       ; Test clear to end of line implemented
  11414.         or      a
  11415.         jp      nz,l0299        ; Yeap
  11416. l3d03:
  11417.         ld      a,' '
  11418.         call    puttoconsole_a          ; Put blanks to console
  11419.         djnz    l3d03
  11420.         ret
  11421. ;
  11422. ; Delete current line
  11423. ;
  11424. l3d0b:
  11425.         ld      a,(l01b4)       ; Test delete line implemented
  11426.         or      a
  11427.         jr      nz,l3d23        ; Yeap
  11428.         ld      (l4474),a       ; Set no change
  11429.         ld      a,(l0169)       ; Get screen lines
  11430.         dec     a
  11431.         ld      l,a             ; Set row
  11432.         ld      h,0             ; Set column
  11433.         call    l02a2           ; Position cursor
  11434.         ld      a,lf
  11435.         jp      puttoconsole_a          ; Put new line to console
  11436. l3d23:
  11437.         ld      hl,256*0+1
  11438.         call    l02a2           ; Position cursor
  11439.         jp      l0259           ; Delete line
  11440. ;
  11441. ; Control: RESTORE DELETED LINE
  11442. ;
  11443. l3d2c:
  11444.         ld      hl,(l4450)      ; Get current memory pointer
  11445.         ld      de,0
  11446.         ld      (l4464),de      ; Reset start of block pointer
  11447.         ld      (l4466),de      ; Reset end of block pointer
  11448.         ld      b,_LinLen       ; Set max length
  11449.         ld      ix,l7b74        ; Set base address
  11450.         ld      (iy+1),0        ; Clear block state
  11451. l3d44: ;;;;;;
  11452.         ld      a,(hl)
  11453.         ld      de,(l4460)      ; Get block start pointer
  11454.         call    cmp_hl_de               ; Compare HL:DE
  11455.         jr      nz,l3d56        ; Not same addresses
  11456.         ld      (l4464),ix      ; Set start of block pointer
  11457.         set     0,(iy+1)        ; Set start block
  11458. l3d56:
  11459.         ld      de,(l4462)      ; Get block end pointer
  11460.         call    cmp_hl_de               ; Compare HL:DE
  11461.         jr      nz,l3d67        ; Not same addresses
  11462.         ld      (l4466),ix      ; Set end of block pointer
  11463.         set     1,(iy+1)        ; Set end block
  11464. l3d67:
  11465.         cp      cr              ; Test end of line
  11466.         jr      nz,l3dc3        ; Nope
  11467.         ld      (ix+0),' '      ; Fill with blank
  11468.         inc     ix
  11469.         dec     b
  11470.         jr      z,l3dd9
  11471.         call    l3bdd
  11472.         jr      nc,l3d44
  11473. l3d79:
  11474.         ld      de,(l4462)      ; Get block end pointer
  11475.         call    cmp_hl_de               ; Compare HL:DE
  11476.         jr      nc,l3d8a        ; HL>= Start_Of_Block
  11477.         push    hl
  11478.         ld      hl,-1
  11479.         ld      (l4466),hl      ; Set end of block pointer
  11480.         pop     hl
  11481. l3d8a:
  11482.         ld      de,(l4460)      ; Get block start pointer
  11483.         call    cmp_hl_de               ; Compare HL:DE
  11484.         jr      nc,l3d99        ; HL>= End_Of_Block
  11485.         ld      hl,-1
  11486.         ld      (l4464),hl      ; Set start of block pointer
  11487. l3d99: ;;;;;
  11488.         ld      a,_LinLen
  11489.         sub     b               ; Calculate remaining length
  11490.         ld      (l446f),a       ; Save relative column
  11491. l3d9f:
  11492.         ld      (ix+0),' '      ; Fill with blanks
  11493.         inc     ix
  11494.         djnz    l3d9f
  11495.         ld      hl,(l4452)      ; Get current edit pointer
  11496.         call    l3fe7 ;set column?
  11497.         bit     0,(iy+14)
  11498.         set     0,(iy+14)
  11499.         jp      nz,l374e
  11500.         ld      a,(l4475)       ; Get current row
  11501.         dec     a
  11502.         cp      (iy+5)          ; Test against row
  11503.         ret     nc
  11504.         jp      l374e
  11505. l3dc3:
  11506.         cp      lf              ; Test end of line
  11507.         jr      z,l3d79         ; Yeap
  11508.         ld      (ix+0),a        ; Store character
  11509.         inc     ix
  11510.         dec     b               ; Test still room
  11511.         jr      nz,l3dd1        ; Yeap
  11512.         jr      l3dd9           ; Line too long
  11513. l3dd1:
  11514.         call    l3bdd
  11515.         jr      nc,l3d79
  11516.         jp      l3d44
  11517. l3dd9:
  11518.         call    l3e04           ; Tell error
  11519.         db      'Line too long - CR inserted'
  11520.         db      null
  11521.         call    l3f12
  11522.         ld      hl,_LinLen-2
  11523.         call    l3970
  11524.         jp      l3d2c           ; Restore line
  11525. ;
  11526. ;
  11527. ;
  11528. l3e04:
  11529.         call    l3ba4
  11530. l3e07:
  11531.         call    l3e0d           ; Set cursor
  11532.         jp      l4211
  11533. ;
  11534. ; Set cursor home
  11535. ;
  11536. l3e0d:
  11537.         ld      (iy+8),0        ; Set no change
  11538.         ld      hl,256*0+0
  11539.         call    l02a2           ; Position cursor
  11540.         call    l3c12           ; Clear line
  11541.         ld      hl,256*0+0
  11542.         call    l02a2           ; Position cursor
  11543.         jp      l3cdf           ; Set low video
  11544. ;
  11545. ; Find last non blank in current line
  11546. ; EXIT  Reg HL holds pointer to non blank
  11547. ;
  11548. l3e23:
  11549.         ld      a,' '           ; Set what we are looking for
  11550.         ld      hl,l7b74+_LinLen-1
  11551.         ld      de,l7b74-1      ; Init pointers
  11552. l3e2b:
  11553.         cp      (hl)            ; Test match
  11554.         ret     nz              ; Nope, got it
  11555.         dec     hl
  11556.         call    cmp_hl_de               ; Test beginning
  11557.         jr      nz,l3e2b        ; Nope
  11558.         ret
  11559. ;
  11560. ; Get pointer within limits
  11561. ; ENTRY Reg HL holds 1st pointer
  11562. ;       Reg BC holds 2nd pointer
  11563. ; EXIT  Reg HL unchanged if out of line
  11564. ;       Reg HL holds MIN(HL,BC) else
  11565. ;
  11566. l3e34:
  11567.         ld      de,l7b74+_LinLen
  11568.         call    cmp_hl_de               ; Compare HL:DE
  11569.         ret     nc              ; End found
  11570.         ld      d,b
  11571.         ld      e,c
  11572.         jp      l4191           ; Find min
  11573. ;
  11574. ; Poll character, insert at end of line
  11575. ;
  11576. l3e40:
  11577.         call    l3e23           ; Find last non blank
  11578.         inc     hl              ; Skip over
  11579. ;
  11580. ; Poll character, insert at current position
  11581. ; ENTRY Reg HL holds current text address
  11582. ;
  11583. l3e44:
  11584.         ld      c,l             ; Copy pointer
  11585.         ld      b,h
  11586.         ld      hl,(l4464)      ; Get start of block pointer
  11587.         call    l3e34           ; Fix it
  11588.         ld      (l4464),hl      ; Set start of block pointer
  11589.         ld      hl,(l4466)      ; Get end of block pointer
  11590.         call    l3e34           ; Fix it
  11591.         ld      (l4466),hl      ; Set end of block pointer
  11592.         ld      l,c
  11593.         ld      h,b
  11594.         inc     hl
  11595.         ld      de,l7b74
  11596.         or      a
  11597.         sbc     hl,de           ; Get relative position
  11598.         push    hl
  11599.         ld      a,(l446f)       ; Get relative column
  11600.         sub     l               ; Subtract it
  11601.         ld      c,a
  11602.         ld      b,0             ; Expand for 16 bits
  11603.         jr      nc,l3e6d
  11604.         ld      b,-1            ; Signed expansion
  11605. l3e6d:
  11606.         ld      hl,(l4450)      ; Get current memory pointer
  11607.         call    nz,l3f18
  11608.         pop     bc
  11609.         ld      ix,(l4450)      ; Get current memory pointer
  11610.         ld      hl,l7b74        ; Load base
  11611.         ld      b,c             ; Copy position
  11612.         dec     b               ; Test any
  11613.         inc     b
  11614.         jr      z,l3ea5         ; Nope
  11615. l3e80:
  11616.         ld      a,(hl)          ; Get character
  11617.         ld      de,(l4464)      ; Get start of block pointer
  11618.         call    cmp_hl_de               ; Compare HL:DE
  11619.         jr      nz,l3e8e        ; Not the same
  11620.         ld      (l4460),ix      ; Set block start pointer
  11621. l3e8e:
  11622.         ld      de,(l4466)      ; Get end of block pointer
  11623.         call    cmp_hl_de               ; Compare HL:DE
  11624.         jr      nz,l3e9b        ; Not the same
  11625.         ld      (l4462),ix      ; Set block end pointer
  11626. l3e9b:
  11627.         ld      (ix+0),a        ; Unpack character
  11628.         inc     hl
  11629.         inc     ix
  11630.         djnz    l3e80
  11631.         dec     ix
  11632. l3ea5:
  11633.         ld      a,cr
  11634.         ld      (ix+0),a        ; Set end of line
  11635.         ret
  11636. ;
  11637. ; Display characters left and check enough memory
  11638. ;
  11639. l3eab:
  11640.         ld      hl,(l4548)      ; Get top of available memory
  11641.         or      a
  11642.         sbc     hl,de           ; Test remainder
  11643.         jr      c,l3ed9         ; Nope
  11644.         ld      bc,l00fe
  11645.         sbc     hl,bc           ; Test min
  11646.         ret     nc              ; Yeap
  11647.         add     hl,bc
  11648.         push    hl
  11649.         call    l3e0d           ; Set cursor
  11650.         pop     hl
  11651.         ld      b,0
  11652.         call    l30fe           ; Tell bytes left
  11653.         call    l4211
  11654.         db      ' byte(s) left'
  11655.         db      null
  11656.         call    l3f12           ; Wait for quit
  11657.         ret
  11658. l3ed9:
  11659.         call    l3e04
  11660.         db      'ERROR: Out of space'
  11661.         db      null
  11662.         call    l3f12           ; Wait for quit
  11663.         jp      l2ebd
  11664. ;
  11665. ; Test editor function cancelled
  11666. ;
  11667. l3ef6:
  11668.         cp      a_CAN           ; Test cancel
  11669.         ret     nz              ; Nope
  11670.         call    l3e04
  11671.         db      '*** INTERRUPTED'
  11672.         db      null
  11673.         call    l3f12           ; Wait for quit
  11674.         jp      l2ebd
  11675. ;
  11676. ; Clear ahaed buffer and wait for user quit
  11677. ;
  11678. l3f12:
  11679.         call    l422b           ; Clear look ahead buffer
  11680.         jp      l2e76           ; Get ESCape
  11681. ;
  11682. ;
  11683. ;
  11684. l3f18:
  11685.         push    hl
  11686.         push    bc
  11687.         jr      nc,l3f96
  11688.         ld      de,(l4546)      ; Get end of text
  11689.         push    de
  11690.         push    de
  11691.         ex      de,hl
  11692.         or      a
  11693.         sbc     hl,de
  11694.         ex      (sp),hl
  11695.         or      a
  11696.         sbc     hl,bc
  11697.         jp      nc,l3ed9
  11698.         ld      e,l
  11699.         ld      d,h
  11700.         push    de
  11701.         call    l3eab           ; Test enough room
  11702.         pop     de
  11703.         pop     bc
  11704.         inc     bc
  11705.         pop     hl
  11706.         ld      (l4546),de      ; Set end of text
  11707.         ld      a,b
  11708. l3f3c:
  11709.         sub     HIGH _SavLen
  11710.         jr      c,l3f4d
  11711.         ld      b,a
  11712.         push    bc
  11713.         ld      bc,_SavLen
  11714.         lddr                    ; move down
  11715.         pop     bc
  11716.         call    l4232           ; Poll character from input
  11717.         jr      l3f3c
  11718. l3f4d:
  11719.         ld      a,c
  11720.         or      b
  11721.         jr      z,l3f53
  11722.         lddr
  11723. l3f53:
  11724.         pop     bc
  11725.         pop     hl
  11726.         ex      de,hl
  11727.         inc     de
  11728.         ld      hl,(l4460)      ; Get block start pointer
  11729.         call    l3f8e
  11730.         ld      (l4460),hl      ; Set block start pointer
  11731.         ld      hl,(l4462)      ; Get block end pointer
  11732.         call    l3f8e
  11733.         ld      (l4462),hl      ; Set block end pointer
  11734.         ld      hl,(curstartofpage)     ; Get start of screen
  11735.         call    l3f8e
  11736.         ld      (curstartofpage),hl     ; Set start of screen
  11737.         ld      hl,(l4450)      ; Get current memory pointer
  11738.         call    l3f8e
  11739.         ld      (l4450),hl      ; Set current memory pointer
  11740.         ld      hl,(l4454)      ; Get block pointer
  11741.         call    l3f8e
  11742.         ld      (l4454),hl      ; Set block pointer
  11743.         ld      hl,(l4458)      ; Get edit pointer
  11744.         call    l3f8e
  11745.         ld      (l4458),hl      ; Set edit pointer
  11746.         ret
  11747. ;
  11748. ;
  11749. ;
  11750. l3f8e:
  11751.         call    cmp_hl_de               ; Compare HL:DE
  11752.         ret     c
  11753.         or      a
  11754.         sbc     hl,bc
  11755.         ret
  11756. ;
  11757. ;
  11758. ;
  11759. l3f96:
  11760.         push    hl
  11761.         add     hl,bc
  11762.         push    hl
  11763.         ld      de,(l4546)      ; Get end of text
  11764.         inc     de
  11765.         ex      de,hl
  11766.         or      a
  11767.         sbc     hl,de
  11768.         ld      c,l
  11769.         ld      b,h
  11770.         pop     hl
  11771.         pop     de
  11772.         ld      a,b
  11773. l3fa7:
  11774.         sub     HIGH _SavLen
  11775.         jr      c,l3fb8
  11776.         ld      b,a
  11777.         push    bc
  11778.         ld      bc,_SavLen
  11779.         ldir                    ; move up
  11780.         pop     bc
  11781.         call    l4232           ; Poll character from input
  11782.         jr      l3fa7
  11783. l3fb8:
  11784.         ld      a,c
  11785.         or      b
  11786.         jr      z,l3fbf
  11787.         ldir
  11788.         dec     de
  11789. l3fbf:
  11790.         ld      (l4546),de      ; Set end of text
  11791.         jr      l3f53
  11792. ;
  11793. ;
  11794. ;
  11795. l3fc5:
  11796.         push    hl
  11797.         ld      de,(l4464)      ; Get start of block pointer
  11798.         call    l4191           ; Find min
  11799.         bit     0,(iy+1)        ; Test start block
  11800.         jr      z,l3fd6         ; Nope
  11801.         ld      (l4464),hl      ; Set start of block pointer
  11802. l3fd6:
  11803.         pop     hl
  11804.         bit     1,(iy+1)        ; Test end block
  11805.         ret     z               ; Nope
  11806.         ld      de,(l4466)      ; Get end of block pointer
  11807.         call    l4191           ; Find min
  11808.         ld      (l4466),hl      ; Set end of block pointer
  11809.         ret
  11810. ;
  11811. ;
  11812. ;set column?
  11813. l3fe7:
  11814.         ld      de,l7b74        ; Get base address
  11815.         ld      a,(l0168)       ; Get screen columns
  11816.         dec     a
  11817.         ld      c,a
  11818.         or      a
  11819.         sbc     hl,de
  11820.         ld      a,l
  11821.         sub     (iy+0)
  11822.         jr      c,l4012
  11823.         cp      c
  11824.         jr      c,l400e
  11825.         sub     c
  11826.         inc     a
  11827.         add     a,(iy+0)
  11828.         ld      (l446c),a ;xscroll???
  11829.         ld      a,(l0168)       ; Get screen columns
  11830.         dec     a
  11831.         dec     a
  11832.         ld      (l4470),a       ; Set column to end
  11833.         jp      l3762
  11834. l400e:
  11835.         ld      (l4470),a       ; Set column
  11836.         ret
  11837. l4012:
  11838.         add     a,(iy+0)
  11839.         ld      (l446c),a ;xscroll???
  11840.         ld      (iy+4),0        ; Clear column
  11841.         jp      l3762
  11842. ;
  11843. ;
  11844. ;
  11845. l401f:
  11846.         bit     0,(iy+7)
  11847.         ret     z
  11848.         ld      hl,(curstartofpage)     ; Get start of screen
  11849.         ld      de,(l4544)      ; Get start of text
  11850.         call    l4191           ; Find min
  11851.         ex      de,hl
  11852.         ld      (curstartofpage),hl     ; Set max for start of screen
  11853.         ld      bc,1
  11854.         ld      de,(l4450)      ; Get current memory pointer
  11855.         call    cmp_hl_de               ; Compare HL:DE
  11856.         jp      z,l40da         ; Same
  11857.         jr      c,l4086         ; HL < Current_Pointer
  11858. l4041:
  11859.         ld      de,(l4450)      ; Get current memory pointer
  11860.         call    cmp_hl_de               ; Compare HL:DE
  11861.         jr      z,l4055         ; Same
  11862.         call    findprevline            ; Find previous line
  11863.         inc     bc
  11864.         ld      a,c
  11865.         or      a
  11866.         call    z,l4232         ; Poll character from input
  11867.         jr      l4041
  11868. l4055:
  11869.         ld      (curstartofpage),hl     ; Set start of screen
  11870.         ld      (iy+5),1        ; Init row
  11871.         set     0,(iy+14)
  11872.         ld      a,b
  11873.         or      a
  11874.         jr      nz,l4083        ; Test row
  11875.         ld      a,(l01ae)       ; Test insert line implemented
  11876.         or      a
  11877.         jr      z,l4083         ; Nope
  11878.         ld      a,(l0169)       ; Get screen lines
  11879.         dec     a
  11880.         cp      c
  11881.         jr      c,l4083
  11882.         dec     c
  11883.         ld      hl,256*0+1
  11884.         call    l02a2           ; Position cursor
  11885.         dec     c
  11886.         push    af
  11887.         inc     c
  11888. l407b:
  11889.         call    l0262           ; Insert line
  11890.         dec     c
  11891.         jr      nz,l407b
  11892.         pop     af
  11893.         ret     z
  11894. l4083:
  11895.         jp      l4147           ; Reset row
  11896. l4086:
  11897.         ld      de,(l4450)      ; Get current memory pointer
  11898.         call    cmp_hl_de               ; Compare HL:DE
  11899.         jr      z,l409a         ; Same
  11900.         call    findnexteol             ; Find next end of line
  11901.         inc     bc
  11902.         ld      a,c
  11903.         or      a
  11904.         call    z,l4232         ; Poll character from input
  11905.         jr      l4086
  11906. l409a:
  11907.         ld      a,b
  11908.         or      a
  11909.         jr      nz,l40de
  11910.         ld      a,(l0169)       ; Get screen lines
  11911.         dec     a
  11912.         ld      e,a
  11913.         ld      a,c
  11914.         sub     e
  11915.         ld      d,a
  11916.         inc     d
  11917.         jr      c,l40da
  11918.         dec     d
  11919.         jr      nz,l40b3
  11920.         bit     0,(iy+21)
  11921.         jp      nz,l4103
  11922. l40b3:
  11923.         inc     d
  11924.         sub     e
  11925.         jr      nc,l40de
  11926.         ld      a,(l4475)       ; Get current row
  11927.         sub     d               ; Test row
  11928.         jr      c,l40de
  11929.         jr      z,l40de
  11930.         ld      (l4475),a       ; Set row
  11931.         ld      hl,(curstartofpage)     ; Get start of screen
  11932.         ld      b,d
  11933.         push    de
  11934. l40c7:
  11935.         call    findnexteol             ; Find next end of line
  11936.         push    hl
  11937.         call    l3d0b           ; Delete current line
  11938.         pop     hl
  11939.         djnz    l40c7
  11940.         ld      (curstartofpage),hl     ; Set start of screen
  11941.         pop     de
  11942. l40d5:
  11943.         dec     e
  11944.         ld      (iy+5),e        ; Set row
  11945.         ret
  11946. l40da:
  11947.         ld      (iy+5),c        ; Set row
  11948.         ret
  11949. l40de:
  11950.         ld      hl,(curstartofpage)     ; Get start of screen
  11951.         dec     bc
  11952.         ld      a,(l0169)       ; Get screen lines
  11953.         sub     3
  11954.         ld      e,a
  11955.         ld      a,c
  11956.         sub     e
  11957.         ld      c,a
  11958.         jr      nc,l40ee
  11959.         dec     b
  11960. l40ee:
  11961.         call    findnexteol             ; Find next end of line
  11962.         dec     bc
  11963.         ld      a,c
  11964.         or      b
  11965.         jr      nz,l40ee
  11966.         ld      (curstartofpage),hl     ; Set start of screen
  11967.         call    l4147           ; Reset row
  11968.         set     0,(iy+14)
  11969.         jp      l401f
  11970. l4103:
  11971.         call    l40d5
  11972.         ld      a,(l4475)       ; Get current row
  11973.         ld      l,a
  11974.         ld      a,(l0169)       ; Get screen lines
  11975.         cp      l
  11976.         ld      a,l
  11977.         jr      z,l4117
  11978.         dec     a
  11979.         jr      z,l4117
  11980.         ld      (l4475),a       ; Set row
  11981. l4117:
  11982.         ld      hl,(curstartofpage)     ; Get start of screen
  11983.         call    findnexteol             ; Find next end of line
  11984.         ld      (curstartofpage),hl     ; Set start of screen
  11985.         call    l3d0b           ; Delete current line
  11986.         ld      a,(l0169)       ; Get screen lines
  11987.         dec     a
  11988.         jp      l3bbc
  11989. ;
  11990. ; Find delimiter
  11991. ; ENTRY Reg HL points to current text
  11992. ; EXIT  Carry set if delimiter found
  11993. ;
  11994. l412a:
  11995.         ld      de,(l7b72)      ; Get pointer to delimiters
  11996. l412e:
  11997.         ld      a,(de)          ; Test end of list
  11998.         or      a
  11999.         ret     z               ; Yeap
  12000.         cp      (hl)            ; Compare
  12001.         jr      z,l4137         ; Got it
  12002.         inc     de
  12003.         jr      l412e
  12004. l4137:
  12005.         scf
  12006.         ret
  12007. ;
  12008. ; Delete line if no ESC sequence present
  12009. ;
  12010. l4139:
  12011.         push    af
  12012.         ld      a,(l4471)       ; Get row
  12013.         cp      (iy+9)          ; Compare
  12014.         jr      nc,l4145
  12015.         ld      (l4475),a       ; Set row
  12016. l4145:
  12017.         pop     af
  12018.         ret
  12019. ;
  12020. ; Reset row
  12021. ;
  12022. l4147:
  12023.         ld      (iy+9),1        ; Init row
  12024.         ret
  12025. ;
  12026. ; Adjust pointer for inserting characters
  12027. ; ENTRY Reg BC holds number of characters to be inserted
  12028. ;
  12029. l414c:
  12030.         ex      de,hl
  12031.         bit     0,(iy+1)        ; Test start block
  12032.         jr      z,l415f         ; Nope
  12033.         ld      hl,(l4464)      ; Get start of block pointer
  12034.         call    cmp_hl_de               ; Compare HL:DE
  12035.         jr      c,l415f         ; Start_of_block < DE
  12036.         add     hl,bc           ; Add offset
  12037.         ld      (l4464),hl      ; Set start of block pointer
  12038. l415f:
  12039.         bit     1,(iy+1)        ; Test end block
  12040.         jr      z,l4171         ; Nope
  12041.         ld      hl,(l4466)      ; Get end of block pointer
  12042.         call    cmp_hl_de               ; Compare HL:DE
  12043.         jr      c,l4171         ; End_of_block < DE
  12044.         add     hl,bc           ; Add offset
  12045.         ld      (l4466),hl      ; Set end of block pointer
  12046. l4171:
  12047.         ex      de,hl
  12048.         ret
  12049. ;
  12050. ;
  12051. ;
  12052. l4173:
  12053.         push    hl
  12054.         ld      bc,-1
  12055.         call    l414c           ; Delete one character
  12056.         ex      de,hl
  12057.         ld      hl,l7b74+_LinLen-1
  12058.         or      a
  12059.         sbc     hl,de
  12060.         jr      z,l418a         ; Same
  12061.         ld      c,l
  12062.         ld      b,h
  12063.         ld      l,e
  12064.         ld      h,d
  12065.         inc     hl
  12066.         ldir                    ; Unpack
  12067. l418a:
  12068.         ld      hl,l7b74+_LinLen-1
  12069.         ld      (hl),' '        ; Clear last entry
  12070.         pop     hl
  12071.         ret
  12072. ;
  12073. ; Get minimum of two addresses
  12074. ; ENTRY Reg HL holds 1st address
  12075. ;       Reg DE holds 2nd address
  12076. ; EXIT  Regs swapped if 1st >= 2nd
  12077. ;
  12078. l4191:
  12079.         call    cmp_hl_de               ; Compare HL:DE
  12080.         ret     c               ; HL < DE
  12081.         ex      de,hl           ; Swap
  12082.         ret
  12083. ;
  12084. ;
  12085. ;
  12086. l4197:
  12087.         call    l37a4           ; Set edit cursor
  12088.         ld      a,(l0168)       ; Get screen columns
  12089.         dec     a
  12090.         sub     (iy+4)          ; Subtract from column
  12091.         ld      hl,(l4452)      ; Get current edit pointer
  12092.         ld      b,a
  12093.         set     0,(iy+16)
  12094.         call    l3c41
  12095.         res     0,(iy+16)
  12096.         ret
  12097. ;
  12098. ; Adjust for next end of line
  12099. ; ENTRY Reg HL holds current pointer
  12100. ; EXIT  Reg HL holds pointer to next line
  12101. ;       Carry set if pointer behind end address
  12102. ;
  12103. findnexteol:
  12104.         push    bc
  12105.         ex      de,hl
  12106.         ld      hl,(l4546)      ; Get end of text
  12107.         dec     hl
  12108.         or      a
  12109.         sbc     hl,de           ; Build difference
  12110.         ld      b,h
  12111.         ld      c,l
  12112.         inc     bc
  12113.         ex      de,hl
  12114.         ld      d,h
  12115.         ld      e,l
  12116.         jr      c,l41cc         ; Out of text
  12117.         ld      a,lf
  12118.         cpir                    ; Find new line
  12119.         jp      po,l41cc
  12120.         or      a
  12121.         pop     bc
  12122.         ret
  12123. l41cc:
  12124.         scf                     ; Set out of text
  12125.         ex      de,hl
  12126.         pop     bc
  12127.         ret
  12128. ;
  12129. ; Adjust for previous end of line
  12130. ; ENTRY Reg HL holds current pointer
  12131. ; EXIT  Reg HL holds pointer to previous line
  12132. ;       Carry set if pointer below start address
  12133. ;
  12134. findprevline:
  12135.         push    bc
  12136.         ld      c,l             ; Save pointer
  12137.         ld      b,h
  12138.         ld      a,lf
  12139.         call    l3bee           ; Fix to start of line
  12140.         jr      c,l41e7         ; Below
  12141. l41da:
  12142.         call    l3bee           ; Fix to start of line
  12143.         jr      z,l41e5         ; Got start
  12144.         jr      c,l41e7         ; It's below start
  12145.         cp      (hl)            ; Find line feed
  12146.         jr      nz,l41da        ; Nope
  12147.         inc     hl
  12148. l41e5:
  12149.         pop     bc
  12150.         ret
  12151. l41e7:
  12152.         ld      h,b             ; Restore pointer
  12153.         ld      l,c
  12154.         pop     bc
  12155.         ret
  12156. ;
  12157. ; Adjust pointer for inserting one character
  12158. ;
  12159. l41eb:
  12160.         push    hl
  12161.         ld      bc,1
  12162.         call    l414c           ; Adjust pointer for inserting one character
  12163.         ld      de,l7b74+_LinLen-1
  12164.         ex      de,hl
  12165.         or      a
  12166.         sbc     hl,de           ; Get difference
  12167.         dec     hl
  12168.         ld      c,l
  12169.         ld      b,h
  12170.         ld      de,l7b74+_LinLen-2
  12171.         ld      l,e
  12172.         ld      h,d
  12173.         dec     hl
  12174.         ld      a,c
  12175.         or      b               ; Test any
  12176.         jr      z,l420c         ; Nope
  12177.         push    de
  12178.         lddr                    ; move characters
  12179.         pop     hl
  12180.         ld      (hl),' '        ; Clear character
  12181. l420c:
  12182.         pop     hl
  12183.         ret
  12184. ;
  12185. ; Position cursor and give immediate string
  12186. ; ENTRY Reg H holds column
  12187. ;       Reg L holds row
  12188. ;
  12189. l420e:
  12190.         call    l02a2           ; Position cursor
  12191. l4211:
  12192.         jp      l01fa           ; Give string
  12193. ;
  12194. ; #####################################################
  12195. ; >>> Redirected console output during edit session <<<
  12196. ; #####################################################
  12197. ;
  12198. l4214:
  12199.         pop     hl
  12200.         ex      (sp),hl
  12201.         bit     0,(iy+7)
  12202.         jr      z,l4220
  12203.         push    hl
  12204. l421e   equ     $+1
  12205.         call    a_DUMMY         ; *** REDIRECTED ***
  12206. l4220:
  12207.         ld      a,(l4543)
  12208.         sub     2
  12209.         ld      (l4543),a
  12210.         ret     nz
  12211.         jr      l423e           ; Poll character from input
  12212. ;
  12213. ; Clear look ahead buffer
  12214. ;
  12215. l422b:
  12216.         ld      hl,(l445c)      ; Get input queue pointer
  12217.         ld      (l445e),hl      ; Set for output queue pointer
  12218.         ret
  12219. ;
  12220. ; Poll character from input
  12221. ;
  12222. l4232:
  12223.         push    af
  12224.         push    bc
  12225.         push    de
  12226.         push    hl
  12227.         call    l423e           ; Poll character from input
  12228.         pop     hl
  12229.         pop     de
  12230.         pop     bc
  12231.         pop     af
  12232.         ret
  12233. ;
  12234. ; Poll character from input without register preserving
  12235. ;
  12236. l423e:
  12237.         ld      hl,(l445e)      ; Get output queue pointer
  12238.         call    l4263           ; Bump it
  12239.         ld      de,(l445c)      ; Get input queue pointer
  12240.         ex      de,hl
  12241.         sbc     hl,de           ; Test room in output queue
  12242.         ex      de,hl
  12243.         ret     z               ; Nope
  12244.         push    hl
  12245.         push    ix
  12246.         push    iy
  12247.         YIELD
  12248.         GET_KEY ;call   l00a0           ; Test key pressed
  12249.         pop     iy
  12250.         pop     ix
  12251.         pop     hl
  12252.          or a
  12253.         ret     z               ; No character available
  12254.         ;call   readfromkbd             ; Read character
  12255.         ld      (hl),a          ; Store it
  12256.         ld      (l445e),hl      ; Set output queue pointer
  12257.         ret
  12258. ;
  12259. ; Bump and check ahead pointer
  12260. ; ENTRY Reg HL holds current pointer
  12261. ; EXIT  Reg HL holds position within the queue
  12262. ;
  12263. l4263:
  12264.         inc     hl              ; Bump pointer
  12265.         ld      de,l7b59+_Ahead
  12266.         or      a
  12267.         ex      de,hl
  12268.         sbc     hl,de           ; Test end of queue
  12269.         ex      de,hl
  12270.         ret     nz              ; Nope
  12271.         ld      hl,l7b59        ; Set start of queue
  12272.         ret
  12273. ;
  12274. ; Get character from console or ahead buffer
  12275. ;
  12276. l4271:
  12277.         push    hl
  12278.         push    de
  12279.         ld      de,(l445c)      ; Get input queue pointer
  12280.         ld      hl,(l445e)      ; Get output queue pointer
  12281.         or      a
  12282.         sbc     hl,de           ; Test any in buffer
  12283.         ex      de,hl
  12284.         jr      z,l4289         ; Nope, buffer is empty
  12285.         call    l4263           ; Bump queue pointer
  12286.         ld      a,(hl)          ; Get character
  12287.         ld      (l445c),hl      ; Set input queue pointer
  12288.         jr      l428c
  12289. l4289:
  12290.         call    readfromkbd             ; Read character
  12291. l428c:
  12292.         pop     de
  12293.         pop     hl
  12294.         ret
  12295. ;
  12296. ; Test look ahead buffer empty - Z set says yes
  12297. ;
  12298. l428f:
  12299.         push    hl
  12300.         push    de
  12301.         ld      de,(l445c)      ; Get input queue pointer
  12302.         ld      hl,(l445e)      ; Get output queue pointer
  12303.         or      a
  12304.         sbc     hl,de
  12305.         pop     de
  12306.         pop     hl
  12307.         ret
  12308. ;
  12309. l429e:
  12310.         dw      l7bf5           ; Base of message file
  12311. l42a0:
  12312.         db      eof
  12313.        
  12314.         if 1==0
  12315. ;default key codes
  12316. l42a1::
  12317. ; Basic movement
  12318.         db      1,0dh
  12319.         db      1,1
  12320.         db      1,0ffh
  12321.         db      1,6
  12322.         db      1,0fah
  12323.         db      1,0fbh
  12324.         db      1,1fh
  12325.         db      1,1eh
  12326.         db      1,0f5h
  12327.         db      1,0f4h
  12328.         db      1,0f8h
  12329.         db      1,0f9h
  12330. ; Extended movement
  12331.         db      1,0f6h
  12332.         db      1,0f7h
  12333.         db      1,0ffh
  12334.         db      1,0ffh
  12335.         db      1,0ffh
  12336.         db      1,0ffh
  12337.         db      1,0ffh
  12338.         db      1,0ffh
  12339.         db      1,0ffh
  12340. ; Insert and delete commands
  12341.         db      1,0e0h
  12342.         db      1,0ffh
  12343.         db      1,0ffh
  12344.         db      1,0ffh
  12345.         db      1,0ffh
  12346.         db      1,0ffh
  12347.         db      1,0ffh
  12348.         db      1,0ffh
  12349. ; Block commands
  12350.         db      1,0ffh
  12351.         db      1,0ffh
  12352.         db      1,0ffh
  12353.         db      1,0ffh
  12354.         db      1,0ffh
  12355.         db      1,0ffh
  12356.         db      1,0ffh
  12357.         db      1,0ffh
  12358.         db      1,0ffh
  12359. ; More commands
  12360.         db      1,0ffh
  12361.         db      1,0ffh
  12362.         db      1,0ffh
  12363.         db      1,0ffh
  12364.         db      1,0ffh
  12365.         db      1,0ffh
  12366.         db      1,0ffh
  12367.         db      1,0ffh
  12368. ;
  12369.         db      0,0ffh
  12370.         db      1,0ffh
  12371. ;
  12372.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12373.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12374.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12375.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12376.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12377.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12378.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12379.         db      0,0,0,0,0,0
  12380.         endif
  12381. l4369::
  12382. ;
  12383. ; Basic movement
  12384. ;
  12385.         db      1,'M'-'@'
  12386.         db      1,key_left;'S'-'@'
  12387.         db      1,key_left;'H'-'@'
  12388.         db      1,key_right;'D'-'@'
  12389.         db      1,'A'-'@'
  12390.         db      1,'F'-'@'
  12391.         db      1,key_up;'E'-'@'
  12392.         db      1,key_down;'X'-'@'
  12393.         db      1,'W'-'@'
  12394.         db      1,'Z'-'@'
  12395.         db      1,key_pgup;'R'-'@' ;pgup
  12396.         db      1,key_pgdown;'C'-'@' ;pgdn
  12397. ;
  12398. ; Extended movement
  12399. ;
  12400.         db      1,key_home;2,'Q'-'@','S'-'@' ; LINE LEFT (home)
  12401.         db      1,key_end;2,'Q'-'@','D'-'@' ; LINE RIGHT (end)
  12402.         db      2,'Q'-'@','E'-'@' ; BOTTOM OF SCREEN
  12403.         db      2,'Q'-'@','X'-'@' ; TOP OF SCREEN
  12404.         db      2,'Q'-'@','R'-'@' ; BEGIN OF TEXT
  12405.         db      2,'Q'-'@','C'-'@' ; END OF TEXT
  12406.         db      2,'Q'-'@','B'-'@' ;to begin of block
  12407.         db      2,'Q'-'@','K'-'@' ;to end of block
  12408.         db      2,'Q'-'@','P'-'@' ;last cursor position
  12409. ;
  12410. ; Insert and delete commands
  12411. ;
  12412.         db      1,key_ins;'V'-'@' ;insert mode on/off
  12413.         db      1,'N'-'@' ;insert line
  12414.         db      1,'Y'-'@' ;delete line
  12415.         db      2,'Q'-'@','Y'-'@' ;delete to end of line
  12416.         db      1,'T'-'@' ;delete right word
  12417.         db      1,key_del;'G'-'@'
  12418.         db      1,key_backspace;DEL
  12419.         db      1,key_backspace;0ffh
  12420. ;
  12421. ; Block commands
  12422. ;
  12423.         db      2,'K'-'@','B'-'@'
  12424.         db      2,'K'-'@','K'-'@'
  12425.         db      2,'K'-'@','T'-'@'
  12426.         db      2,'K'-'@','H'-'@'
  12427.         db      2,'K'-'@','C'-'@'
  12428.         db      2,'K'-'@','V'-'@'
  12429.         db      2,'K'-'@','Y'-'@'
  12430.         db      2,'K'-'@','R'-'@'
  12431.         db      2,'K'-'@','W'-'@'
  12432. ;
  12433. ; More commands
  12434. ;
  12435.         db 1,key_esc;db 2,'K'-'@','D'-'@'
  12436.         db      1,'I'-'@'
  12437.         db      2,'Q'-'@','I'-'@'
  12438.         db      2,'Q'-'@','L'-'@'
  12439.         db      2,'Q'-'@','F'-'@'
  12440.         db      2,'Q'-'@','A'-'@'
  12441.         db      1,'L'-'@'
  12442.         db      1,'P'-'@'
  12443.         db      0
  12444. l43de::
  12445.         db      '<>,[].*+-/$:=(){}^#'''
  12446. l43f2::
  12447.         db      ' ',null
  12448. l43f4::
  12449. ;
  12450. ; Basic movement
  12451. ;
  12452.         dw      l38e6           ; NEW LINE
  12453.         dw      l3984           ; CURSOR LEFT
  12454.         dw      l3984           ; CURSOR LEFT
  12455.         dw      l3991           ; CURSOR RIGHT
  12456.         dw      l39ea           ; WORD LEFT
  12457.         dw      l3a0b           ; WORD RIGHT
  12458.         dw      l37d2           ; LINE UP
  12459.         dw      l37ad           ; LINE DOWN
  12460.         dw      l37e0           ; SCROLL UP
  12461.         dw      l3822           ; SCROLL DOWN
  12462.         dw      l389c           ; PAGE UP
  12463.         dw      l3872           ; PAGE DOWN
  12464. ;
  12465. ; Extended movement
  12466. ;
  12467.         dw      l3771           ; LINE LEFT (home)
  12468.         dw      l377a           ; LINE RIGHT (end)
  12469.         dw      l384d           ; BOTTOM OF SCREEN
  12470.         dw      l385f           ; TOP OF SCREEN
  12471.         dw      l38bc           ; BEGIN OF TEXT
  12472.         dw      l3768           ; END OF TEXT
  12473.         dw      l373c           ; BEGIN OF BLOCK
  12474.         dw      l3745           ; END OF BLOCK
  12475.         dw      l399a           ; LAST CURSOR POSITION
  12476. ;
  12477. ; Insert and delete commands
  12478. ;
  12479.         dw      l378f           ; TOGGLE INSERT/OVERWRITE
  12480.         dw      MMSB+l393b      ; INSERT LINE
  12481.         dw      MMSB+l3aec      ; DELETE LINE
  12482.         dw      MMSB+l3ad2      ; DELETE TO END OF LINE
  12483.         dw      MMSB+l3b42      ; DELETE RIGHT WORD
  12484.         dw      MMSB+l3b73      ; DELETE RIGHT CHARACTER
  12485.         dw      MMSB+l3b78      ; DELETE LEFT CHARACTER
  12486.         dw      MMSB+l3b78      ; DELETE LEFT CHARACTER
  12487. ;
  12488. ; Block commands
  12489. ;
  12490.         dw      l3726           ; MARK BEGIN OF BLOCK
  12491.         dw      l3702           ; MARK END OF BLOCK
  12492.         dw      l39ac           ; MARK SINGLE WORD
  12493.         dw      l36f9           ; TOGGLE BLOCK DISPLAY
  12494.         dw      MMSB+l3620      ; COPY BLOCK
  12495.         dw      MMSB+l35fb      ; MOVE BLOCK
  12496.         dw      MMSB+l36a1      ; DELETE BLOCK
  12497.         dw      MMSB+l3573      ; READ BLOCK FROM FILE
  12498.         dw      l34ed           ; WRITE BLOCK TO FILE
  12499. ;
  12500. ; More commands
  12501. ;
  12502.         dw      l2b0f           ; EXIT EDITOR
  12503.         dw      MMSB+l3a72      ; TABULATE
  12504.         dw      l379b           ; TOGGLE TABULATE
  12505.         dw      MMSB+l3d2c      ; RESTORE DELETED LINE
  12506.         dw      l31f1           ; FIND STRING
  12507.         dw      l323b           ; FIND AND REPLACE STRING
  12508.         dw      l324b           ; REPEAT LAST SEARCH
  12509.         dw      MMSB+l2f02      ; CONTROL PREFIX
  12510. l4450::
  12511.         dw      0               ; Current memory pointer
  12512. l4452:
  12513.         dw      l7b74           ; Current edit pointer
  12514. l4454:
  12515.         dw      0               ; Block pointer
  12516. l4456:
  12517.         dw      l7b74
  12518. l4458:
  12519.         dw      0               ; Edit pointer
  12520. l445a:
  12521.         dw      l7b74
  12522. l445c:
  12523.         dw      l7b59           ; Input queue pointer
  12524. l445e:
  12525.         dw      l7b59           ; Output queue pointer
  12526. l4460:
  12527.         dw      0               ; Block start pointer
  12528. l4462:
  12529.         dw      0               ; Block end pointer
  12530. l4464:
  12531.         dw      2               ; Block start pointer
  12532. l4466:
  12533.         dw      2               ; Block end pointer
  12534. l4468:
  12535.         dw      0               ; Temporry edit pointer
  12536. curstartofpage:
  12537.         dw      0               ; Start of screen
  12538. ;
  12539. ; The editor status block
  12540. ;
  12541. l446c:
  12542.         db      0               ; + 0 xscroll???
  12543.         db      0               ; + 1: Block state
  12544.                                 ; xxxxxxx1: Start set)
  12545.                                 ; xxxxxx1x: End set)
  12546.         db      1               ; + 2
  12547. l446f:
  12548.         db      1               ; + 3: Relative column
  12549. l4470:
  12550.         db      0               ; + 4: Editor column
  12551. l4471:
  12552.         db      1               ; + 5: Editor row
  12553. l4472:
  12554.         db      0               ; + 6: Insert flag (Bit 0=0)
  12555.         db      1               ; + 7: Video flag (1 is reverse)
  12556. l4474:
  12557.         db      0               ; + 8: Change flag
  12558. l4475:
  12559.         db      1               ; + 9: Editor row
  12560. l4476:
  12561.         db      0               ; +10
  12562.         db      0               ; +11
  12563. l4478:
  12564.         db      0               ; +12
  12565. l4479:
  12566.         db      0               ; +13: Auto tabulate flag
  12567.         db      1               ; +14
  12568.         db      1               ; +15
  12569.         db      0               ; +16
  12570. l447d:
  12571.         db      0               ; +17: Option flags for search/replace
  12572.                                 ; 00000001: W: Whole word search
  12573.                                 ; 00000010: N: No request
  12574.                                 ; 00000100: U: Ignore case
  12575.                                 ; 00001000: G: Global search
  12576.                                 ; 00010000: B: Backwards
  12577. l447e:
  12578.         db      0               ; +18: Find (0) or replace (-1) flag
  12579. l447f:
  12580.         db      0               ; +19: Text change flag
  12581. l4480:
  12582.         db      0               ; +20: Block marker (1: Not set)
  12583.         db      0               ; +21
  12584. l4482:
  12585.         db      3               ; +22
  12586. l4483:
  12587.         db      0,0,0
  12588. l4486:
  12589.         db      0,0
  12590. l4488:
  12591.         dw      0               ; End of search pointer
  12592. l448a:
  12593.         dw      0               ; Search loop count
  12594. l448c:
  12595.         dw      0
  12596. l448e:
  12597.         dw      0
  12598. ;
  12599. ; Search buffer
  12600. ;
  12601. l4490:
  12602.         db      1eh
  12603. l4491:
  12604.         db      0
  12605. l4492:
  12606.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12607.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12608.         db      0,0,0
  12609. ;
  12610. ; Replace buffer
  12611. ;
  12612. l44b1:
  12613.         db      1eh
  12614. l44b2:
  12615.         db      0
  12616. l44b3:
  12617.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12618.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12619.         db      0,0,0
  12620. ;
  12621. ; Option buffer
  12622. ;
  12623. l44d2:
  12624.         db      0ah
  12625.         db      0,0,0,0,0,0,0,0,0,0,0,0
  12626. ;
  12627. ; Block file name
  12628. ;
  12629. l44df:
  12630.         db      0fh
  12631.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12632. l44f1:
  12633.         db      0               ; File flag
  12634. l44f2:
  12635.         db      0               ; Rename flag (1 is rename)
  12636. l44f3:
  12637.         db      1               ; Compile flag:
  12638.                                 ; 1: Compile to memory
  12639.                                 ; 2: Compile to COM-file
  12640.                                 ; 3: Compile to CHN-file
  12641. l44f4:
  12642.         dw      l20e2           ; Start address of compiler
  12643. l44f6:
  12644.         dw      0               ; Top of available memory
  12645. l44f8:
  12646.         db      0               ; Logged disk
  12647. l44f9:
  12648.         ds      FCBlen          ; Main file
  12649. l451d:
  12650.         ds      FCBlen
  12651. l4541:
  12652.         db      0               ; Error message file flag (0 is not read)
  12653. l4542:
  12654.         db      0               ; Compile flag
  12655. l4543:
  12656.         db      0
  12657. l4544:
  12658.         dw      l7bf5           ; Start of text
  12659. l4546:
  12660.         dw      l7bf5           ; End of text
  12661. l4548:
  12662.         dw      0               ; Top of available memory
  12663. ;
  12664. ; %%%%%%%%%%%%%%%%%%%%%%
  12665. ; %%% COMPILER ENTRY %%%
  12666. ; %%%%%%%%%%%%%%%%%%%%%%
  12667. ;
  12668. l454a:
  12669.         ld      (l7b71),sp      ; Save stack
  12670.         ld      hl,(l4546)      ; Get end of text
  12671.         inc     hl
  12672.         ld      (l7bdf),hl      ; Save for memory top
  12673.         inc     h               ; Allow a gap of 1024 bytes
  12674.         inc     h
  12675.         inc     h
  12676.         inc     h
  12677.         ld      (l7be1),hl      ; Save for top of .COM file
  12678.         ld      hl,(l790a)      ; Get end of code
  12679.         ld      (l7908),hl      ; Save for start of data
  12680.         xor     a
  12681.         ld      h,a
  12682.         ld      l,a
  12683.         ld      (l7b91),a       ; Clear ????
  12684.         ld      (l7b92),a       ; Clear ????
  12685.         ld      (l7b94),a       ; Clear ????
  12686.         ld      (l7ba2),a       ; Clear end of file
  12687.         ld      (l7ba0),a       ; Clear end on break [option U+]
  12688.         ld      (l7be3),a       ; Clear back fix level
  12689.         ld      (l790e),a       ; Enable memory read
  12690.         ld      (l7b96),a       ; Clear OVERLAY number
  12691.         ld      (l7bdb),a       ; Clear file access
  12692.         ld      (l7bdd),hl      ; Clear record base
  12693.         ld      (l7bef),hl      ; Clear line count
  12694.         call    l718f           ; Test abort
  12695.         dec     hl
  12696.         ld      (l7933+_rrn),hl ; Set highest record
  12697.         ld      a,_Char+1 ;13=element of a set???
  12698.         ld      (curtype_l7b93),a       ; Set special type
  12699.         ld      a,0xff-(__Ropt+__Uopt)
  12700.         ld      (l7b9d),a       ; Set default options
  12701.         ld      a,2*DefWITH
  12702.         ld      (l7bc7),a       ; Set depth for WITH
  12703.         ld      hl,(l4544)      ; Get start of text
  12704.         ld      (l7bd7),hl      ; Init source pointer
  12705.         ld      (l7bd9),hl
  12706.         ld      ix,l79d7        ; Init start of line
  12707.         ld      (ix+0),null     ; Set line empty
  12708.         ld      hl,(l7904)      ; Get code start address
  12709.         call    l6cc2           ; Check chaining
  12710.         ld      hl,(l4548)      ; Get top of available memory
  12711.         dec     hl
  12712.         ld      (l7b77),hl      ; Save
  12713.         ld      d,h
  12714.         ld      e,l
  12715.         ld      bc,LenLab       ; Get length of internal table
  12716.         or      a
  12717.         sbc     hl,bc
  12718.         ld      (l7b73),hl      ; Init label pointers
  12719.         ld      (l7b75),hl
  12720.         ld      (l7b7b),hl
  12721.         call    l6bc7           ; Check enough memory
  12722.         ld      hl,l731f+LenLab-1
  12723.         lddr                    ; Unpack symbol table
  12724.         call    l45ea           ; Go compile
  12725.         ld      a,(l7900)       ; Get compile flag
  12726.         dec     a               ; Test compiling to file
  12727.         jr      nz,l45e2        ; Nope
  12728.         call    l6c96           ; Fix back level
  12729.         call    writerecord_l7957               ; Write record
  12730. l45e2:
  12731.         ld      (l7906),iy      ; Save new top of code
  12732.         xor     a
  12733.         jp      l72e3           ; Set special zero error
  12734. ;
  12735. ; Do the compiler task
  12736. ;
  12737. l45ea:
  12738.         call    l6f95           ; Process line
  12739.         call    l6e76           ; Find PROGRAM
  12740.         dw      l7529
  12741.         jr      nz,l460a        ; Nope
  12742.         call    l4692           ; Build dummy label
  12743.         call    l6f1b           ; Test (
  12744.         jr      nz,l4607        ; Nope
  12745. l45fc:
  12746.         call    l4692           ; Build dummy label
  12747.         call    l6f13           ; Test ,
  12748.         jr      z,l45fc         ; Yeap, get next dummy
  12749.         call    l6f6e           ; Verify )
  12750. l4607:
  12751.         call    l6f48           ; Verify ;
  12752. l460a:
  12753.         ld      a,_LD.SP
  12754.         ld      hl,0x0100;TPA
  12755.         call    l6b94           ; Set LD SP,TPA
  12756.         ld      hl,l79d7        ; Get start of source line
  12757.         ld      a,(l7900)       ; Get compile flag
  12758.         or      a               ; Test compile to memory
  12759.         jr      z,l4621         ; Yeap
  12760.         ld      de,l0080
  12761.         call    l6c30           ; Allow space for loader
  12762. l4621:
  12763.         call    l6b92           ; Set LD HL,L79D7
  12764.         ld      a,(l7b9d)       ; Get options
  12765.         bit     _Copt,a         ; Test $C+
  12766.         ld      d,0
  12767.         jr      z,l462e         ; Nope
  12768.         dec     d
  12769. l462e:
  12770.         push    de              ; Save flag
  12771.         ld      a,_LD.BC
  12772.         call    writebyte_a_addriy              ; Set LD BC,FLAG
  12773.         push    iy              ; Save PC
  12774.         call    writeword_hl_addriy             ; Set dummy word
  12775.         ld      hl,l0364
  12776.         call    l6b86           ; Set CALL INIPRG
  12777.         ld      a,_LD.HL
  12778.         call    writebyte_a_addriy              ; Set LD HL,1STFREE
  12779.         push    iy              ; Save PC
  12780.         call    writeword_hl_addriy             ; Set dummy word
  12781.         ld      a,_LD.DE
  12782.         call    writebyte_a_addriy              ; Set LD DE,LASTFREE
  12783.         push    iy              ; Save PC
  12784.         call    writeword_hl_addriy             ; Set dummy word
  12785.         ld      hl,(l790a)      ; Get end of code
  12786.         call    l6b8a           ; Set LD BC,TOPRAM
  12787.         ld      a,(l7900)       ; Get compile flag
  12788.         ld      h,a
  12789.         ld      l,_LD.A
  12790.         call    writeword_hl_addriy             ; Set LD A,FLAG
  12791.         ld      hl,l04d4
  12792.         call    l6b86           ; Set CALL RANGCHK
  12793.         call    l469e           ; Do a block
  12794.         call    l52fc
  12795.         ld      a,(ix+0)
  12796.         cp      '.'             ; Verify closing .
  12797.         call    l72da
  12798.         db      _DotExp
  12799.         ld      hl,l20d4
  12800.         call    l6b82           ; Set JP HALT
  12801.         pop     hl              ; Get back PC for LASTFREE
  12802.         ld      de,(l7908)      ; Get start of data
  12803.         call    storeback_de_to_addrhl          ; Store back
  12804.         pop     hl              ; Get back PC for 1STFREE
  12805.         call    storeback_iy_to_addrhl          ; Store back current PC
  12806.         pop     hl              ; Get back PC for FLAG
  12807.         pop     de              ; Get FLAG
  12808.         ld      a,(l7ba0)       ; Get end on break flag [option U+]
  12809.         ld      e,a
  12810.         jp      storeback_de_to_addrhl          ; Store it back
  12811. ;
  12812. ; Build dummy label
  12813. ;
  12814. l4692:
  12815.         ld      hl,(l7b73)      ; Get label pointer
  12816.         push    hl              ; Save it
  12817.         call    l6d87           ; Get label
  12818.         pop     hl
  12819.         ld      (l7b73),hl      ; Restore label pointer
  12820.         ret
  12821. ;
  12822. ; Perform a block
  12823. ;
  12824. l469e:
  12825.         ld      a,(l7bc7)       ; Get depth for WITH
  12826.         push    af
  12827.         add     a,a             ; Double it
  12828.         ld      e,a
  12829.         ld      d,0
  12830.         call    l6c30           ; Allocate space for it
  12831.         push    hl
  12832.         call    l6b77           ; Set JP
  12833.         push    iy              ; Save PC
  12834.         push    hl
  12835.         call    writeword_hl_addriy             ; Set dummy word
  12836. l46b3:
  12837.         call    l6e5a           ; Find statement
  12838.         db      _Byte
  12839.         dw      l7584
  12840.         call    l72da           ; Must be
  12841.         db      _BEGINexp
  12842.         ld      a,(hl)          ; Get type
  12843. l46be:
  12844.         cp      _Label          ; Test LABEL
  12845.         jr      nz,l46c7        ; Nope
  12846.         call    l488e           ; Process it
  12847.         jr      l46b3
  12848. l46c7:
  12849.         cp      _Const          ; Test CONST
  12850.         jr      nz,l46d0        ; Nope
  12851.         call    l48b7           ; Process it
  12852.         jr      l46be
  12853. l46d0:
  12854.         cp      _Type           ; Test TYPE
  12855.         jr      nz,l46d9        ; Nope
  12856.         call    l4aeb           ; Process it
  12857.         jr      l46be
  12858. l46d9:
  12859.         cp      _Var            ; Test VAR
  12860.         jr      nz,l46e6        ; Nope
  12861.         call    l4b2a           ; Process it
  12862.         ld      hl,(l7908)      ; Get start of data
  12863.         ex      (sp),hl
  12864.         jr      l46be
  12865. l46e6:
  12866.         cp      _Overly         ; Test OVERLAY
  12867.         jp      nz,l485e
  12868.         ld      a,(l7900)       ; Get compile flag
  12869.         or      a
  12870.         call    l72d4           ; Must not be compiled to memory
  12871.         db      _OvlDirErr
  12872.         ld      hl,l7933+Fdrv
  12873.         ld      de,l7bb2
  12874.         ld      bc,Fname
  12875.         ldir                    ; Copy name of file
  12876.         ld      hl,l7b96        ; Point to OVERLAY number
  12877.         ld      a,(hl)          ; Get current number
  12878.         inc     (hl)            ; Advance it
  12879.         ex      de,hl           ; Get pointer to extension
  12880.         ld      (hl),'0'        ; Init extension
  12881.         inc     hl
  12882.         ld      b,'0'-1         ; Init tens
  12883. l4709:
  12884.         inc     b               ; Divide by ten
  12885.         sub     10
  12886.         jr      nc,l4709
  12887.         ld      (hl),b          ; Save tens
  12888.         inc     hl
  12889.         add     a,'9'+1         ; Calculate units
  12890.         ld      (hl),a          ; Save it
  12891.         ld      hl,l1c59
  12892.         call    l6b86           ; Set CALL OVERLAY
  12893.         ld      hl,-1
  12894.         call    writeword_hl_addriy             ; Save word
  12895.         ld      hl,l7bb2        ; Point to name
  12896.         ld      b,Fname+Fext
  12897. l4724:
  12898.         ld      a,(hl)
  12899.         call    writebyte_a_addriy              ; Store name and extension
  12900.         inc     hl
  12901.         djnz    l4724
  12902.         ld      a,(l7900)       ; Get compile flag
  12903.         dec     a               ; Test compiling to file
  12904.         jr      nz,l473b        ; Nope
  12905.         call    l6c96           ; Fix back level
  12906.         xor     a
  12907.         ld      (l7be3),a       ; Set back fix level
  12908.         call    writerecord_l7957               ; Write record
  12909. l473b:
  12910.         ld      hl,(l7bdd)      ; Get record base
  12911.         push    hl
  12912.         ld      hl,(l7902)      ; Get code pointer
  12913.         push    hl
  12914.         ld      hl,(l7bb0)      ; Get length of overlay
  12915.         push    hl
  12916.         ld      (l7902),iy      ; Set code pointer
  12917.         ld      hl,0
  12918.         ld      (l7bb0),hl      ; Clear length of overlay
  12919.         ld      hl,-FCBlen
  12920.         add     hl,sp           ; Let some space on stack for FCB
  12921.         ld      sp,hl
  12922.         ex      de,hl
  12923.         ld      hl,l7933
  12924.         ld      bc,FCBlen
  12925.         ldir                    ; Unpack current FCB
  12926.         ld      a,(l7900)       ; Get compile flag
  12927.         dec     a               ; Test compiling to file
  12928.         jr      nz,l478c        ; Nope
  12929.         ld      hl,l7bb2
  12930.         ld      de,l7933+Fdrv
  12931.         ld      bc,Fname+Fext
  12932.         ldir                    ; Copy overlay FCB to .COM FCB
  12933.         ex      de,hl
  12934.         ld      b,FCBlen-Fdrv-Fname-Fext
  12935. l4773:
  12936.         ld      (hl),0          ; Clear remainder of FCB
  12937.         inc     hl
  12938.         djnz    l4773
  12939.         ld      de,l7933
  12940.         push    de
  12941.         ld      c,_delete
  12942.         call    l7265           ; Delete file
  12943.         pop     de
  12944.         ld      c,_make
  12945.         call    l7265           ; Create new one
  12946.         inc     a
  12947.         call    l72d4           ; Must be success
  12948.         db      _NoOvl
  12949. l478c:
  12950.         xor     a
  12951.         ld      (l7bdb),a       ; Clear file access
  12952.         ld      (l7bdc),a       ; Clear record pointer
  12953.         ld      hl,(l7908)      ; Get start of data
  12954.         ld      (l7bab),hl      ; Set for overlay
  12955. l4799:
  12956.         call    l6e5a           ; Find PROCEDURE or FUNCTION
  12957.         db      1
  12958.         dw      l75a7
  12959.         call    l72da           ; Must be either
  12960.         db      _SUBexp
  12961.         ld      a,(hl)          ; Get type
  12962.         push    iy
  12963.         ld      hl,(l7933+_rrn) ; Get current record
  12964.         ld      (l7bdd),hl      ; Set record base
  12965.         ld      hl,(l7908)      ; Get start of data
  12966.         push    hl
  12967.         ld      hl,(l7bab)      ; Get address of overlay data
  12968.         push    hl
  12969.         ld      e,-1
  12970.         call    l4b3a           ; Perform PROCEDURE/FUNCTION
  12971.         ld      b,h
  12972.         ld      c,l
  12973.         pop     de              ; Get back overlay data
  12974.         ld      hl,(l7908)      ; Get start of data
  12975.         or      a
  12976.         sbc     hl,de           ; Test min
  12977.         add     hl,de
  12978.         jr      c,l47c6
  12979.         ex      de,hl           ; Swap addresses
  12980. l47c6:
  12981.         ld      (l7bab),hl      ; Set address of overlay data
  12982.         pop     hl
  12983.         ld      (l7908),hl      ; Set start of data
  12984.         pop     de
  12985.         push    bc
  12986.         push    de
  12987.         ld      a,(l7900)       ; Get compile flag
  12988.         dec     a               ; Test compiling to file
  12989.         call    z,l6c96         ; Yeap, fix back level
  12990.         xor     a
  12991.         ld      (l7be3),a       ; Reset back fix level
  12992.         pop     de
  12993.         push    de
  12994. l47dd:
  12995.          ld     a,(l7900)       ; Get compile flag
  12996.          dec    a               ; Test compiling to memory
  12997.          call z,flushunfinished ;nope
  12998.         push    iy              ; Copy code pointer
  12999.         pop     hl
  13000.         or      a
  13001.         sbc     hl,de           ; Get difference
  13002.         ld      a,l
  13003.         and     RecLng-1        ; Test record boundary
  13004.         jr      z,l47ee         ; Yeap
  13005.         xor     a
  13006.         call    writebyte_a_addriy              ; Fill remainder with zeroes
  13007.         jr      l47dd
  13008. l47ee:
  13009.         add     hl,hl           ; Calculate lenght in bytes
  13010.         ld      e,h
  13011.         ld      d,0
  13012.         rl      d
  13013.         ld      hl,(l7bb0)      ; Get length of overlay
  13014.         sbc     hl,de           ; Test max
  13015.         jr      nc,l47ff
  13016.         ld      (l7bb0),de      ; Set new length
  13017. l47ff:
  13018.         pop     iy              ; Get back PC
  13019.         pop     hl
  13020.         inc     hl
  13021.         ld      (hl),e          ; Save record
  13022.         inc     hl
  13023.         ld      (hl),d
  13024.         call    l6e76           ; Find more OVERLAY
  13025.         dw      l759f
  13026.         jr      z,l4799         ; Yeap
  13027.         ld      hl,(l7bab)      ; Get address of overlay data
  13028.         ld      (l7908),hl      ; Set start of data
  13029.         ld      a,(l7900)       ; Get compile flag
  13030.         dec     a               ; Test compiling to file
  13031.         jr      nz,l4821        ; Nope
  13032.         ld      de,l7933
  13033.         ld      c,_close
  13034.         call    l7265           ; Close file
  13035. l4821:
  13036.         ld      hl,0
  13037.         add     hl,sp           ; Copy stack
  13038.         ld      de,l7933
  13039.         ld      bc,FCBlen
  13040.         ldir                    ; Get back original .COM FCB
  13041.         ld      sp,hl
  13042.         ld      de,(l7bb0)      ; Get length of overlay
  13043.         pop     hl
  13044.         ld      (l7bb0),hl      ; Set new length
  13045.         pop     hl
  13046.         ld      (l7902),hl      ; Set code pointer
  13047.         pop     hl
  13048.         ld      (l7bdd),hl      ; Set record base
  13049.         xor     a
  13050.         ld      (l7bdb),a       ; Clear file access
  13051.         ld      hl,-1
  13052.         ld      (l7933+_rrn),hl ; Set highest record number
  13053.         push    iy
  13054.         pop     hl
  13055.         call    l6cc2           ; Check chaining
  13056. l484e:
  13057.         ld      b,RecLng
  13058. l4850:
  13059.         xor     a
  13060.         call    writebyte_a_addriy              ; Clear record
  13061.         djnz    l4850
  13062.         dec     de
  13063.         ld      a,d             ; Test all done
  13064.         or      e
  13065.         jr      nz,l484e
  13066.         jp      l46b3
  13067. l485e:
  13068.         cp      _Begin          ; Test BEGIN
  13069.         jr      z,l486a         ; Yeap
  13070.         ld      e,0
  13071.         call    l4b3a           ; Perform PROCEDURE/FUNCTION
  13072.         jp      l46b3
  13073. l486a:
  13074.         call    l4e8a           ; Process it
  13075.         pop     de
  13076.         pop     hl
  13077.         push    de
  13078.         push    iy              ; Copy PC
  13079.         pop     de
  13080.         dec     de              ; Fix it
  13081.         dec     de
  13082.         or      a
  13083.         sbc     hl,de           ; Calculate size
  13084.         add     hl,de
  13085.         jr      z,l4880
  13086.         call    storeback_iy_to_addrhl          ; Store back PC
  13087.         jr      l4884
  13088. l4880:
  13089.         dec     hl
  13090.         call    l6cc2           ; Check chaining
  13091. l4884:
  13092.         pop     de
  13093.         pop     hl
  13094.         ld      (l7bca),hl
  13095.         pop     af
  13096.         ld      (l7bc6),a
  13097.         ret
  13098. ;
  13099. ; Process LABEL
  13100. ;
  13101. l488e:
  13102.         ld      de,256*1+0
  13103.         call    puttolabel_d_e          ; Put to table
  13104.         ld      a,(ix+0)
  13105.         call    l7282           ; Test valid character
  13106.         call    l6d8d           ; Build label
  13107.         ld      a,(l7b94)       ; Get ???
  13108.         call    puttolabel              ; Put to label
  13109.         ld      b,3
  13110. l48a5:
  13111.         ld      a,-1
  13112.         call    puttolabel              ; Set end
  13113.         djnz    l48a5
  13114.         call    l6dc6           ; Set label pointer
  13115.         call    l6f13           ; Test ,
  13116.         jr      z,l488e         ; Yeap
  13117.         jp      l6f48           ; Verify ;
  13118. ;
  13119. ; Process CONST
  13120. ;
  13121. l48b7:
  13122.         ld      hl,(l7b73)      ; Get label pointer
  13123.         push    hl
  13124.         ld      de,256*0+0
  13125.         call    puttolabel_d_e          ; Put to table
  13126.         call    l6d87           ; Get label
  13127.         call    l6f23           ; Test =
  13128.         jr      nz,l4901        ; Nope, must be : then
  13129.         call    l6a0d           ; Get constant
  13130.         ld      a,b             ; Get type
  13131.         call    puttolabel              ; Store into table
  13132.         ld      a,b             ; Get back type
  13133.         cp      _Real           ; Test real
  13134.         jr      nz,l48e3        ; Nope
  13135.         exx
  13136.         push    hl              ; Save reals
  13137.         push    de
  13138.         push    bc
  13139.         ld      b,3             ; Set word count
  13140. l48db:
  13141.         pop     de              ; Get part of real
  13142.         call    puttolabel_d_e          ; Put to table
  13143.         djnz    l48db
  13144.         jr      l48fa
  13145. l48e3:
  13146.         cp      _String         ; Test string
  13147.         jr      nz,l48f6        ; Nope, must be integer
  13148.         ld      hl,l7a57        ; Get buffer
  13149.         ld      a,c             ; Get length
  13150.         inc     c               ; Fix it
  13151. l48ec:
  13152.         call    puttolabel              ; Put to table
  13153.         ld      a,(hl)
  13154.         inc     hl
  13155.         dec     c
  13156.         jr      nz,l48ec
  13157.         jr      l48fa
  13158. l48f6:
  13159.         ex      de,hl           ; Get integer
  13160.         call    puttolabel_d_e          ; Put to table
  13161. l48fa:
  13162.         call    l6dc6           ; Set label pointer
  13163.         ld      d,2
  13164.         jr      l4928
  13165. l4901:
  13166.         call    l6f40           ; Verify :
  13167.         xor     a
  13168.         call    puttolabel              ; Store zero in table
  13169.         call    puttolabel_i_y          ; Store PC to table
  13170.         ld      hl,(l7b73)      ; Get label pointer
  13171.         push    hl
  13172.         call    puttolabel_d_e          ; Put to table
  13173.         call    l6dc6           ; Set label pointer
  13174.         call    l4f9b           ; Get type
  13175.         pop     hl              ; Get back label pointer
  13176.         ld      de,(l7b5a)      ; Get type table
  13177.         ld      (hl),d          ; Store into
  13178.         dec     hl
  13179.         ld      (hl),e
  13180.         call    l6f76           ; Verify =
  13181.         call    l4937           ; Assign constant
  13182.         ld      d,4
  13183. l4928:
  13184.         pop     hl              ; Get back label pointer
  13185.         ld      (hl),d          ; Put into
  13186.         call    l6f48           ; Verify ;
  13187.         call    l6e5a           ; Find statement
  13188.         db      1
  13189.         dw      l7584
  13190.         jr      nz,l48b7        ; Nope
  13191.         ld      a,(hl)          ; Get type
  13192.         ret
  13193. ;
  13194. ; Process presetted constant
  13195. ;
  13196. l4937:
  13197.         ld      a,(l7b5c)       ; Get type
  13198.         cp      _Ptr            ; Test valid
  13199.         jr      c,l4946         ; May not be a file
  13200.         cp      _String
  13201.         jr      nc,l4946
  13202.         call    l72e1
  13203.         db      _InvFilPtr
  13204. l4946:
  13205.         cp      _Array          ; Test ARRAY constant
  13206.         jr      nz,l49a1        ; Nope
  13207.         call    l6d2a           ; Save environment
  13208.         ld      hl,(l7b60)      ; Get hi set limit
  13209.         call    l5271           ; Load name
  13210.         ld      hl,(l7b6d)      ; Get last memory address
  13211.         ld      de,(l7b6b)
  13212.         or      a
  13213.         sbc     hl,de
  13214.         inc     hl
  13215.         push    hl
  13216.         ld      hl,(l7b5e)      ; Get lo set limit
  13217.         call    l5287           ; Get name
  13218.         pop     de
  13219.         ld      a,(l7b5c)       ; Get type
  13220.         cp      _Char           ; Test character
  13221.         jr      nz,l4978
  13222.         ld      a,d             ; Test byte
  13223.         or      a
  13224.         jr      nz,l4978        ; Nope
  13225.         call    l6f1b           ; Test (
  13226.         jr      nz,l498a        ; Nope
  13227.         jr      l497b
  13228. l4978:
  13229.         call    l6f66           ; Verify (
  13230. l497b:
  13231.         push    de
  13232.         call    l4937           ; Recursive assign constant
  13233.         pop     de
  13234.         dec     de
  13235.         ld      a,d
  13236.         or      e
  13237.         jr      z,l499a
  13238.         call    l6f5e           ; Verify ,
  13239.         jr      l497b
  13240. l498a:
  13241.         push    de
  13242.         call    l69fd           ; Get string constant
  13243.         pop     de
  13244.         ld      a,c             ; Get length
  13245.         cp      e
  13246.         call    l72da           ; Verify valid length
  13247.         db      _StrConst
  13248.         call    l6b62           ; Store string
  13249.         jr      l499d
  13250. l499a:
  13251.         call    l6f6e           ; Verify )
  13252. l499d:
  13253.         call    l6d49           ; Get back environment
  13254.         ret
  13255. l49a1:
  13256.         cp      _Record         ; Test RECORD constant
  13257.         jr      nz,l49fa        ; Nope
  13258.         call    l6d2a           ; Save environment
  13259.         call    l6f66           ; Verify (
  13260.         ld      a,(l7b5d)
  13261.         ld      c,a
  13262.         ld      hl,(l7b62)      ; Get length of type
  13263.         push    hl
  13264.         ld      hl,0
  13265. l49b6:
  13266.         push    bc
  13267.         push    hl
  13268.         ld      b,_Ptr
  13269.         call    l6e54           ; Get pointer label
  13270.         call    l72da           ; Should be found
  13271.         db      _Undef
  13272.         call    l5276           ; Get values and name
  13273.         pop     de
  13274.         ld      hl,(l7b58)      ; Get value
  13275.         or      a
  13276.         sbc     hl,de
  13277.         add     hl,de
  13278.         call    l72da           ; Verify valid size
  13279.         db      _InvSetOrder
  13280.         ld      de,(l7b62)      ; Get length of type
  13281.         add     hl,de
  13282.         push    hl
  13283.         call    l6f40           ; Verify :
  13284.         call    l4937           ; Assign constant recursively
  13285.         pop     hl
  13286.         pop     bc
  13287.         call    l6f0f           ; Test ;
  13288.         jr      z,l49b6         ; Yeap
  13289.         call    l6f6e           ; Verify )
  13290.         pop     de
  13291.         ex      de,hl
  13292.         or      a
  13293.         sbc     hl,de
  13294. l49eb:
  13295.         ld      a,h             ; Test zero
  13296.         or      l
  13297.         jr      z,l49f6         ; Yeap
  13298.         xor     a
  13299.         call    writebyte_a_addriy              ; Fill zeroes
  13300.         dec     hl
  13301.         jr      l49eb
  13302. l49f6:
  13303.         call    l6d49           ; Get back environment
  13304.         ret
  13305. l49fa:
  13306.         cp      _Set            ; Test SET constant
  13307.         jr      nz,l4a7a        ; Nope
  13308.         call    l6d2a           ; Save environment
  13309.         ld      hl,(l7b62)      ; Get length of type
  13310.         ld      (l7b6f),hl
  13311.         ld      hl,(l7b5e)      ; Get lo set limit
  13312.         call    l5287           ; Get name
  13313.         call    l6f30           ; Verify [
  13314.         ld      (l7ba9),ix      ; Save line pointer
  13315.         call    l0581           ; Initialize a set on stack
  13316.         ld      ix,(l7ba9)      ; Get back line pointer
  13317.         call    l6ef7           ; Test ]
  13318.         jr      z,l4a4b         ; Yeap
  13319. l4a20:
  13320.         call    l4aca
  13321.         push    hl
  13322.         call    l6e76           ; Find ..
  13323.         dw      l7580
  13324.         jr      nz,l4a37        ; Nope
  13325.         call    l4aca
  13326.         ld      (l7ba9),ix      ; Save source pointer
  13327.         call    l059b           ; Init a contiguous set value
  13328.         jr      l4a3f
  13329. l4a37:
  13330.         pop     hl
  13331.         ld      (l7ba9),ix      ; Save source pointer
  13332.         call    l0591           ; Init one set element
  13333. l4a3f:
  13334.         ld      ix,(l7ba9)      ; Get back source pointer
  13335.         call    l6f13           ; Test ,
  13336.         jr      z,l4a20         ; Yeap
  13337.         call    l6f38           ; Verify ]
  13338. l4a4b:
  13339.         ld      hl,l7a57
  13340.         ld      bc,set.len
  13341.         ld      (l7ba9),ix      ; Save source pointer
  13342.         call    l0612           ; Assign set variable
  13343.         ld      ix,(l7ba9)      ; Get back source pointer
  13344.         ld      hl,l7a57
  13345.         ld      a,(l7b5e)       ; Get lo set limit
  13346.         rra                     ; Divide by 8
  13347.         rra
  13348.         rra
  13349.         and     set.len-1       ; Get modulo
  13350.         ld      e,a
  13351.         ld      d,0
  13352.         add     hl,de           ; Build pointer
  13353.         ld      a,(l7b6f)       ; Get length
  13354.         ld      b,a
  13355. l4a6f:
  13356.         ld      a,(hl)          ; Get bytes
  13357.         call    writebyte_a_addriy              ; Store them
  13358.         inc     hl
  13359.         djnz    l4a6f
  13360.         call    l6d49           ; Get back environment
  13361.         ret
  13362. l4a7a:
  13363.         cp      _String         ; Test STRING constant
  13364.         jr      nz,l4a99        ; Nope
  13365.         call    l69fd           ; Get string constant
  13366.         ld      a,(l7b62)       ; Get length of string
  13367.         dec     a
  13368.         sub     c
  13369.         ld      b,a
  13370.         jr      nc,l4a8d
  13371.         add     a,c
  13372.         ld      c,a             ; Set length
  13373.         ld      b,0
  13374. l4a8d:
  13375.         call    l6b5e           ; Put string
  13376.         inc     b
  13377. l4a91:
  13378.         dec     b
  13379.         ret     z
  13380.         xor     a
  13381.         call    writebyte_a_addriy              ; Fill zeroes
  13382.         jr      l4a91
  13383. l4a99:
  13384.         cp      _Real           ; Test REAL constant
  13385.         jr      nz,l4abc        ; Nope
  13386.         call    l69ea           ; Get constant
  13387.         ld      a,b             ; Get type
  13388.         cp      _Real           ; Test real
  13389.         jr      z,l4aaf         ; Yeap
  13390.         cp      _Integ          ; Test integer
  13391.         call    l72da           ; Should be
  13392.         db      _IntRealCexp
  13393.         call    l1008           ; Convert to real
  13394.         exx
  13395. l4aaf:
  13396.         exx
  13397.         push    bc
  13398.         push    de
  13399.         push    hl
  13400.         ld      b,Real.Len/2    ; Set word count
  13401. l4ab5:
  13402.         pop     hl
  13403.         call    writeword_hl_addriy             ; Save real number
  13404.         djnz    l4ab5
  13405.         ret
  13406. l4abc:
  13407.         call    l4aca
  13408.         ld      a,(l7b62)       ; Get length of type
  13409.         dec     a
  13410.         ld      a,l
  13411.         jp      z,writebyte_a_addriy            ; Set byte
  13412.         jp      writeword_hl_addriy             ; Or set word
  13413. ;
  13414. ;
  13415. ;
  13416. l4aca:
  13417.         call    l69ea           ; Get constant
  13418.         ld      a,(l7b5c)       ; Get type
  13419.         cp      b               ; Verify same types
  13420.         call    l72da
  13421.         db      _InvType
  13422.         ld      de,(l7b5e)      ; Get lo set limit
  13423.         call    l728d           ; Compare
  13424.         jr      c,l4ae7         ; Out of range
  13425.         ld      de,(l7b60)      ; Get hi set limit
  13426.         call    l728d           ; Compare
  13427.         ret     c
  13428.         ret     z
  13429. l4ae7:
  13430.         call    l72e1
  13431.         db      _ConstRange
  13432. ;
  13433. ; Process TYPE
  13434. ;
  13435. l4aeb:
  13436.         ld      hl,(l7b73)      ; Get label pointer
  13437.         push    hl
  13438. l4aef:
  13439.         ld      hl,(l7b73)      ; Get label pointer
  13440.         push    hl
  13441.         ld      de,0
  13442.         call    puttolabel_d_e          ; Put to table
  13443.         call    l6d87           ; Get label
  13444.         ld      hl,(l7b73)      ; Get label pointer
  13445.         push    hl
  13446.         call    puttolabel_d_e          ; Put to table
  13447.         call    l6dc6           ; Set label pointer
  13448.         call    l6f76           ; Verify =
  13449.         call    l4f9b           ; Get type
  13450.         pop     hl
  13451.         ld      de,(l7b5a)      ; Get type table
  13452.         ld      (hl),d          ; Store into
  13453.         dec     hl
  13454.         ld      (hl),e
  13455.         pop     hl
  13456.         ld      (hl),3
  13457.         call    l6f48           ; Verify ;
  13458.         call    l6e5a           ; Find statement
  13459.         db      _Byte
  13460.         dw      l7584
  13461.         jr      nz,l4aef        ; Nope
  13462.         ld      a,(hl)          ; Fetch type
  13463.         pop     hl
  13464.         push    af
  13465.         call    l5295
  13466.         pop     af
  13467.         ret
  13468. ;
  13469. ; Process VAR
  13470. ;
  13471. l4b2a:
  13472.         call    l4f35
  13473.         call    l6f48           ; Verify ;
  13474.         call    l6e5a           ; Find statement
  13475.         db      _Byte
  13476.         dw      l7584
  13477.         jr      nz,l4b2a        ; Nope
  13478.         ld      a,(hl)          ; Fetch type
  13479.         ret
  13480. ;
  13481. ; Perform PROCEDURE/FUNCTION
  13482. ;
  13483. ; Accu holds PROCEDURE or FUNCTION
  13484. ; Reg E holds overlay flag (-1)
  13485. ;
  13486. l4b3a:
  13487.         ld      b,a
  13488.         ld      c,0
  13489.         sub     _Proc           ; Get type
  13490.         ld      (l7b97),a       ; 0 is PROCEDURE
  13491.         ld      a,e             ; Get overlay
  13492.         ld      (l7b99),a       ; 0 is normal
  13493.         ld      a,(l7b9d)       ; Get options
  13494.         ld      (l7b9e),a       ; Set local options
  13495.         push    bc
  13496.         call    l6ddb
  13497.         jp      z,l4c61
  13498.         pop     de
  13499.         call    puttolabel_d_e          ; Put to table
  13500.         call    l6d87           ; Get label
  13501.         ld      hl,(l7b7b)      ; Get current label pointer
  13502.         push    hl
  13503.         ld      hl,(l7b75)      ; Get previous label pointer
  13504.         ld      (l7b7b),hl
  13505.         ld      hl,(l7b73)      ; Get label pointer
  13506.         push    hl
  13507.         call    puttolabel_d_e          ; Put to table
  13508.         call    puttolabel_d_e          ; Multiple
  13509.         call    puttolabel_d_e
  13510.         call    puttolabel_d_e
  13511.         ld      de,(l7bdd)      ; Get record base
  13512.         call    puttolabel_d_e          ; Put to table
  13513.         ld      de,0
  13514.         call    puttolabel_d_e          ; Put to table
  13515.         call    l6f1b           ; Test (
  13516.         ld      b,0             ; Clear parameter count
  13517.         jr      nz,l4bda        ; Nope
  13518. l4b88:
  13519.         push    bc
  13520.         ld      hl,(l7b73)      ; Get label pointer
  13521.         push    hl
  13522.         call    puttolabel_d_e          ; Put to table
  13523.         call    puttolabel_d_e          ; Twice
  13524.         call    l6e76           ; Find VAR
  13525.         dw      l7595
  13526.         ld      bc,0
  13527.         jr      nz,l4b9e        ; Nope
  13528.         dec     c               ; Indicate VAR
  13529. l4b9e:
  13530.         push    bc
  13531.         call    l6d87           ; Get label
  13532.         pop     bc
  13533.         inc     b               ; Count parameters
  13534.         call    l6f13           ; Test ,
  13535.         jr      z,l4b9e         ; Yeap
  13536.         push    bc
  13537.         call    l6f0b           ; Test :
  13538.         jr      nz,l4bb8        ; Nope
  13539.         ld      a,c
  13540.         ld      (l7b8f),a       ; Save state
  13541.         call    l4f18           ; Get variable
  13542.         jr      l4bc3
  13543. l4bb8:
  13544.         inc     c               ; Verify not VAR
  13545.         call    l72da
  13546.         db      _SemiExp
  13547.         ld      hl,l750b+7
  13548.         ld      (l7b5a),hl      ; Init type table
  13549. l4bc3:
  13550.         pop     bc
  13551.         pop     hl
  13552.         ld      (hl),b
  13553.         dec     hl
  13554.         ld      (hl),c
  13555.         ld      de,(l7b5a)      ; Get type table
  13556.         dec     hl
  13557.         ld      (hl),d          ; Store into
  13558.         dec     hl
  13559.         ld      (hl),e
  13560.         pop     bc
  13561.         inc     b
  13562.         call    l6f0f           ; Test ;
  13563.         jr      z,l4b88         ; Yeap
  13564.         call    l6f6e           ; Verify )
  13565. l4bda:
  13566.         push    bc
  13567.         ld      a,(l7b97)
  13568.         or      a               ; Test PROCEDURE
  13569.         jr      z,l4c07         ; Yeap
  13570.         call    l6f40           ; Verify :
  13571.         xor     a
  13572.         ld      (l7b8f),a
  13573.         call    l4f18           ; Get variable
  13574.         ld      a,(l7b5c)       ; Get type
  13575.         cp      _String         ; Test range
  13576.         jr      nc,l4bf8
  13577.         cp      _Ptr            ; Should be pointer
  13578.         call    l72da
  13579.         db      _InvResult
  13580. l4bf8:
  13581.         pop     bc
  13582.         pop     hl
  13583.         push    hl
  13584.         push    bc
  13585.         ld      de,-4
  13586.         add     hl,de           ; Fix pointer
  13587.         ld      de,(l7b5a)      ; Get type table
  13588.         ld      (hl),d          ; Store into
  13589.         dec     hl
  13590.         ld      (hl),e
  13591. l4c07:
  13592.         pop     bc
  13593.         pop     de
  13594.         pop     hl
  13595.         ld      (l7b7b),hl      ; Restore current label pointer
  13596.         push    de
  13597.         push    bc
  13598.         call    l6dc6           ; Set label pointer
  13599.         call    l6f48           ; Verify ;
  13600.         ld      a,(l7b99)
  13601.         or      a               ; Test overlay
  13602.         jr      nz,l4c44        ; Yeap
  13603.         call    l6e76           ; Find FORWARD
  13604.         dw      l7533
  13605.         jr      nz,l4c2c        ; Nope
  13606.         push    iy              ; Copy PC
  13607.         pop     de
  13608.         call    l6b82           ; Set JP <addr>
  13609.         ld      a,-1
  13610.         jr      l4c38
  13611. l4c2c:
  13612.         call    l6e76           ; Find EXTERNAL
  13613.         dw      l753a
  13614.         jr      nz,l4c44        ; Nope
  13615.         call    l69f2           ; Get integer constant
  13616.         ex      de,hl
  13617.         xor     a
  13618. l4c38:
  13619.         pop     bc
  13620.         pop     hl
  13621.         ld      (hl),a          ; Store values
  13622.         dec     hl
  13623.         ld      (hl),b
  13624.         dec     hl
  13625.         ld      (hl),d          ; Set address
  13626.         dec     hl
  13627.         ld      (hl),e
  13628.         jp      l6f48           ; Verify ;
  13629. l4c44:
  13630.         pop     bc
  13631.         pop     hl
  13632.         push    hl
  13633.         ld      (hl),0          ; Set values
  13634.         dec     hl
  13635.         ld      (hl),b
  13636.         dec     hl
  13637.         push    iy              ; Copy PC
  13638.         pop     de
  13639.         ld      a,(l7b99)
  13640.         or      a               ; Test overlay
  13641.         jr      z,l4c5b         ; Nope
  13642.         ex      de,hl
  13643.         ld      bc,-16
  13644.         add     hl,bc           ; Fix value
  13645.         ex      de,hl
  13646. l4c5b:
  13647.         ld      (hl),d          ; Save address
  13648.         dec     hl
  13649.         ld      (hl),e
  13650.         pop     hl
  13651.         jr      l4c76
  13652. l4c61:
  13653.         ld      a,(hl)
  13654.         or      a
  13655.         call    l72d4           ; Verify label not found
  13656.         db      _DoubleLab
  13657.         ld      a,(l7b99)
  13658.         or      a               ; Test overlay (0 is not)
  13659.         call    l72da           ; Verify not FORWARD overlay
  13660.         db      _OvlFORW
  13661.         call    l6e96           ; Set new pointer
  13662.         pop     de
  13663.         call    l6f48           ; Verify ;
  13664. l4c76:
  13665.         ex      de,hl
  13666.         ld      a,(l7b9d)       ; Get option
  13667.         ld      hl,(l7908)      ; Get start of data
  13668.         bit     _Aopt,a         ; Test $A+ - absolute code for recursion
  13669.         jr      z,l4c84         ; Yeap
  13670.         ld      hl,0
  13671. l4c84:
  13672.         ld      (l7b83),hl
  13673.         ld      hl,(l7b7b)      ; Get current label pointer
  13674.         push    hl
  13675.         ld      hl,(l7b73)      ; Get label pointer
  13676.         ld      (l7b7b),hl      ; Into current
  13677.         push    hl
  13678.         ex      de,hl
  13679.         ld      a,(hl)
  13680.         ld      (hl),0
  13681.         dec     hl
  13682.         ld      b,(hl)
  13683.         dec     hl
  13684.         ld      d,(hl)
  13685.         dec     hl
  13686.         ld      e,(hl)
  13687.         dec     hl
  13688.         or      a
  13689.         jr      z,l4ca7
  13690.         push    hl
  13691.         ex      de,hl
  13692.         inc     hl
  13693.         call    storeback_iy_to_addrhl          ; Store back PC
  13694.         pop     hl
  13695. l4ca7:
  13696.         ld      a,(l7b97)
  13697.         or      a               ; Test PROCEDURE
  13698.         jr      z,l4cd2         ; Yeap
  13699.         ld      d,(hl)
  13700.         dec     hl
  13701.         ld      e,(hl)
  13702.         dec     hl
  13703.         push    hl
  13704.         ex      de,hl
  13705.         call    l5287           ; Get name
  13706.         ld      a,(l7b5c)       ; Get type
  13707.         ld      (l7b87),a
  13708.         ld      hl,(l7b62)      ; Get length of type
  13709.         ld      a,l
  13710.         ld      (l7b88),a       ; save lo
  13711.         ex      de,hl
  13712.         call    l6c30           ; Allocate space
  13713.         ld      (l7b89),hl
  13714.         ex      de,hl
  13715.         pop     hl
  13716.         ld      (hl),d
  13717.         dec     hl
  13718.         ld      (hl),e
  13719.         dec     hl
  13720.         jr      l4cd6
  13721. l4cd2:
  13722.         ld      de,-4
  13723.         add     hl,de
  13724. l4cd6:
  13725.         ld      de,-4
  13726.         add     hl,de
  13727.         push    hl
  13728.         ld      c,0
  13729.         ld      a,b
  13730.         or      a
  13731.         jr      z,l4d2b
  13732. l4ce1:
  13733.         ld      a,(hl)
  13734.         add     a,c
  13735.         ld      c,a
  13736.         push    bc
  13737.         ld      b,(hl)
  13738.         dec     hl
  13739.         ld      a,(hl)
  13740.         ld      (l7b8f),a
  13741.         dec     hl
  13742.         ld      d,(hl)          ; Get type table
  13743.         dec     hl
  13744.         ld      e,(hl)
  13745.         dec     hl
  13746.         push    hl
  13747.         ex      de,hl
  13748.         ld      (l7b5a),hl      ; Save type table
  13749.         call    l5287           ; Get name
  13750.         ld      hl,(l7b73)      ; Get label pointer
  13751.         ex      (sp),hl
  13752.         push    bc
  13753. l4cfd:
  13754.         push    bc
  13755.         ld      de,4*256+0
  13756.         call    puttolabel_d_e          ; Put to table
  13757. l4d04:
  13758.         ld      a,(hl)
  13759.         call    puttolabel              ; Store into table
  13760.         bit     _MB,(hl)        ; Test end of table
  13761.         dec     hl
  13762.         jr      z,l4d04         ; Nope
  13763.         push    hl
  13764.         call    puttolabel              ; Store last byte into table
  13765.         call    puttolabel_d_e          ; Put to table
  13766.         call    puttolabel_d_e
  13767.         call    l6dc6           ; Set label pointer
  13768.         pop     hl
  13769.         pop     bc
  13770.         djnz    l4cfd
  13771.         pop     bc
  13772.         ex      (sp),hl
  13773.         xor     a
  13774.         ld      (l7b90),a
  13775.         call    l4f52
  13776.         pop     hl
  13777.         pop     bc
  13778.         djnz    l4ce1
  13779. l4d2b:
  13780.         ld      b,c
  13781.         push    bc
  13782.         ld      hl,(l7b73)      ; Get label pointer
  13783.         push    hl
  13784.         ld      hl,(l7b83)
  13785.         push    hl
  13786.         ld      hl,(l7b89)
  13787.         push    hl
  13788.         ld      a,(l7b87)
  13789.         push    af
  13790.         ld      a,(l7b88)
  13791.         push    af
  13792.         ld      a,(l7b97)       ; Get PROCEDURE/FUNCTION flag
  13793.         push    af              ; Save it
  13794.         ld      hl,l7b94        ; Point to ???
  13795.         inc     (hl)
  13796.         call    l469e           ; Perform a block
  13797.         pop     af
  13798.         ld      (l7b97),a       ; Reset flag
  13799.         pop     af
  13800.         ld      (l7b88),a
  13801.         pop     af
  13802.         ld      (l7b87),a
  13803.         pop     hl
  13804.         ld      (l7b89),hl
  13805.         pop     hl
  13806.         ld      (l7b83),hl
  13807.         ld      (l7b85),de
  13808.         ld      a,h
  13809.         or      l
  13810.         jr      z,l4d79
  13811.         sbc     hl,de
  13812.         jr      z,l4d79
  13813.         call    l6b8a           ; Set LD BC,val16
  13814.         ex      de,hl
  13815.         call    l6b92           ; Set LD HL,val16
  13816.         ld      hl,l0508        ; Set recursion routine
  13817.         call    l6b86           ; Set CALL RECUR
  13818. l4d79:
  13819.         pop     hl
  13820.         pop     bc
  13821.         inc     b
  13822.         dec     b
  13823.         jp      z,l4df3
  13824.         call    l6b50           ; Set POP IY
  13825.         db      a_L1
  13826. s_I1:
  13827.         POP     IY
  13828. a_L1    equ     $-s_I1
  13829. l4d86:
  13830.         push    bc
  13831.         inc     hl
  13832.         ld      e,(hl)
  13833.         inc     hl
  13834.         ld      d,(hl)
  13835.         add     hl,de
  13836.         push    hl
  13837.         dec     hl
  13838.         dec     hl
  13839. l4d8f:
  13840.         bit     _MB,(hl)        ; Test end of string
  13841.         dec     hl
  13842.         jr      z,l4d8f         ; Nope
  13843.         call    l5276           ; Get values and name
  13844.         ld      a,(l7b57)
  13845.         or      a
  13846.         jr      nz,l4dd4
  13847.         ld      a,(l7b5c)       ; Get type
  13848.         cp      _Set
  13849.         jr      c,l4dbd
  13850.         jr      z,l4de6
  13851.         cp      _Ptr
  13852.         jr      z,l4de3
  13853.         cp      _String
  13854.         jr      c,l4dbd
  13855.         jr      z,l4de6
  13856.         cp      _Integ
  13857.         jr      nc,l4de3
  13858.         call    l6b50           ; Set POP sequence
  13859.         db      a_L2
  13860. s_I2:
  13861.         POP     HL
  13862.         POP     DE
  13863.         POP     BC
  13864. a_L2    equ     $-s_I2
  13865.         jr      l4de6
  13866. l4dbd:
  13867.         call    l6b73           ; Set POP HL
  13868.         ld      hl,(l7b58)      ; Get value
  13869.         call    l6b8e           ; Set LD DE,val16
  13870.         ld      hl,(l7b62)      ; Get length of type
  13871.         call    l6b8a           ; Set LD BC,val16
  13872.         call    l6b50           ; Set LDIR
  13873.         db      a_L3
  13874. s_I3:
  13875.         LDIR
  13876. a_L3    equ     $-s_I3
  13877.         jr      l4de9
  13878. l4dd4:
  13879.         xor     a
  13880.         ld      (l7b57),a
  13881.         ld      a,_Ptr
  13882.         ld      (l7b5c),a       ; Set POINTER
  13883.         ld      hl,2
  13884.         ld      (l7b62),hl      ; Set length of pointer type
  13885. l4de3:
  13886.         call    l6b73           ; Set POP HL
  13887. l4de6:
  13888.         call    l661b
  13889. l4de9:
  13890.         pop     hl
  13891.         pop     bc
  13892.         djnz    l4d86
  13893.         call    l6b50           ; Set PUSH IY
  13894.         db      a_L4
  13895. s_I4:
  13896.         PUSH    IY
  13897. a_L4    equ     $-s_I4
  13898. l4df3:
  13899.         call    l52fc
  13900.         ld      hl,l7b94        ; Point to ???
  13901.         dec     (hl)
  13902.         ld      a,(l7b97)
  13903.         or      a               ; Test PROCEDURE
  13904.         jr      z,l4e46         ; Yeap
  13905.         ld      hl,(l7b89)
  13906.         ld      a,(l7b87)
  13907.         cp      _String
  13908.         jr      nz,l4e24
  13909.         ld      b,a
  13910.         call    l6b50           ; Set POP IY
  13911.         db      a_L5
  13912. s_I5:
  13913.         POP     IY
  13914. a_L5    equ     $-s_I5
  13915.         ld      a,_LD.HL
  13916.         call    l6b94           ; Set LD HL,val16
  13917.         ld      hl,l053a
  13918.         call    l6b86           ; move string to stack
  13919.         call    l6b50
  13920.         db      a_L6
  13921. s_I6:
  13922.         PUSH    IY
  13923. a_L6    equ     $-s_I6
  13924.         jr      l4e46
  13925. l4e24:
  13926.         cp      _Real
  13927.         jr      nz,l4e35
  13928.         ld      a,_LD.HL
  13929.         call    l6b94           ; Set LD HL,val16
  13930.         ld      hl,l052c
  13931.         call    l6b86           ; Set load real
  13932.         jr      l4e46
  13933. l4e35:
  13934.         ld      a,_LD_a_HL
  13935.         call    l6b94           ; Set LD HL,(adr16)
  13936.         ld      a,(l7b88)
  13937.         dec     a
  13938.         jr      nz,l4e46
  13939.         call    l6b50           ; Set LD H,0
  13940.         db      a_L7
  13941. s_I7:
  13942.         LD      H,0
  13943. a_L7    equ     $-s_I7
  13944. l4e46:
  13945.         ld      hl,(l7b83)
  13946.         ld      a,h
  13947.         or      l
  13948.         jr      z,l4e74
  13949.         ld      de,(l7b85)
  13950.         sbc     hl,de
  13951.         jr      z,l4e74
  13952.         ld      a,(l7b97)
  13953.         or      a               ; Test PROCEDURE
  13954.         jr      z,l4e65         ; Yeap
  13955.         ld      a,(l7b87)
  13956.         cp      _String
  13957.         ld      a,_EXX
  13958.         call    nz,writebyte_a_addriy   ; Set EXX
  13959. l4e65:
  13960.         call    l6b8a           ; Set LD BC,val16
  13961.         ex      de,hl
  13962.         call    l6b8e           ; Set LD DE,val16
  13963.         ld      hl,l0522
  13964.         call    l6b82           ; Set end of recursive routine
  13965.         jr      l4e79
  13966. l4e74:
  13967.         call    l6b50           ; Set RET
  13968.         db      a_L8
  13969. s_I8:
  13970.         RET
  13971. a_L8    equ     $-s_I8
  13972. l4e79:
  13973.         call    l6f48           ; Verify ;
  13974.         pop     de
  13975.         pop     hl
  13976.         ld      (l7b73),hl      ; Set label pointers
  13977.         ld      (l7b75),hl
  13978.         pop     hl
  13979.         ld      (l7b7b),hl      ; Restore current label pointer
  13980.         ex      de,hl
  13981.         ret
  13982. ;
  13983. ; Process BEGIN
  13984. ;
  13985. l4e8a:
  13986.         ld      hl,(l7b73)      ; Get label pointer
  13987. l4e8d:
  13988.         ld      de,(l7b7b)      ; Get current label pointer
  13989.         or      a
  13990.         sbc     hl,de
  13991.         add     hl,de
  13992.         ret     z               ; End on level 0
  13993.         inc     hl
  13994.         ld      e,(hl)
  13995.         inc     hl
  13996.         ld      d,(hl)
  13997.         add     hl,de
  13998.         ld      a,(hl)
  13999.         cp      6 ;_TxtF???
  14000.         jr      z,l4ea4
  14001.         cp      5 ;_RecF???
  14002.         jr      nz,l4e8d
  14003. l4ea4:
  14004.         push    hl
  14005.         dec     hl
  14006.         dec     hl
  14007. l4ea7:
  14008.         bit     _MB,(hl)        ; Find end of string
  14009.         dec     hl
  14010.         jr      z,l4ea7
  14011.         ld      a,(hl)          ; Get type
  14012.         or      a
  14013.         call    l72da           ; Maybe undefined FORWARD
  14014.         db      _UndefFORW
  14015.         pop     hl
  14016.         jr      l4e8d
  14017. ;
  14018. ;
  14019. ;
  14020. l4eb5:
  14021.         ld      hl,(l7b73)      ; Get label pointer
  14022.         push    hl
  14023.         ld      b,0
  14024. l4ebb:
  14025.         push    bc
  14026.         ld      d,_Ptr  ; Set type
  14027.         ld      a,(l7b91)       ; Get ???
  14028.         ld      e,a
  14029.         call    puttolabel_d_e          ; Put to table
  14030.         call    l6d87           ; Get label
  14031.         call    puttolabel              ; Store into table
  14032.         call    puttolabel_d_e          ; Put to table
  14033.         call    puttolabel_d_e          ; Twice
  14034.         call    l6dc6           ; Set label pointer
  14035.         pop     bc
  14036.         inc     b
  14037.         call    l6f13           ; Test ,
  14038.         jr      z,l4ebb         ; Yeap
  14039.         pop     hl
  14040.         ret
  14041. ;
  14042. ;
  14043. ;
  14044. l4edd:
  14045.         ld      hl,(l7b73)      ; Get label pointer
  14046.         push    hl
  14047.         call    l4f9b           ; Get type
  14048.         pop     hl
  14049.         call    l5295
  14050.         call    l6e76           ; Test ABSOLUTE
  14051.         dw      l7562
  14052.         ld      a,0
  14053.         jr      nz,l4f14        ; Nope
  14054.         ld      a,(l7b91)       ; Get ???
  14055.         or      a
  14056.         call    l72da
  14057.         db      _InvalABS
  14058.         ld      bc,256*_Ptr+0
  14059.         call    l6e54           ; Find label
  14060.         jr      nz,l4f0c        ; Nope
  14061.         ld      a,(hl)
  14062.         ld      (l7b8f),a
  14063.         dec     hl
  14064.         ld      d,(hl)
  14065.         dec     hl
  14066.         ld      e,(hl)
  14067.         ex      de,hl
  14068.         jr      l4f0f
  14069. l4f0c:
  14070.         call    l69f2           ; Get integer constant
  14071. l4f0f:
  14072.         ld      (l7b7f),hl      ; Store value
  14073.         ld      a,-1
  14074. l4f14:
  14075.         ld      (l7b90),a
  14076.         ret
  14077. ;
  14078. ; Process variable on PROCEDURE and FUNCTION
  14079. ;
  14080. l4f18:
  14081.         call    l4fc8           ; Get simple type
  14082.         call    l72da           ; Verify ok
  14083.         db      _TypeExp
  14084.         xor     a
  14085.         ld      (l7b90),a
  14086.         ld      a,(l7b8f)
  14087.         or      a
  14088.         ret     nz
  14089.         ld      a,(l7b5c)       ; Get type
  14090.         cp      _RecF
  14091.         ret     c
  14092.         cp      _String
  14093.         ret     nc
  14094.         call    l72e1           ; Files must be VAR
  14095.         db      _VarFile
  14096. ;
  14097. ;
  14098. ;
  14099. l4f35:
  14100.         call    l4eb5
  14101.         push    hl
  14102.         push    bc
  14103.         call    l6f40           ; Verify :
  14104.         xor     a
  14105.         ld      (l7b8f),a
  14106.         call    l4edd
  14107.         pop     bc
  14108.         ld      a,(l7b90)
  14109.         or      a
  14110.         jr      z,l4f51
  14111.         ld      a,b
  14112.         dec     a
  14113.         call    l72da           ; Invalid ABSOLUTE
  14114.         db      _InvalABS
  14115. l4f51:
  14116.         pop     hl
  14117. l4f52:
  14118.         push    bc
  14119.         push    hl
  14120.         ld      a,(l7b8f)
  14121.         ld      hl,2
  14122.         or      a
  14123.         jr      nz,l4f60
  14124.         ld      hl,(l7b62)      ; Get length of type
  14125. l4f60:
  14126.         ex      de,hl
  14127.         ld      a,(l7b91)       ; Get ???
  14128.         or      a
  14129.         jr      nz,l4f72
  14130.         ld      a,(l7b90)
  14131.         or      a
  14132.         jr      nz,l4f72
  14133.         call    l6c30           ; Allocate space
  14134.         jr      l4f7b
  14135. l4f72:
  14136.         ld      hl,(l7b7f)
  14137.         push    hl
  14138.         add     hl,de
  14139.         ld      (l7b7f),hl
  14140.         pop     hl
  14141. l4f7b:
  14142.         ex      de,hl
  14143.         pop     hl
  14144.         dec     hl
  14145. l4f7e:
  14146.         dec     hl
  14147.         bit     _MB,(hl)
  14148.         jr      z,l4f7e
  14149.         dec     hl
  14150.         ld      a,(l7b8f)
  14151.         ld      (hl),a
  14152.         dec     hl
  14153.         ld      (hl),d
  14154.         dec     hl
  14155.         ld      (hl),e
  14156.         dec     hl
  14157.         ld      de,(l7b5a)      ; Get type table
  14158.         ld      (hl),d          ; Store into
  14159.         dec     hl
  14160.         ld      (hl),e
  14161.         dec     hl
  14162.         dec     hl
  14163.         dec     hl
  14164.         pop     bc
  14165.         djnz    l4f52
  14166.         ret
  14167. ;
  14168. ; Get a TYPE
  14169. ;
  14170. l4f9b:
  14171.         call    l4fc8           ; Test simple type
  14172.         ret     z
  14173.         call    l6e76           ; Skip possible PACKED
  14174.         dw      l7542
  14175.         call    l4fdb           ; Check ARRAY
  14176.         ret     z
  14177.         call    l5039           ; Check RECORD
  14178.         ret     z
  14179.         call    l5106           ; Check SET
  14180.         ret     z
  14181.         call    l5140           ; Check ^
  14182.         ret     z
  14183.         call    l516b           ; Check FILE
  14184.         ret     z
  14185.         call    l51a5           ; Check STRING
  14186.         ret     z
  14187.         call    l51c5           ; Test SCALAR ()
  14188.         ret     z
  14189.         call    l5210           ; Test RANGE ..
  14190.         ret     z
  14191.         call    l72e1           ; Type declaration expected
  14192.         db      _TypeExp
  14193. ;
  14194. ; Get SIMPLE TYPE
  14195. ; EXIT  Zero set if found
  14196. ;
  14197. l4fc8:
  14198.         ld      bc,256*3+0
  14199.         call    l6e54           ; Get from table
  14200.         ret     nz              ; Not found
  14201.         ld      d,(hl)          ; Fetch type table
  14202.         dec     hl
  14203.         ld      e,(hl)
  14204.         ex      de,hl
  14205.         ld      (l7b5a),hl      ; Save type
  14206.         call    l5287           ; Get name
  14207.         xor     a               ; Set success
  14208.         ret
  14209. ;
  14210. ; Look for ARRAY
  14211. ;
  14212. l4fdb:
  14213.         call    l6e76           ; Test ARRAY
  14214.         dw      l7548
  14215.         ret     nz              ; Nope
  14216.         call    l6f30           ; Verify [
  14217.         ld      b,0
  14218. l4fe6:
  14219.         push    bc
  14220.         call    l523b
  14221.         pop     bc
  14222.         ld      hl,(l7b5a)      ; Get type table
  14223.         push    hl
  14224.         ld      hl,(l7b60)      ; Get hi limit
  14225.         ld      de,(l7b5e)      ; Get lo limit
  14226.         or      a
  14227.         sbc     hl,de
  14228.         inc     hl
  14229.         ld      a,h
  14230.         or      l
  14231.         call    l72d4           ; Verify not same
  14232.         db      _MemOvfl
  14233.         push    hl
  14234.         inc     b
  14235.         call    l6f13           ; Test ,
  14236.         jr      z,l4fe6         ; Yeap
  14237.         push    bc
  14238.         call    l6f38           ; Verify ]
  14239.         call    l6f88
  14240.         call    l4f9b           ; Get type
  14241.         pop     bc
  14242. l5012:
  14243.         ld      hl,(l7b5a)      ; Get type table
  14244.         ld      (l7b5e),hl      ; Set as lo limit
  14245.         ld      hl,(l7b62)      ; Get length of type
  14246.         pop     de
  14247.         push    bc
  14248.         call    l729a           ; Multiply numbers
  14249.         call    l72c8           ; Check compiler overflow
  14250.         db      _MemOvfl
  14251.         pop     bc
  14252.         ld      (l7b62),hl      ; Set length of type
  14253.         pop     hl
  14254.         ld      (l7b60),hl      ; Set hi limit
  14255.         ld      a,_Array
  14256.         ld      (l7b5c),a       ; Set ARRAY
  14257.         push    bc
  14258.         call    l5254           ; Put to table
  14259.         pop     bc
  14260.         djnz    l5012
  14261.         ret
  14262. ;
  14263. ; Look for RECORD
  14264. ;
  14265. l5039:
  14266.         call    l6e76           ; Test RECORD
  14267.         dw      l7554
  14268.         ret     nz              ; Nope
  14269.         ld      a,(l7b9a)
  14270.         push    af
  14271.         ld      a,(l7b91)       ; Get ???
  14272.         push    af
  14273.         ld      hl,l7b92        ; Point to ???
  14274.         inc     (hl)
  14275.         ld      a,(hl)
  14276.         ld      (l7b91),a       ; Set ???
  14277.         ld      hl,(l7b7f)
  14278.         push    hl
  14279.         ld      hl,(l7b81)
  14280.         push    hl
  14281.         ld      hl,l0000
  14282.         ld      (l7b7f),hl
  14283.         ld      (l7b81),hl
  14284.         xor     a
  14285.         ld      (l7b9a),a
  14286.         call    l508b
  14287.         ld      hl,(l7b81)
  14288.         ld      (l7b62),hl      ; Set length of type
  14289.         pop     hl
  14290.         ld      (l7b81),hl
  14291.         pop     hl
  14292.         ld      (l7b7f),hl
  14293.         ld      a,(l7b91)       ; Get ???
  14294.         ld      (l7b5d),a
  14295.         pop     af
  14296.         ld      (l7b91),a       ; Set ???
  14297.         pop     af
  14298.         ld      (l7b9a),a
  14299.         ld      a,_Record
  14300.         ld      (l7b5c),a       ; Set RECORD
  14301.         jp      l5254
  14302. ;
  14303. ;
  14304. ;
  14305. l508b:
  14306.         call    l50f9
  14307.         ret     z
  14308.         call    l6e76           ; Test CASE
  14309.         dw      l75da
  14310.         jr      z,l50b0         ; Yeap
  14311.         call    l4f35
  14312.         ld      hl,(l7b7f)
  14313.         ld      de,(l7b81)
  14314.         or      a
  14315.         sbc     hl,de
  14316.         jr      c,l50a9
  14317.         add     hl,de
  14318.         ld      (l7b81),hl
  14319. l50a9:
  14320.         call    l6f0f           ; Test ;
  14321.         jr      z,l508b         ; Yeap
  14322.         jr      l50e8
  14323. l50b0:
  14324.         call    l4fc8
  14325.         call    nz,l4f35
  14326.         call    l6f88
  14327. l50b9:
  14328.         call    l50f9
  14329.         ret     z
  14330.         ld      hl,(l7b7f)
  14331.         push    hl
  14332. l50c1:
  14333.         call    l69ea           ; Get constant
  14334.         call    l6f13           ; Test ,
  14335.         jr      z,l50c1         ; Yeap
  14336.         call    l6f40           ; Verify :
  14337.         call    l6f66           ; Verify (
  14338.         ld      a,(l7b9a)
  14339.         push    af
  14340.         ld      a,0ffh
  14341.         ld      (l7b9a),a
  14342.         call    l508b
  14343.         pop     af
  14344.         ld      (l7b9a),a
  14345.         pop     hl
  14346.         ld      (l7b7f),hl
  14347.         call    l6f0f           ; Test ;
  14348.         jr      z,l50b9         ; Yeap
  14349. l50e8:
  14350.         ld      a,(l7b9a)
  14351.         or      a
  14352.         jp      nz,l6f6e        ; Verify )
  14353.         call    l6e76           ; Find END
  14354.         dw      l7530
  14355.         ret     z               ; Yeap
  14356.         call    l72e1
  14357.         db      _End
  14358. l50f9:
  14359.         ld      a,(l7b9a)
  14360.         or      a
  14361.         jp      nz,l6f1f
  14362.         call    l6e76           ; Find END
  14363.         dw      l7530
  14364.         ret
  14365. ;
  14366. ; Check SET
  14367. ;
  14368. l5106:
  14369.         call    l6e76           ; Test SET
  14370.         dw      l7551
  14371.         ret     nz              ; Nope
  14372.         call    l6f88
  14373.         call    l523b
  14374.         ld      hl,(l7b60)      ; Get hi set limit
  14375.         ld      de,(l7b5e)      ; Get lo set limit
  14376.         ld      a,h
  14377.         or      d
  14378.         call    l72da
  14379.         db      _IllSetRange
  14380.         srl     l
  14381.         srl     l
  14382.         srl     l
  14383.         srl     e
  14384.         srl     e
  14385.         srl     e
  14386.         ld      a,l
  14387.         inc     a
  14388.         sub     e
  14389.         ld      l,a
  14390.         ld      (l7b62),hl      ; Set length of type
  14391.         ld      hl,(l7b5a)      ; Get type table
  14392.         ld      (l7b5e),hl      ; Set lo set limit
  14393.         ld      a,_Set
  14394.         ld      (l7b5c),a       ; Set SET
  14395.         jp      l5254
  14396. ;
  14397. ; Check ^
  14398. ;
  14399. l5140:
  14400.         call    l6f27
  14401.         ret     nz
  14402.         ld      de,l0000
  14403.         call    puttolabel_d_e          ; Put to table
  14404.         ld      hl,(l7b73)      ; Get label pointer
  14405.         push    hl
  14406.         call    l6dba
  14407.         call    l6dc6           ; Set label pointer
  14408.         pop     hl
  14409.         ld      (l7b5e),hl      ; Set lo set limit
  14410.         ld      a,_Ptr
  14411.         ld      (l7b5c),a       ; Set POINTER
  14412.         ld      a,0ffh
  14413.         ld      (l7b5d),a
  14414.         ld      hl,l0002
  14415.         ld      (l7b62),hl      ; Set length of type
  14416.         jp      l5254
  14417. ;
  14418. ; Check FILE
  14419. ;
  14420. l516b:
  14421.         call    l6e76           ; Find FILE
  14422.         dw      l754d
  14423.         ret     nz              ; Nope
  14424.         call    l6e76           ; Find OF
  14425.         dw      l7560
  14426.         jr      nz,l5197        ; Nope
  14427.         call    l4f9b           ; Get type
  14428.         ld      a,(l7b5c)       ; Get type
  14429.         cp      _RecF
  14430.         jr      c,l518a
  14431.         cp      _String
  14432.         jr      nc,l518a
  14433.         call    l72e1
  14434.         db      _FileF
  14435. l518a:
  14436.         ld      hl,(l7b5a)      ; Get type table
  14437.         ld      (l7b5e),hl      ; Set lo set limit
  14438.         ld      a,_RecF
  14439.         ld      hl,l00b0
  14440.         jr      l519c
  14441. l5197:
  14442.         ld      a,_UntF
  14443.         ld      hl,l0030
  14444. l519c:
  14445.         ld      (l7b5c),a       ; Set type
  14446.         ld      (l7b62),hl      ; Set length of type
  14447.         jp      l5254
  14448. ;
  14449. ; Check STRING
  14450. ;
  14451. l51a5:
  14452.         call    l6e76           ; Find STRING
  14453.         dw      l755a
  14454.         ret     nz              ; Nope
  14455.         call    l6f30           ; Verify [
  14456.         call    l69f2           ; Get integer constant
  14457.         inc     h
  14458.         dec     h
  14459.         call    l72da
  14460.         db      _IllStrgLen
  14461.         inc     l
  14462.         dec     l
  14463.         call    l72d4
  14464.         db      _IllStrgLen
  14465.         call    l6f38           ; Verify ]
  14466.         inc     hl
  14467.         ld      a,_String
  14468.         jr      l519c
  14469. ;
  14470. ; Test SCALAR ()
  14471. ;
  14472. l51c5:
  14473.         call    l6f1b           ; Test (
  14474.         ret     nz              ; Nope
  14475.         ld      hl,lffff
  14476. l51cc:
  14477.         push    hl
  14478.         ld      de,2*256+0 ;l0200
  14479.         call    puttolabel_d_e          ; Put to table
  14480.         call    l6d87           ; Get label
  14481.         ld      a,(curtype_l7b93)       ; Get type
  14482.         call    puttolabel
  14483.         pop     de
  14484.         inc     de
  14485.         push    de
  14486.         call    puttolabel_d_e          ; Put to table
  14487.         call    l6dc6           ; Set label pointer
  14488.         pop     hl
  14489.         call    l6f13           ; Test ,
  14490.         jr      z,l51cc         ; Yeap
  14491.         call    l6f6e           ; Verify )
  14492.         push    hl
  14493.         ld      hl,curtype_l7b93        ; Point to type
  14494.         ld      a,(hl)
  14495.         inc     (hl)
  14496.         pop     hl
  14497.         ld      de,l0000
  14498. l51f8:
  14499.         ld      (l7b5c),a       ; Set type
  14500.         ld      (l7b5e),de      ; Set lo set limit
  14501.         ld      (l7b60),hl      ; Set hi set limit
  14502.         ld      a,d
  14503.         or      h
  14504.         ld      hl,l0001
  14505.         jr      z,l520a
  14506.         inc     hl
  14507. l520a:
  14508.         ld      (l7b62),hl      ; Set length of type
  14509.         jp      l5254
  14510. ;
  14511. ; Test RANGE ..
  14512. ;
  14513. l5210:
  14514.         call    l6a0d           ; Get constant
  14515.         ret     nz
  14516.         ld      a,b
  14517.         push    af
  14518.         cp      0ah ;_Integ
  14519.         call    l72c8
  14520.         db      _IllSkalar
  14521.         push    hl
  14522.         call    l6e76           ; Find ..
  14523.         dw      l7580
  14524.         call    l72da
  14525.         db      _TwoDots
  14526.         call    l69ea           ; Get constant
  14527.         pop     de
  14528.         pop     af
  14529.         push    af
  14530.         cp      b
  14531.         call    l72da
  14532.         db      _InvType
  14533.         call    l728d           ; Compare
  14534.         call    l72c8           ; Verify upper > lower
  14535.         db      _IllLimit
  14536.         pop     af
  14537.         jr      l51f8
  14538. ;
  14539. ;
  14540. ;
  14541. l523b:
  14542.         call    l5210
  14543.         ret     z
  14544.         call    l51c5
  14545.         ret     z
  14546.         call    l4fc8
  14547.         call    l72da
  14548.         db      _SimTyp
  14549.         ld      a,(l7b5c)       ; Get type
  14550.         cp      _Integ
  14551.         ret     nc
  14552.         call    l72e1
  14553.         db      _SimTyp
  14554. l5254:
  14555.         ld      de,8*256+0 ;l0800
  14556.         call    puttolabel_d_e          ; Put to table
  14557.         ld      hl,(l7b73)      ; Get label pointer
  14558.         ld      (l7b5a),hl      ; Save into type table
  14559.         ld      hl,l7b5c        ; Point to type
  14560.         ld      b,8
  14561. l5265:
  14562.         ld      a,(hl)
  14563.         call    puttolabel
  14564.         inc     hl
  14565.         djnz    l5265
  14566.         call    l6dc6           ; Set label pointer
  14567.         xor     a
  14568.         ret
  14569. ;
  14570. ;
  14571. ;
  14572. l5271:
  14573.         ld      de,l7b69
  14574.         jr      l528a
  14575. ;
  14576. ; Get values and name
  14577. ;
  14578. l5276:
  14579.         ld      a,(hl)
  14580.         dec     hl
  14581.         ld      (l7b57),a
  14582.         ld      d,(hl)
  14583.         dec     hl
  14584.         ld      e,(hl)
  14585.         dec     hl
  14586.         ld      (l7b58),de      ; Set value
  14587.         ld      d,(hl)
  14588.         dec     hl
  14589.         ld      e,(hl)
  14590.         ex      de,hl
  14591. ;
  14592. ; Get name
  14593. ;
  14594. l5287:
  14595.         ld      de,l7b5c        ; Point to type
  14596. l528a:
  14597.         push    bc
  14598.         ld      b,8
  14599. l528d:
  14600.         ld      a,(hl)
  14601.         ld      (de),a
  14602.         dec     hl
  14603.         inc     de
  14604.         djnz    l528d
  14605.         pop     bc
  14606.         ret
  14607. ;
  14608. ;
  14609. ;
  14610. l5295:
  14611.         ld      (l7b79),hl
  14612.         ld      hl,(l7b73)      ; Get label pointer
  14613. l529b:
  14614.         ld      bc,(l7b79)
  14615.         or      a
  14616.         sbc     hl,bc
  14617.         add     hl,bc
  14618.         ret     z
  14619.         inc     hl
  14620.         ld      c,(hl)
  14621.         inc     hl
  14622.         ld      b,(hl)
  14623.         add     hl,bc
  14624.         ld      a,(hl)
  14625.         cp      8 ;???
  14626.         jr      nz,l529b
  14627.         ld      (hl),0
  14628.         push    hl
  14629.         dec     hl
  14630.         dec     hl
  14631.         ld      a,(hl)
  14632.         cp      4 ;???
  14633.         jr      nz,l52f8
  14634.         dec     hl
  14635.         ld      a,(hl)
  14636.         or      a
  14637.         jr      z,l52f8
  14638.         ld      (hl),0
  14639.         dec     hl
  14640.         push    hl
  14641.         ld      e,(hl)
  14642.         dec     hl
  14643.         ld      d,(hl)
  14644.         ld      hl,(l7b73)      ; Get label pointer
  14645. l52c7:
  14646.         ld      bc,(l7b77)      ; Get top of available memory
  14647.         or      a
  14648.         sbc     hl,bc
  14649.         add     hl,bc
  14650.         call    l72d4
  14651.         db      _InkPointer
  14652.         inc     hl
  14653.         ld      c,(hl)
  14654.         inc     hl
  14655.         ld      b,(hl)
  14656.         add     hl,bc
  14657.         ld      a,(hl)
  14658.         cp      3 ;???
  14659.         jr      nz,l52c7
  14660.         push    hl
  14661.         push    de
  14662.         dec     hl
  14663.         dec     hl
  14664. l52e1:
  14665.         ld      a,(de)
  14666.         cp      (hl)
  14667.         jr      z,l52e9
  14668.         pop     de
  14669.         pop     hl
  14670.         jr      l52c7
  14671. l52e9:
  14672.         bit     7,(hl)
  14673.         dec     hl
  14674.         dec     de
  14675.         jr      z,l52e1
  14676.         pop     bc
  14677.         pop     bc
  14678.         ld      b,(hl)
  14679.         dec     hl
  14680.         ld      c,(hl)
  14681.         pop     hl
  14682.         ld      (hl),c
  14683.         dec     hl
  14684.         ld      (hl),b
  14685. l52f8:
  14686.         pop     hl
  14687.         jp      l529b
  14688. ;
  14689. ;
  14690. ;
  14691. l52fc:
  14692.         xor     a
  14693.         ld      (l7b95),a
  14694.         ld      (l7bc9),a
  14695.         call    l5377
  14696.         ld      (l7ba4),iy
  14697.         call    l6b82
  14698.         ld      hl,(l7b73)      ; Get label pointer
  14699. l5310:
  14700.         ld      de,(l7b75)      ; Get previous label pointer
  14701.         or      a
  14702.         sbc     hl,de
  14703.         add     hl,de
  14704.         jr      nc,l5363
  14705.         inc     hl
  14706.         ld      c,(hl)
  14707.         inc     hl
  14708.         ld      b,(hl)
  14709.         inc     hl
  14710.         ld      a,(hl)
  14711.         inc     hl
  14712.         ld      e,(hl)
  14713.         inc     hl
  14714.         ld      d,(hl)
  14715.         push    hl
  14716.         push    bc
  14717.         ld      b,a
  14718.         ld      a,d
  14719.         or      e
  14720.         jr      z,l533a
  14721.         ex      de,hl
  14722.         dec     hl
  14723.         ld      a,(hl)
  14724.         ld      c,a
  14725.         inc     a
  14726.         call    l72d4
  14727.         db      _UnkLabel
  14728.         dec     hl
  14729.         ld      d,(hl)
  14730.         dec     hl
  14731.         ld      e,(hl)
  14732.         jr      l5340
  14733. l533a:
  14734.         ld      de,(l7ba4)
  14735.         ld      c,0
  14736. l5340:
  14737.         pop     hl
  14738.         ld      a,b
  14739.         sub     c
  14740.         jr      nz,l534a
  14741.         call    storeback_de_to_addrhl
  14742.         jr      l5360
  14743. l534a:
  14744.         call    l72c8
  14745.         db      _IllGOTO
  14746.         push    de
  14747.         push    af
  14748.         call    storeback_iy_to_addrhl          ; Store back PC
  14749.         pop     af
  14750.         ld      b,a
  14751. l5355:
  14752.         call    l6b73           ; Set POP HL
  14753.         djnz    l5355
  14754.         ld      a,_JP
  14755.         pop     hl
  14756.         call    l6b94
  14757. l5360:
  14758.         pop     hl
  14759.         jr      l5310
  14760. l5363:
  14761.         ld      hl,(l7ba4)
  14762.         inc     hl
  14763.         push    iy
  14764.         pop     de
  14765.         dec     de
  14766.         dec     de
  14767.         or      a
  14768.         sbc     hl,de
  14769.         add     hl,de
  14770.         jp      nz,storeback_iy_to_addrhl       ; Store back PC
  14771.         dec     hl
  14772.         jp      l6cc2           ; Check chaining
  14773. ;
  14774. ; Statement BEGIN
  14775. ;
  14776. l5377:
  14777.         call    l5385           ; Process a statement
  14778.         call    l6e76           ; Find END
  14779.         dw      l7530
  14780.         ret     z
  14781.         call    l6f50
  14782.         jr      l5377
  14783. ;
  14784. ; Process a statement
  14785. ;
  14786. l5385:
  14787.         ld      a,0ffh
  14788.         ld      (l7b98),a
  14789.         ld      a,(l7b9d)       ; Get options
  14790.         ld      (l7b9e),a       ; Set local options
  14791.         bit     _Uopt,a         ; Test $U+
  14792.         jr      z,l539c         ; Nope
  14793.         ld      a,RST
  14794.         ld      (l7ba0),a       ; Set end on break flag [option U+]
  14795.         call    writebyte_a_addriy              ; Insert RST
  14796. l539c:
  14797.         call    l6e5a           ; Find statement
  14798.         db      2
  14799.         dw      l75bb
  14800.         jr      z,l53cb         ; Yeap
  14801.         call    l67b2
  14802.         jp      z,l57ea
  14803.         ld      bc,256*5+0
  14804.         call    l6e54
  14805.         jp      z,l573d
  14806.         ld      bc,256*1+0
  14807.         call    l6e54
  14808.         jr      z,l53d0
  14809.         ld      bc,256*6+0
  14810.         call    l6e54
  14811.         jp      z,l591f
  14812.         call    l6e5a           ; Find procedure
  14813.         db      2
  14814.         dw      l7638
  14815.         ret     nz              ; Nope
  14816. l53cb:
  14817.         ld      e,(hl)          ; Fetch address
  14818.         inc     hl
  14819.         ld      d,(hl)
  14820.         ex      de,hl
  14821.         jp      (hl)            ; Go
  14822. l53d0:
  14823.         call    l6f40           ; Verify :
  14824.         ld      a,(l7b94)       ; Get ???
  14825.         cp      (hl)
  14826.         call    l72da
  14827.         db      _IllLabel
  14828.         dec     hl
  14829.         ld      a,(hl)
  14830.         inc     a
  14831.         call    l72da
  14832.         db      _DoubleLab
  14833.         ld      a,(l7b95)
  14834.         ld      (hl),a
  14835.         push    iy
  14836.         pop     de
  14837.         dec     hl
  14838.         ld      (hl),d
  14839.         dec     hl
  14840.         ld      (hl),e
  14841.         jr      l5385
  14842. ;
  14843. ; Statement IF
  14844. ;
  14845. l53ef:
  14846.         call    l5eb0
  14847.         call    l6b50           ; Set BIT 0,L ! JP Z,addr
  14848.         db      a_L9
  14849. s_I9:
  14850.         BIT     _LB,L
  14851.         db      _JPZ
  14852. a_L9    equ     $-s_I9
  14853.         push    iy
  14854.         call    writeword_hl_addriy
  14855.         call    l6e76           ; Find THEN
  14856.         dw      l756a
  14857.         call    l72da
  14858.         db      _StrIdx
  14859.         call    l5385           ; Process a statement
  14860.         call    l6e76           ; Find ELSE
  14861.         dw      l756e
  14862.         jr      nz,l5420        ; Nope
  14863.         call    l6b77           ; Set JP
  14864.         pop     hl
  14865.         push    iy
  14866.         call    writeword_hl_addriy
  14867.         call    storeback_iy_to_addrhl          ; Store back PC
  14868.         call    l5385           ; Process a statement
  14869. l5420:
  14870.         pop     hl
  14871.         jp      storeback_iy_to_addrhl          ; Store back PC
  14872. ;
  14873. ; Statement WHILE
  14874. ;
  14875. l5424:
  14876.         push    iy
  14877.         call    l5eb0
  14878.         call    l6e76           ; Find DO
  14879.         dw      l7572
  14880.         call    l72da
  14881.         db      _NoDO
  14882.         call    l6b50           ; Set BIT 0,L ! JP Z,addr
  14883.         db      a_L10
  14884. s_I10:
  14885.         BIT     _LB,L
  14886.         db      _JPZ
  14887. a_L10   equ     $-s_I10
  14888.         push    iy
  14889.         call    writeword_hl_addriy
  14890.         call    l5385           ; Process a statement
  14891.         pop     de
  14892.         pop     hl
  14893.         ld      a,_JP
  14894.         call    l6b94
  14895.         ex      de,hl
  14896.         jp      storeback_iy_to_addrhl          ; Store back PC
  14897. ;
  14898. ; Statement REPEAT
  14899. ;
  14900. l544c:
  14901.         push    iy
  14902. l544e:
  14903.         call    l5385           ; Process a statement
  14904.         call    l6e76           ; Find UNTIL
  14905.         dw      l7574
  14906.         jr      z,l545d         ; Yeap
  14907.         call    l6f50
  14908.         jr      l544e
  14909. l545d:
  14910.         call    l5eb0
  14911.         call    l6b50
  14912.         db      a_L11
  14913. s_I11:
  14914.         BIT     _LB,L
  14915.         db      _JPZ
  14916. a_L11   equ     $-s_I11
  14917.         pop     hl
  14918.         jp      writeword_hl_addriy
  14919. ;
  14920. ; Statement FOR
  14921. ;
  14922. l546b:
  14923.         ld      bc,256*4+0
  14924.         call    l6e54
  14925.         call    l72da
  14926.         db      _Undef
  14927.         call    l5276
  14928.         ld      a,(l7b57)
  14929.         or      a
  14930.         jr      nz,l5485
  14931.         ld      a,(l7b5c)       ; Get type
  14932.         cp      _Integ
  14933.         jr      nc,l5489
  14934. l5485:
  14935.         call    l72e1
  14936.         db      _SimTyp
  14937. l5489:
  14938.         call    l6d2a           ; Save environment
  14939.         ld      a,(l7b5c)       ; Get type
  14940.         push    af
  14941.         call    l6f7e
  14942.         call    l5ee8
  14943.         call    l6b6f           ; Set PUSH HL
  14944.         pop     af
  14945.         push    af
  14946.         cp      b
  14947.         call    l72da
  14948.         db      _InvType
  14949.         call    l6e5a           ; Find TO or DOWNTO
  14950.         db      1
  14951.         dw      l75f5
  14952.         call    l72da
  14953.         db      _NoDOWN_TO
  14954.         ld      e,(hl)          ; Get instruction
  14955.         push    de
  14956.         call    l5ee8
  14957.         pop     de
  14958.         pop     af
  14959.         push    de
  14960.         cp      b
  14961.         call    l72da
  14962.         db      _InvType
  14963.         call    l6e76           ; Find DO
  14964.         dw      l7572
  14965.         call    l72da
  14966.         db      _NoDO
  14967.         call    l6b50           ; Set POP DE
  14968.         db      a_L12
  14969. s_I12:
  14970.         POP     DE
  14971. a_L12   equ     $-s_I12
  14972.         pop     de
  14973.         call    l6d63
  14974.         push    de
  14975.         ld      a,e
  14976.         ld      hl,l0666        ; Set up FOR .. TO loop
  14977.         cp      '#'
  14978.         jr      z,l54d5
  14979.         ld      hl,l0676        ; Set up FOR .. DOWNTO loop
  14980. l54d5:
  14981.         call    l6b86           ; Set CALL <loop>
  14982.         push    iy
  14983.          ;jr $
  14984.         call    l6b50           ; Set code sequence
  14985.         db      a_L13
  14986. s_I13:
  14987.         LD      A,D
  14988.         OR      E
  14989.         JP      Z,$-$ ;for future patching???
  14990.         PUSH    DE
  14991. a_L13   equ     $-s_I13
  14992.         call    l661b
  14993.         ld      hl,l7b95
  14994.         inc     (hl)
  14995.         call    l5385           ; Process a statement
  14996.         ld      hl,l7b95
  14997.         dec     (hl)
  14998.         pop     hl
  14999.         pop     de
  15000.         call    l6d49           ; Get back environment
  15001.         push    hl
  15002.         ld      hl,(l7b58)      ; Get value
  15003.         ld      a,_LD_a_HL
  15004.         call    l6b94
  15005.         ld      a,(l7b62)       ; Get length of type
  15006.         dec     a
  15007.         jr      nz,l550c
  15008.         call    l6b50           ; Set LD H,0
  15009.         db      a_L14
  15010. s_I14:
  15011.         LD      H,0
  15012. a_L14   equ     $-s_I14
  15013. l550c:
  15014.         ld      a,e             ; Get byte
  15015.         call    writebyte_a_addriy              ; Store it
  15016.         call    l6b50           ; Set code sequence
  15017.         db      a_L15
  15018. s_I15:
  15019.         POP     DE
  15020.         DEC     DE
  15021.         db      _JP
  15022. a_L15   equ     $-s_I15
  15023.         pop     hl
  15024.         call    writeword_hl_addriy
  15025.         inc     hl
  15026.         inc     hl
  15027.         inc     hl
  15028.         jp      storeback_iy_to_addrhl          ; Store back PC
  15029. ;
  15030. ; Statement CASE
  15031. ;
  15032. l5521:
  15033.         call    l5ebb
  15034.         ld      (l7b9c),a
  15035.         xor     a
  15036.         ld      (l7b9b),a
  15037.         call    l6f88
  15038.         ld      b,0
  15039.         push    bc
  15040. l5531:
  15041.         ld      b,1
  15042. l5533:
  15043.         push    bc
  15044.         ld      hl,l7b9b
  15045.         bit     7,(hl)
  15046.         jr      z,l5549
  15047.         call    l6b50           ; Set ADD HL,DE
  15048.         db      a_L16
  15049. s_I16:
  15050.         ADD     HL,DE
  15051. a_L16   equ     $-s_I16
  15052.         bit     4,(hl)
  15053.         jr      z,l5549
  15054.         call    l6b50           ; Set ADD HL,BC
  15055.         db      a_L17
  15056. s_I17:
  15057.         ADD     HL,BC
  15058. a_L17   equ     $-s_I17
  15059. l5549:
  15060.         call    l69ea           ; Get constant
  15061.         ld      a,(l7b9c)
  15062.         cp      b
  15063.         call    l72da
  15064.         db      _IllCASE
  15065.         call    l6b8e           ; Set LD DE,val16
  15066.         push    hl
  15067.         call    l6e76           ; Find ..
  15068.         dw      l7580
  15069.         pop     hl
  15070.         jr      nz,l5582        ; Nope
  15071.         push    hl
  15072.         call    l69ea           ; Get constant
  15073.         ld      a,(l7b9c)
  15074.         cp      b
  15075.         call    l72da
  15076.         db      _IllCASE
  15077.         pop     de
  15078.         or      a
  15079.         sbc     hl,de
  15080.         inc     hl
  15081.         call    l6b8a
  15082.         call    l6b50           ; Set sequence
  15083.         db      a_L18
  15084. s_I18:
  15085.         OR      A
  15086.         SBC     HL,DE
  15087.         OR      A
  15088.         SBC     HL,BC
  15089. a_L18   equ     $-s_I18
  15090.         ld      a,0dah
  15091.         jr      l558b
  15092. l5582:
  15093.         call    l6b50           ; Set sequence
  15094.         db      a_L19
  15095. s_I19:
  15096.         OR      A
  15097.         SBC     HL,DE
  15098. a_L19   equ     $-s_I19
  15099.         ld      a,0cah
  15100. l558b:
  15101.         ld      (l7b9b),a
  15102.         call    l6f0b           ; Test :
  15103.         pop     bc
  15104.         jr      z,l55a5
  15105.         ld      a,(l7b9b)       ; Get byte
  15106.         call    writebyte_a_addriy              ; Store it
  15107.         push    iy
  15108.         call    writeword_hl_addriy
  15109.         call    l6f5e           ; Verify ,
  15110.         inc     b
  15111.         jr      l5533
  15112. l55a5:
  15113.         push    iy
  15114.         pop     de
  15115.         inc     de
  15116.         inc     de
  15117.         inc     de
  15118. l55ab:
  15119.         dec     b
  15120.         jr      z,l55b4
  15121.         pop     hl
  15122.         call    storeback_de_to_addrhl
  15123.         jr      l55ab
  15124. l55b4:
  15125.         ld      a,(l7b9b)       ; Get byte
  15126.         res     3,a             ; Fix it
  15127.         call    writebyte_a_addriy              ; Store
  15128.         pop     bc
  15129.         push    iy
  15130.         inc     b
  15131.         push    bc
  15132.         call    writeword_hl_addriy
  15133.         ld      a,(l7b9b)
  15134.         push    af
  15135.         ld      a,(l7b9c)
  15136.         push    af
  15137.         call    l5385           ; Process a statement
  15138.         pop     af
  15139.         ld      (l7b9c),a
  15140.         pop     af
  15141.         ld      (l7b9b),a
  15142.         call    l6f0f           ; Test ;
  15143.         ld      e,1
  15144.         jr      z,l55df         ; Yeap
  15145.         dec     e
  15146. l55df:
  15147.         push    de
  15148.         call    l6e76           ; Find END
  15149.         dw      l7530
  15150.         pop     de
  15151.         jr      z,l561e
  15152.         call    l6b77           ; Set JP
  15153.         pop     bc
  15154.         pop     hl
  15155.         push    iy
  15156.         push    bc
  15157.         push    de
  15158.         call    writeword_hl_addriy
  15159.         call    storeback_iy_to_addrhl          ; Store back PC
  15160.         call    l6e76           ; Find ELSE
  15161.         dw      l756e
  15162.         pop     de
  15163.         jr      z,l560f         ; Yeap
  15164.         dec     e
  15165.         jp      z,l5531
  15166.         ld      a,(l7b98)
  15167.         or      a
  15168.         call    l72d4
  15169.         db      _End
  15170.         call    l72e1
  15171.         db      _Undef
  15172. l560f:
  15173.         call    l5385           ; Process a statement
  15174.         call    l6e76           ; Find END
  15175.         dw      l7530
  15176.         jr      z,l561e         ; Yeap
  15177.         call    l6f50
  15178.         jr      l560f
  15179. l561e:
  15180.         pop     bc
  15181. l561f:
  15182.         pop     hl
  15183.         call    storeback_iy_to_addrhl          ; Store back PC
  15184.         djnz    l561f
  15185.         ret
  15186. ;
  15187. ; Statement GOTO
  15188. ;
  15189. l5626:
  15190.         ld      bc,256*1+0
  15191.         call    l6e54
  15192.         call    l72da
  15193.         db      _UnkLabel
  15194.         ld      a,(l7b94)
  15195.         cp      (hl)
  15196.         call    l72da
  15197.         db      _IllLabel
  15198.         ex      de,hl
  15199. l5639:
  15200.         call    puttolabel_d_e          ; Put to table
  15201.         ld      a,(l7b95)
  15202.         call    puttolabel
  15203.         call    l6b77           ; Set JP
  15204.         push    iy
  15205.         pop     de
  15206.         call    puttolabel_d_e          ; Put to table
  15207.         jp      writeword_hl_addriy
  15208. ;
  15209. ; Statement WITH
  15210. ;
  15211. l564e:
  15212.         ld      a,(l7bc9)
  15213.         push    af
  15214. l5652:
  15215.         ld      a,(l7bc6)
  15216.         ld      hl,l7bc9
  15217.         cp      (hl)
  15218.         call    l72d4
  15219.         db      _TooManyWITH
  15220.         call    l677f
  15221.         ld      a,(l7b5c)       ; Get type
  15222.         cp      _Record
  15223.         call    l72da
  15224.         db      _RecVarExp
  15225.         ld      hl,l7bc9
  15226.         ld      e,(hl)
  15227.         ld      d,0
  15228.         inc     (hl)
  15229.         ld      hl,l7bcc
  15230.         add     hl,de
  15231.         ld      a,(l7b5d)
  15232.         ld      (hl),a
  15233.         ld      hl,(l7bca)
  15234.         add     hl,de
  15235.         add     hl,de
  15236.         ld      a,_LDHL_a
  15237.         call    l6b94
  15238.         call    l6f13           ; Test ,
  15239.         jr      z,l5652         ; Yeap
  15240.         call    l6e76           ; Find DO
  15241.         dw      l7572
  15242.         call    l72da
  15243.         db      _NoDO
  15244.         call    l5385           ; Process a statement
  15245.         pop     af
  15246.         ld      (l7bc9),a
  15247.         ret
  15248. ;
  15249. ; Statement INLINE
  15250. ;
  15251. l5698:
  15252.         call    l6f66           ; Verify (
  15253. l569b:
  15254.         ld      a,'>'
  15255.         call    l6f29
  15256.         ld      a,2
  15257.         jr      z,l56ae
  15258.         ld      a,'<'
  15259.         call    l6f29
  15260.         ld      a,1
  15261.         jr      z,l56ae
  15262.         xor     a
  15263. l56ae:
  15264.         ld      (l7ba6),a
  15265.         xor     a
  15266.         ld      h,a
  15267.         ld      l,a
  15268.         ld      b,a
  15269. l56b5:
  15270.         push    bc
  15271.         push    hl
  15272.         call    l6a0d           ; Get constant
  15273.         jr      nz,l56c5
  15274.         ld      a,b
  15275.         cp      0ah
  15276.         jr      z,l5702
  15277.         call    l72e1
  15278.         db      _IntConst
  15279. l56c5:
  15280.         ld      hl,l7ba6
  15281.         ld      a,(hl)
  15282.         or      a
  15283.         jr      nz,l56ce
  15284.         ld      (hl),2
  15285. l56ce:
  15286.         ld      a,'*'
  15287.         call    l6f29
  15288.         jr      nz,l56da
  15289.         push    iy
  15290.         pop     hl
  15291.         jr      l5702
  15292. l56da:
  15293.         ld      bc,256*4+0
  15294.         call    l6e54
  15295.         jr      nz,l56ea
  15296.         call    l5276
  15297.         ld      hl,(l7b58)      ; Get value
  15298.         jr      l5702
  15299. l56ea:
  15300.         ld      bc,256*5+0
  15301.         call    l6e54
  15302.         jr      z,l56fc
  15303.         ld      bc,256*6+0
  15304.         call    l6e54
  15305.         call    l72da
  15306.         db      _IllINLINE
  15307. l56fc:
  15308.         dec     hl
  15309.         dec     hl
  15310.         ld      d,(hl)
  15311.         dec     hl
  15312.         ld      e,(hl)
  15313.         ex      de,hl
  15314. l5702:
  15315.         pop     de
  15316.         pop     bc
  15317.         dec     b
  15318.         jr      nz,l570a
  15319.         call    l6a30
  15320. l570a:
  15321.         add     hl,de
  15322.         ld      b,0
  15323.         ld      a,'+'
  15324.         call    l6f29
  15325.         jr      z,l56b5
  15326.         inc     b
  15327.         ld      a,'-'
  15328.         call    l6f29
  15329.         jr      z,l56b5
  15330.         ld      a,(l7ba6)
  15331.         cp      1
  15332.         jr      z,l5729
  15333.         jr      nc,l572f
  15334.         inc     h
  15335.         dec     h
  15336.         jr      nz,l572f
  15337. l5729:
  15338.         ld      a,l             ; Get byte
  15339.         call    writebyte_a_addriy              ; Store it
  15340.         jr      l5732
  15341. l572f:
  15342.         call    writeword_hl_addriy
  15343. l5732:
  15344.         ld      a,'/'
  15345.         call    l6f29
  15346.         jp      z,l569b
  15347.         jp      l6f6e           ; Verify )
  15348. l573d:
  15349.         dec     hl
  15350.         ld      b,(hl)
  15351.         dec     hl
  15352.         ld      d,(hl)
  15353.         dec     hl
  15354.         ld      e,(hl)
  15355.         dec     hl
  15356.         push    de
  15357.         ld      d,(hl)
  15358.         dec     hl
  15359.         ld      e,(hl)
  15360.         dec     hl
  15361.         push    de
  15362.         dec     hl
  15363.         dec     hl
  15364.         ld      d,(hl)
  15365.         dec     hl
  15366.         ld      e,(hl)
  15367.         dec     hl
  15368.         push    de
  15369.         ld      d,(hl)
  15370.         dec     hl
  15371.         ld      e,(hl)
  15372.         dec     hl
  15373.         push    de
  15374.         inc     b
  15375.         dec     b
  15376.         jp      z,l57d6
  15377.         call    l6f66           ; Verify (
  15378. l575e:
  15379.         push    bc
  15380.         ld      b,(hl)
  15381.         dec     hl
  15382.         ld      a,(hl)
  15383.         dec     hl
  15384.         ld      (l7b57),a
  15385.         ld      d,(hl)
  15386.         dec     hl
  15387.         ld      e,(hl)
  15388.         dec     hl
  15389.         ld      c,b
  15390. l576b:
  15391.         bit     7,(hl)
  15392.         dec     hl
  15393.         jr      z,l576b
  15394.         djnz    l576b
  15395.         ld      b,c
  15396.         push    hl
  15397.         ex      de,hl
  15398.         call    l5287           ; Get name
  15399. l5778:
  15400.         push    bc
  15401.         ld      a,(l7b57)
  15402.         or      a
  15403.         jr      nz,l57a9
  15404.         ld      a,(l7b5c)       ; Get type
  15405.         cp      _Set
  15406.         jr      c,l57a1
  15407.         call    l5e84
  15408.         call    l5864
  15409.         ld      a,(l7b5c)       ; Get type
  15410.         cp      _Ptr
  15411.         jr      z,l57bd
  15412.         cp      _Real
  15413.         jr      c,l57c0
  15414.         jr      nz,l57bd
  15415.         call    l6b50           ; Set sequence
  15416.         db      a_L20
  15417. s_I20:
  15418.         PUSH    BC
  15419.         PUSH    DE
  15420. a_L20   equ     $-s_I20
  15421.         jr      l57bd
  15422. l57a1:
  15423.         call    l6d2a           ; Save environment
  15424.         call    l6749
  15425.         jr      l57af
  15426. l57a9:
  15427.         call    l6d2a           ; Save environment
  15428.         call    l677f
  15429. l57af:
  15430.         call    l6d5d
  15431.         ld      a,(l7b69)
  15432.         cp      0
  15433.         call    nz,l58c5
  15434.         call    l6d49           ; Get back environment
  15435. l57bd:
  15436.         call    l6b6f           ; Set PUSH HL
  15437. l57c0:
  15438.         pop     bc
  15439.         dec     b
  15440.         jr      z,l57c9
  15441.         call    l6f5e           ; Verify ,
  15442.         jr      l5778
  15443. l57c9:
  15444.         pop     hl
  15445.         pop     bc
  15446.         dec     b
  15447.         jr      z,l57d3
  15448.         call    l6f5e           ; Verify ,
  15449.         jr      l575e
  15450. l57d3:
  15451.         call    l6f6e           ; Verify )
  15452. l57d6:
  15453.         pop     de
  15454.         pop     hl
  15455.         ld      a,d
  15456.         or      e
  15457.         jr      z,l57e3
  15458.         call    l6b92           ; Set LD HL,val16
  15459.         ex      de,hl
  15460.         call    l6b8e           ; Set LD DE,val16
  15461. l57e3:
  15462.         pop     de
  15463.         pop     hl
  15464.         ld      a,_CALL
  15465.         jp      l6b94
  15466. l57ea:
  15467.         ld      a,(l7b5c)       ; Get type
  15468.         cp      0
  15469.         jr      z,l57f9
  15470.         cp      _RecF
  15471.         jr      c,l57fd
  15472.         cp      _String
  15473.         jr      nc,l57fd
  15474. l57f9:
  15475.         call    l72e1
  15476.         db      _IllAss
  15477. l57fd:
  15478.         ld      a,(l7bbd)
  15479.         bit     1,a
  15480.         jr      nz,l5812
  15481.         bit     0,a
  15482.         jr      z,l580a
  15483.         ld      a,0ffh
  15484. l580a:
  15485.         ld      hl,(l7bbe)
  15486.         ld      (l7b58),hl      ; Set value
  15487.         jr      l581a
  15488. l5812:
  15489.         call    l678b
  15490.         call    l6b6f           ; Set PUSH HL
  15491.         ld      a,1
  15492. l581a:
  15493.         ld      (l7b57),a
  15494.         call    l6f7e
  15495.         ld      a,(l7b5c)       ; Get type
  15496.         cp      _Set
  15497.         jp      nc,l593a
  15498.         call    l6d2a           ; Save environment
  15499.         call    l6749
  15500.         call    l6d43
  15501.         call    l58c5
  15502.         ld      a,(l7b64)
  15503.         dec     a
  15504.         jr      z,l5852
  15505.         inc     a
  15506.         jr      z,l5845
  15507.         call    l6b50           ; Set LD DE,(adr)
  15508.         db      a_L21
  15509. s_I21:
  15510.         dw      _LD_a_DE
  15511. a_L21   equ     $-s_I21
  15512.         jr      l584a
  15513. l5845:
  15514.         call    l6b50
  15515.         db      a_L22
  15516. s_I22:
  15517.         db      _LD.DE          ; Set LD DE,adr
  15518. a_L22   equ     $-s_I22
  15519. l584a:
  15520.         ld      hl,(l7b65)
  15521.         call    writeword_hl_addriy
  15522.         jr      l5857
  15523. l5852:
  15524.         call    l6b50           ; Set POP DE
  15525.         db      a_L23
  15526. s_I23:
  15527.         pop     de
  15528. a_L23   equ     $-s_I23
  15529. l5857:
  15530.         ld      hl,(l7b6f)
  15531.         call    l6b8a
  15532.         call    l6b50           ; Set LDIR
  15533.         db      a_L24
  15534. s_I24:
  15535.         LDIR
  15536. a_L24   equ     $-s_I24
  15537.         ret
  15538. l5864:
  15539.         ld      a,(l7b5c)       ; Get type
  15540.         cp      _Real
  15541.         jr      nz,l5877
  15542.         ld      a,b
  15543.         cp      _Integ
  15544.         jr      nz,l589d
  15545.         ld      b,9
  15546.         ld      hl,l1008
  15547.         jr      l589a
  15548. l5877:
  15549.         cp      _String
  15550.         jr      nz,l588c
  15551.         ld      a,b
  15552.         cp      _Char
  15553.         jr      nz,l589d
  15554.         ld      b,8
  15555.         call    l6b50           ; Set sequence
  15556.         db      a_L25
  15557. s_I25:
  15558.         LD      H,L
  15559.         LD      L,1
  15560.         PUSH    HL
  15561. a_L25   equ     $-s_I25
  15562.         jr      l589d
  15563. l588c:
  15564.         cp      _Char
  15565.         jr      nz,l589d
  15566.         ld      a,b
  15567.         cp      _String
  15568.         jr      nz,l589d
  15569.         ld      b,0ch
  15570.         ld      hl,l0996        ; Set check assignment
  15571. l589a:
  15572.         call    l6b86           ; Set CALL <check>
  15573. l589d:
  15574.         ld      a,(l7b5c)       ; Get type
  15575.         cp      b
  15576.         jr      nz,l58c1
  15577.         cp      3
  15578.         jr      nz,l58b1
  15579.         ld      a,c
  15580.         or      a
  15581.         ret     z
  15582.         ld      hl,(l7b5e)      ; Get lo set limit
  15583.         cp      (hl)
  15584.         ret     z
  15585.         jr      l58c1
  15586. l58b1:
  15587.         cp      4
  15588.         ret     nz
  15589.         ld      hl,(l7b8b)
  15590.         ld      a,h
  15591.         or      l
  15592.         ret     z
  15593.         ld      de,(l7b5e)      ; Get lo set limit
  15594.         sbc     hl,de
  15595.         ret     z
  15596. l58c1:
  15597.         call    l72e1
  15598.         db      _InvType
  15599. l58c5:
  15600.         ld      a,(l7b5c)       ; Get type
  15601.         cp      0
  15602.         jr      z,l591b
  15603.         ld      c,0bfh
  15604.         cp      _Integ
  15605.         jr      nc,l5906
  15606.         ld      c,83h
  15607.         cp      _String
  15608.         jr      nz,l58e3
  15609.         ld      a,(l7b9e)       ; Get local options
  15610.         bit     _Vopt,a         ; Test $V+
  15611.         jr      nz,l5906        ; Yeap
  15612.         ld      c,80h
  15613.         jr      l5906
  15614. l58e3:
  15615.         cp      _TxtF
  15616.         jr      nc,l5906
  15617.         ld      c,0b3h
  15618.         cp      _Set
  15619.         jr      nc,l5906
  15620.         ld      c,0c3h
  15621.         cp      _Record
  15622.         jr      nc,l5906
  15623.         ld      hl,(l7b60)      ; Get hi set limit
  15624.         ld      a,h
  15625.         or      l
  15626.         ld      c,0bfh
  15627.         jr      nz,l5906
  15628.         ld      hl,(l7b6d)      ; Get last memory address
  15629.         ld      a,(hl)
  15630.         cp      0ah
  15631.         jr      nz,l591b
  15632.         ld      c,0b3h
  15633. l5906:
  15634.         ld      hl,l7b5c        ; Point to type
  15635.         ld      de,l7b69
  15636.         ld      b,8
  15637. l590e:
  15638.         rl      c
  15639.         jr      nc,l5916
  15640.         ld      a,(de)
  15641.         cp      (hl)
  15642.         jr      nz,l591b
  15643. l5916:
  15644.         inc     hl
  15645.         inc     de
  15646.         djnz    l590e
  15647.         ret
  15648. l591b:
  15649.         call    l72e1
  15650.         db      _InvType
  15651. l591f:
  15652.         ld      de,lfffc
  15653.         add     hl,de
  15654.         ld      d,(hl)
  15655.         dec     hl
  15656.         ld      e,(hl)
  15657.         dec     hl
  15658.         push    de
  15659.         ld      d,(hl)
  15660.         dec     hl
  15661.         ld      e,(hl)
  15662.         ld      (l7b58),de      ; Set value
  15663.         pop     hl
  15664.         call    l5287           ; Get name
  15665.         xor     a
  15666.         ld      (l7b57),a
  15667.         call    l6f7e
  15668. l593a:
  15669.         call    l5e84
  15670.         call    l5864
  15671.         jp      l661b
  15672. ;
  15673. ; Procedure ASSIGN(FileVar,String)
  15674. ;
  15675. l5943:
  15676.         call    l5a0c
  15677.         ld      hl,l1370
  15678.         cp      6
  15679.         jr      nz,l5955
  15680.         ld      hl,l136f
  15681.         call    l5955
  15682.         jr      l5989
  15683. l5955:
  15684.         push    hl
  15685.         call    l6b6f           ; Set PUSH HL
  15686.         call    l6f5e           ; Verify ,
  15687.         call    l5ed0
  15688.         pop     hl
  15689. l5960:
  15690.         call    l6f6e           ; Verify )
  15691.         jp      l6b86           ; Set CALL <...>
  15692. ;
  15693. ; Procedure RENAME(FileVar,String)
  15694. ;
  15695. l5966:
  15696.         call    l5a0c
  15697.         ld      hl,l1ba5
  15698.         call    l5955
  15699.         jr      l5989
  15700. ;
  15701. ; Procedure ERASE(FileVar)
  15702. ;
  15703. l5971:
  15704.         call    l5a0c
  15705.         ld      hl,l1b93
  15706.         jr      l5960
  15707. ;
  15708. ; Procedure CHAIN(FileVar)
  15709. ;
  15710. l5979:
  15711.         ld      hl,l1beb
  15712.         jr      l5981
  15713. ;
  15714. ; Procedure EXECUTE(FileVar)
  15715. ;
  15716. l597e:
  15717.         ld      hl,l1bea
  15718. l5981:
  15719.         push    hl
  15720.         call    l5a0c
  15721. l5985:
  15722.         pop     hl
  15723. l5986:
  15724.         call    l5960
  15725. l5989:
  15726.         jp      l5abe
  15727. ;
  15728. ; Procedure SEEK(FileVar,Integer)
  15729. ;
  15730. l598c:
  15731.         call    l5a0c
  15732.         cp      6
  15733.         call    l72d4
  15734.         db      _IllTxtFile
  15735.         ld      hl,l19d5
  15736.         cp      5
  15737.         jr      z,l599f
  15738.         ld      hl,l1b6f
  15739. l599f:
  15740.         push    hl
  15741.         call    l6b6f           ; Set PUSH HL
  15742.         call    l6f5e           ; Verify ,
  15743.         call    l5e97
  15744.         jr      l5985
  15745. ;
  15746. ; Procedure FLUSH(FileVar)
  15747. ;
  15748. l59ab:
  15749.         call    l5a0c
  15750.         cp      5
  15751.         call    l72da
  15752.         db      _IllFileType
  15753.         ld      hl,l19a5
  15754.         jr      l5986
  15755. ;
  15756. ; Procedure RESET(FileVar,String)
  15757. ;
  15758. l59b9:
  15759.         ld      hl,l59fa
  15760.         jr      l59c1
  15761. ;
  15762. ; Procedure REWRITE(FileVar,String)
  15763. ;
  15764. l59be:
  15765.         ld      hl,l5a00
  15766. l59c1:
  15767.         push    hl
  15768.         call    l5a0c
  15769.         ld      a,(l7b5c)       ; Get type
  15770.         cp      _RecF
  15771.         jr      nz,l59d8
  15772.         ld      hl,(l7b5e)      ; Get lo set limit
  15773.         call    l5271           ; Load name
  15774.         ld      hl,(l7b6f)
  15775.         call    l6b8e           ; Set LD DE,val16
  15776. l59d8:
  15777.         pop     hl
  15778.         jr      l59e1
  15779. ;
  15780. ; Procedure CLOSE(FileVar)
  15781. ;
  15782. l59db:
  15783.         call    l5a0c
  15784.         ld      hl,l5a06
  15785. l59e1:
  15786.         call    l6f6e           ; Verify )
  15787.         call    l59e9
  15788.         jr      l5989
  15789. l59e9:
  15790.         ld      a,(l7b5c)       ; Get type
  15791.         sub     _RecF
  15792.         add     a,a
  15793.         ld      e,a
  15794.         ld      d,0
  15795.         add     hl,de
  15796.         ld      e,(hl)
  15797.         inc     hl
  15798.         ld      d,(hl)
  15799.         ex      de,hl
  15800.         jp      l6b86           ; Set CALL <...>
  15801. l59fa:
  15802.         dw      l1811           ; Record file
  15803.         dw      l13ff           ; Text file
  15804.         dw      l1a70           ; Untyped file
  15805. l5a00:
  15806.         dw      l1810
  15807.         dw      l13fe
  15808.         dw      l1a6f
  15809. l5a06:
  15810.         dw      l187a
  15811.         dw      l1469
  15812.         dw      l1ab0
  15813. l5a0c:
  15814.         call    l6f66           ; Verify (
  15815.         call    l5a17
  15816.         ret     z
  15817.         call    l72e1
  15818.         db      _FileVarExp
  15819. l5a17:
  15820.         call    l67b2
  15821.         scf
  15822.         ret     nz
  15823.         ld      a,(l7b5c)       ; Get type
  15824.         cp      _RecF
  15825.         jr      c,l5a2f
  15826.         cp      _String
  15827.         jr      nc,l5a2f
  15828.         call    l678b
  15829.         xor     a
  15830.         ld      a,(l7b5c)       ; Get back type
  15831.         ret
  15832. l5a2f:
  15833.         xor     a
  15834.         dec     a
  15835.         ret
  15836. ;
  15837. ; Procedure READLN(FileVar,Variables)
  15838. ;
  15839. l5a32:
  15840.         db      skip
  15841. ;
  15842. ; Procedure READ(FileVar,Variables)
  15843. ;
  15844. l5a33:
  15845.         xor     a
  15846.         ld      (l7ba3),a
  15847.         call    l6f1b           ; Test (
  15848.         jr      z,l5a41         ; Yeap
  15849.         call    l5aca
  15850.         jr      l5ab4
  15851. l5a41:
  15852.         call    l5a17
  15853.         jr      c,l5a63
  15854.         jr      nz,l5a5b
  15855.         cp      5
  15856.         jp      z,l5bd8
  15857.         cp      6
  15858.         call    l72da
  15859.         db      _NoUntypeFile
  15860.         ld      hl,l14a9
  15861.         call    l6b86           ; Set CALL FILECHECK
  15862.         jr      l5aac
  15863. l5a5b:
  15864.         call    l678b
  15865.         call    l5aca
  15866.         jr      l5a69
  15867. l5a63:
  15868.         call    l5aca
  15869. l5a66:
  15870.         call    l677f
  15871. l5a69:
  15872.         ld      a,(l7b5c)       ; Get type
  15873.         cp      _String
  15874.         jr      c,l5a78
  15875.         cp      _Bool
  15876.         jr      z,l5a78
  15877.         cp      _Char+1
  15878.         jr      c,l5a7c
  15879. l5a78:
  15880.         call    l72e1
  15881.         db      _InvIO
  15882. l5a7c:
  15883.         cp      _String
  15884.         jr      nz,l5a8f
  15885.         ld      a,(l7b62)       ; Get length of type
  15886.         dec     a
  15887.         ld      h,a
  15888.         ld      l,6
  15889.         call    writeword_hl_addriy
  15890.         ld      hl,l168e
  15891.         jr      l5aa9
  15892. l5a8f:
  15893.         ld      hl,l1672
  15894.         cp      _Real
  15895.         jr      z,l5aa9
  15896.         ld      hl,l1644
  15897.         cp      _Char
  15898.         jr      z,l5aa9
  15899.         ld      hl,l164e
  15900.         ld      a,(l7b62)       ; Get length of type
  15901.         dec     a
  15902.         jr      nz,l5aa9
  15903.         ld      hl,l164d
  15904. l5aa9:
  15905.         call    l6b86           ; Set CALL <read>
  15906. l5aac:
  15907.         call    l6f13           ; Test ,
  15908.         jr      z,l5a66         ; Yeap
  15909.         call    l6f6e           ; Verify )
  15910. l5ab4:
  15911.         ld      hl,l16ab
  15912. l5ab7:
  15913.         ld      a,(l7ba3)
  15914.         or      a
  15915.         call    nz,l6b86        ; Set CALL NEWLINE
  15916. l5abe:
  15917.         ld      a,(l7b9e)       ; Get local options
  15918.         bit     _Iopt,a         ; Test $I+
  15919.         ret     z               ; Nope
  15920.         ld      hl,l201b
  15921.         jp      l6b86           ; Set CALL CHECKIO
  15922. l5aca:
  15923.         ld      hl,l149b
  15924.         ld      a,(l7b9e)       ; Get local options
  15925.         bit     _Bopt,a         ; Test $B+
  15926.         jr      z,l5ae4         ; Nope
  15927.         ld      hl,l14cc
  15928.         ld      a,(l7ba3)
  15929.         or      a
  15930.         jr      z,l5ae4
  15931.         ld      hl,l14cb
  15932.         xor     a
  15933.         ld      (l7ba3),a
  15934. l5ae4:
  15935.         jp      l6b86           ; Set CALL <read>
  15936. ;
  15937. ; Procedure WRITELN(FileVar,Variables)
  15938. ;
  15939. l5ae7:
  15940.         db      skip
  15941. ;
  15942. ; Procedure WRITE(FileVar,Variables)
  15943. ;
  15944. l5ae8:
  15945.         xor     a
  15946.         ld      (l7ba3),a
  15947.         call    l6f1b           ; Test (
  15948.         jr      z,l5afa         ; Yeap
  15949.         ld      hl,l149b
  15950.         call    l6b86           ; Set CALL STDIO
  15951.         jp      l5bd2
  15952. l5afa:
  15953.         call    l5a17
  15954.         jr      c,l5b20
  15955.         jr      nz,l5b15
  15956.         cp      5
  15957.         jp      z,l5bdd
  15958.         cp      6
  15959.         call    l72da
  15960.         db      _NoUntypeFile
  15961.         ld      hl,l14ba
  15962.         call    l6b86           ; Set CALL CHECKWRFILE
  15963.         jp      l5bc9
  15964. l5b15:
  15965.         call    l620f
  15966.         ld      hl,l149b
  15967.         call    l6b86           ; Set CALL STDIO
  15968.         jr      l5b4f
  15969. l5b20:
  15970.         ld      hl,l149b
  15971.         call    l6b86           ; Set CALL STDIO
  15972. l5b26:
  15973.         call    l6a5c
  15974.         jr      nz,l5b4c
  15975.         ld      a,b
  15976.         cp      8 ;_String???
  15977.         jr      nz,l5b47
  15978.         ld      a,(ix+0)
  15979.         cp      ','
  15980.         jr      z,l5b3b
  15981.         cp      ')'
  15982.         jr      nz,l5b47
  15983. l5b3b:
  15984.         ld      hl,l17ba
  15985.         call    l6b86           ; Set CALL IMSTRG
  15986.         call    l6b5e
  15987.         jp      l5bc9
  15988. l5b47:
  15989.         call    l6201
  15990.         jr      l5b4f
  15991. l5b4c:
  15992.         call    l5ee8
  15993. l5b4f:
  15994.         ld      a,b
  15995.         cp      8 ;0..7: _Array,_Record,_Set,_Ptr,_RecF,_TxtF,_UntF
  15996.         jr      c,l5b58 ;not a scalar type???
  15997.         cp      0dh ;element of a set???
  15998.         jr      c,l5b5c ;8..12: (_String excluded above),_Real,_Integ,_Bool,_Char
  15999. l5b58:
  16000.         call    l72e1
  16001.         db      _InvIO
  16002. l5b5c:
  16003.         cp      0ch ;_Char???
  16004.         jr      nz,l5b6a
  16005.         call    l6f0b           ; Test :
  16006.         jr      nz,l5ba6
  16007.         call    l5edd
  16008.         jr      l5b72
  16009. l5b6a:
  16010.         call    l6148
  16011.         call    l6f0b           ; Test :
  16012.         jr      nz,l5b8b
  16013. l5b72:
  16014.         push    bc
  16015.         call    l5e97
  16016.         pop     bc
  16017.         ld      a,b
  16018.         cp      9 ;_Real???
  16019.         jr      nz,l5ba6
  16020.         call    l6f0b           ; Test :
  16021.         jr      nz,l5b9d
  16022.         push    bc
  16023.         call    l6b6f           ; Set PUSH HL
  16024.         call    l5e97
  16025.         pop     bc
  16026.         jr      l5ba6
  16027. l5b8b:
  16028.         ld      hl,l0000
  16029.         ld      a,b
  16030.         cp      9 ;_Real???
  16031.         jr      nz,l5b95
  16032.         ld      l,12h
  16033. l5b95:
  16034.         call    l6b92           ; Set LD HL,val16
  16035.         ld      a,b
  16036.         cp      9 ;_Real???
  16037.         jr      nz,l5ba6
  16038. l5b9d:
  16039.         call    l6b6f           ; Set PUSH HL
  16040.         ld      hl,lffff
  16041.         call    l6b92           ; Set LD HL,val16
  16042. l5ba6:
  16043.         ld      a,b
  16044.         ld      hl,l17aa
  16045.         cp      8 ;_String???
  16046.         jr      z,l5bc6
  16047.         ld      hl,l1779
  16048.         cp      9 ;_Real???
  16049.         jr      z,l5bc6
  16050.         ld      hl,l1726
  16051.         cp      0ah ;_Integ???
  16052.         jr      z,l5bc6
  16053.         ld      hl,l178b
  16054.         cp      0bh ;_Bool???
  16055.         jr      z,l5bc6
  16056.         ld      hl,l1722
  16057. l5bc6:
  16058.         call    l6b86           ; Set CALL <wrtype>
  16059. l5bc9:
  16060.         call    l6f13           ; Test ,
  16061.         jp      z,l5b26         ; Yeap
  16062.         call    l6f6e           ; Verify )
  16063. l5bd2:
  16064.         ld      hl,l17cd
  16065.         jp      l5ab7
  16066. l5bd8:
  16067.         ld      hl,l18b6
  16068.         jr      l5be0
  16069. l5bdd:
  16070.         ld      hl,l18dc
  16071. l5be0:
  16072.         ld      (l7ba7),hl
  16073.         ld      a,(l7ba3)
  16074.         or      a
  16075.         call    l72da
  16076.         db      _MustTextFile
  16077.         ld      hl,l18a4
  16078.         call    l6b86           ; Set CALL PREPRECWR
  16079.         ld      hl,(l7b5e)      ; Get lo set limit
  16080.         call    l5271           ; Load name
  16081. l5bf7:
  16082.         call    l6f13           ; Test ,
  16083.         jr      nz,l5c10        ; Nope
  16084.         call    l6d24
  16085.         call    l677f
  16086.         call    l6d43
  16087.         call    l58c5
  16088.         ld      hl,(l7ba7)
  16089.         call    l6b86           ; Set CALL <write>
  16090.         jr      l5bf7
  16091. l5c10:
  16092.         call    l6f6e           ; Verify )
  16093.         jp      l5abe
  16094. ;
  16095. ; Procedure BLOCKREAD(FileVar,Variable,Integer[,Integer])
  16096. ;
  16097. l5c16:
  16098.         ld      hl,l1af1
  16099.         ld      de,l1abe
  16100.         jr      l5c24
  16101. ;
  16102. ; Procedure BLOCKWRITE(FileVar,Variable,Integer[,Integer])
  16103. ;
  16104. l5c1e:
  16105.         ld      hl,l1aed
  16106.         ld      de,l1aba
  16107. l5c24:
  16108.         push    hl
  16109.         push    de
  16110.         call    l5a0c
  16111.         cp      7
  16112.         call    l72da
  16113.         db      _UntFileExp
  16114.         call    l6b6f           ; Set PUSH HL
  16115.         call    l6f5e           ; Verify ,
  16116.         call    l677f
  16117.         call    l6b6f           ; Set PUSH HL
  16118.         call    l6f5e           ; Verify ,
  16119.         call    l5e97
  16120.         call    l6f13           ; Test ,
  16121.         pop     de
  16122.         pop     hl
  16123.         jr      z,l5c4b         ; Yeap
  16124.         push    de
  16125.         jr      l5c63
  16126. l5c4b:
  16127.         push    hl
  16128.         call    l6b6f           ; Set PUSH HL
  16129.         call    l677f
  16130.         ld      a,(l7b5c)       ; Get type
  16131.         cp      _Integ
  16132.         jr      nz,l5c5f
  16133.         ld      a,(l7b62)       ; Get length of type
  16134.         dec     a
  16135.         jr      nz,l5c63
  16136. l5c5f:
  16137.         call    l72e1
  16138.         db      _IntVarExp
  16139. l5c63:
  16140.         jp      l5985
  16141. ;
  16142. ; Procedure DELETE(String,Integer,Integer)
  16143. ;
  16144. l5c66:
  16145.         call    l6f66           ; Verify (
  16146.         call    l5cad
  16147.         call    l6b6f           ; Set PUSH HL
  16148.         call    l6f5e           ; Verify ,
  16149.         call    l5e97
  16150.         call    l6b6f           ; Set PUSH HL
  16151.         call    l6f5e           ; Verify ,
  16152.         call    l5e97
  16153.         ld      hl,l08f3        ; Set DELETE
  16154. l5c81:
  16155.         call    l6f6e           ; Verify )
  16156.         jp      l6b86           ; Set CALL <string_procedure>
  16157. ;
  16158. ; Procedure INSERT(String,String,Integer)
  16159. ;
  16160. l5c87:
  16161.         call    l6f66           ; Verify (
  16162.         call    l5ed0
  16163.         call    l6f5e           ; Verify ,
  16164.         call    l5cad
  16165.         call    l6b6f           ; Set PUSH HL
  16166.         ld      a,(l7b62)       ; Get length of type
  16167.         dec     a
  16168.         ld      h,a
  16169.         ld      l,6
  16170.         push    hl
  16171.         call    l6f5e           ; Verify ,
  16172.         call    l5e97
  16173.         pop     hl
  16174.         call    writeword_hl_addriy
  16175.         ld      hl,l0920
  16176.         jr      l5c81           ; Set INSERT
  16177. l5cad:
  16178.         call    l677f
  16179.         ld      a,(l7b5c)       ; Get type
  16180.         cp      _String
  16181.         ret     z
  16182.         call    l72e1
  16183.         db      _StrgVarExp
  16184. ;
  16185. ; Procedure STR(Num,String)
  16186. ;
  16187. l5cba:
  16188.         call    l6f66           ; Verify (
  16189.         call    l5ea2
  16190.         call    l6148
  16191.         call    l6f0b           ; Test :
  16192.         jr      nz,l5ce4
  16193.         push    bc
  16194.         call    l5e97
  16195.         call    l6b6f           ; Set PUSH HL
  16196.         pop     bc
  16197.         ld      a,b
  16198.         cp      0ah
  16199.         jr      z,l5d02
  16200.         call    l6f0b           ; Test :
  16201.         jr      nz,l5cf9
  16202.         push    bc
  16203.         call    l5e97
  16204.         call    l6b6f           ; Set PUSH HL
  16205.         pop     bc
  16206.         jr      l5d02
  16207. l5ce4:
  16208.         ld      hl,l0000
  16209.         ld      a,b
  16210.         cp      0ah
  16211.         jr      z,l5cee
  16212.         ld      l,12h
  16213. l5cee:
  16214.         call    l6b92           ; Set LD HL,val16
  16215.         call    l6b6f           ; Set PUSH HL
  16216.         ld      a,b
  16217.         cp      0ah
  16218.         jr      z,l5d02
  16219. l5cf9:
  16220.         ld      hl,lffff
  16221.         call    l6b92           ; Set LD HL,val16
  16222.         call    l6b6f           ; Set PUSH HL
  16223. l5d02:
  16224.         call    l6f5e           ; Verify ,
  16225.         push    bc
  16226.         call    l5cad
  16227.         ld      a,(l7b62)       ; Get length of type
  16228.         dec     a
  16229.         ld      h,a
  16230.         ld      l,6
  16231.         call    writeword_hl_addriy
  16232.         pop     bc
  16233.         ld      hl,l1ebe
  16234.         ld      a,b
  16235.         cp      0ah
  16236.         jr      z,l5d1f
  16237.         ld      hl,l1ebd
  16238. l5d1f:
  16239.         jp      l5c81
  16240. ;
  16241. ; Procedure VAL(String,Integer,Integer)
  16242. ;
  16243. l5d22:
  16244.         call    l6f66           ; Verify (
  16245.         call    l5ed0
  16246.         call    l6f5e           ; Verify ,
  16247.         call    l677f
  16248.         ld      a,(l7b5c)       ; Get type
  16249.         cp      _Real
  16250.         jr      z,l5d45
  16251.         cp      _Integ
  16252.         jr      nz,l5d41
  16253.         ld      a,(l7b62)       ; Get length of type
  16254.         dec     a
  16255.         ld      a,0ah
  16256.         jr      nz,l5d45
  16257. l5d41:
  16258.         call    l72e1
  16259.         db      _NumVarExp
  16260. l5d45:
  16261.         push    af
  16262.         call    l6b6f           ; Set PUSH HL
  16263.         call    l6f5e           ; Verify ,
  16264.         call    l677f
  16265.         ld      a,(l7b5c)       ; Get type
  16266.         cp      _Integ
  16267.         jr      nz,l5d5c
  16268.         ld      a,(l7b62)       ; Get length of type
  16269.         dec     a
  16270.         jr      nz,l5d60
  16271. l5d5c:
  16272.         call    l72e1
  16273.         db      _IntVarExp
  16274. l5d60:
  16275.         pop     af
  16276.         ld      hl,l1ef4
  16277.         cp      0ah
  16278.         jr      z,l5d1f
  16279.         ld      hl,l1ef3
  16280.         jr      l5d1f
  16281. ;
  16282. ; Procedure GOTOXY(Integer,Integer)
  16283. ;
  16284. l5d6d:
  16285.         call    l6f66           ; Verify (
  16286.         call    l5e97
  16287.         ld      hl,l1fdb
  16288. l5d76:
  16289.         push    hl
  16290.         call    l6b6f           ; Set PUSH HL
  16291.         call    l6f5e           ; Verify ,
  16292.         call    l5e97
  16293.         pop     hl
  16294.         jr      l5db1
  16295. ;
  16296. ; Procedure RANDOMIZE
  16297. ;
  16298. l5d83:
  16299.         ld      hl,l1f48
  16300.         jp      l6b86           ; Set CALL RANDOMIZE
  16301. ;
  16302. ; Procedure DELAY(Integer)
  16303. ;
  16304. l5d89:
  16305.         call    l6f66           ; Verify (
  16306.         call    l5e97
  16307.         ld      hl,l021d
  16308.         jr      l5db1           ; Set call to delay
  16309. ;
  16310. ; Procedure GETMEM(Variable,Integer)
  16311. ;
  16312. l5d94:
  16313.         call    l5de3
  16314.         call    l6f5e           ; Verify ,
  16315.         call    l5e97
  16316.         jr      l5dae
  16317. ;
  16318. ; Procedure NEW(Variable)
  16319. ;
  16320. l5d9f:
  16321.         call    l5de3
  16322.         ld      hl,(l7b5e)      ; Get lo set limit
  16323.         call    l5271           ; Load name
  16324.         ld      hl,(l7b6f)
  16325.         call    l6b92           ; Set LD HL,val16
  16326. l5dae:
  16327.         ld      hl,l1ce5
  16328. l5db1:
  16329.         jp      l5960
  16330. ;
  16331. ; Procedure FREEMEM(Variable,Integer)
  16332. ;
  16333. l5db4:
  16334.         call    l5de3
  16335.         call    l6f5e           ; Verify ,
  16336.         call    l5e97
  16337.         jr      l5dce
  16338. ;
  16339. ; Procedure DISPOSE(Variable)
  16340. ;
  16341. l5dbf:
  16342.         call    l5de3
  16343.         ld      hl,(l7b5e)      ; Get lo set limit
  16344.         call    l5271           ; Load name
  16345.         ld      hl,(l7b6f)
  16346.         call    l6b92           ; Set LD HL,val16
  16347. l5dce:
  16348.         ld      hl,l1d7a
  16349.         jp      l5960
  16350. ;
  16351. ; Procedure MARK(Variable)
  16352. ;
  16353. l5dd4:
  16354.         ld      hl,l1ea3
  16355.         jr      l5ddc
  16356. ;
  16357. ; Procedure RELEASE(Variable)
  16358. ;
  16359. l5dd9:
  16360.         ld      hl,l1eab
  16361. l5ddc:
  16362.         push    hl
  16363.         call    l5de9
  16364.         pop     hl
  16365.         jr      l5db1
  16366. l5de3:
  16367.         call    l5de9
  16368.         jp      l6b6f           ; Set PUSH HL
  16369. l5de9:
  16370.         call    l6f66           ; Verify (
  16371.         call    l677f
  16372.         ld      a,(l7b5c)       ; Get type
  16373.         cp      _Ptr
  16374.         ret     z
  16375.         call    l72e1
  16376.         db      _PtrVarExp
  16377. ;
  16378. ; Procedure OVRDRIVE(Integer)
  16379. ;
  16380. l5df9:
  16381.         call    l6f66           ; Verify (
  16382.         call    l5e97
  16383.         ld      hl,l1cdb
  16384.         jp      l5960
  16385. ;
  16386. ; Procedure MOVE(Integer,Integer,Integer)
  16387. ;
  16388. l5e05:
  16389.         call    l6f66           ; Verify (
  16390.         call    l677f
  16391.         call    l6b6f           ; Set PUSH HL
  16392.         call    l6f5e           ; Verify ,
  16393.         call    l677f
  16394.         ld      hl,l1f64
  16395.         jp      l5d76
  16396. ;
  16397. ; Procedure FILLCHAR(Integer,Integer,Byte)
  16398. ;
  16399. l5e1a:
  16400.         call    l6f66           ; Verify (
  16401.         call    l677f
  16402.         call    l6b6f           ; Set PUSH HL
  16403.         call    l6f5e           ; Verify ,
  16404.         call    l5e97
  16405.         call    l6b6f           ; Set PUSH HL
  16406.         call    l6f5e           ; Verify ,
  16407.         call    l5ebb
  16408.         ld      hl,l1f4e
  16409.         jp      l5db1
  16410. ;
  16411. ; Procedure CRTINIT
  16412. ;
  16413. l5e38:
  16414.         ld      hl,l030a
  16415.         jr      l5e45           ; Set call to lead in
  16416. ;
  16417. ; Procedure CRTEXIT
  16418. ;
  16419. l5e3d:
  16420.         ld      hl,l0310
  16421.         jr      l5e45           ; Set call to lead out
  16422. ;
  16423. ; Procedure CLRSCR
  16424. ;
  16425. l5e42:
  16426.         ld      hl,l023e        ; Set call to clear screen
  16427. l5e45:
  16428.         jp      l6b86           ; Set CALL <crt_procedure>
  16429. ;
  16430. ; Procedure CLREOL
  16431. ;
  16432. l5e48:
  16433.         ld      hl,l0299        ; Set call to clear to end of line
  16434.         jr      l5e45
  16435. ;
  16436. ; Procedure NORMVIDEO or HIGHVIDEO
  16437. ;
  16438. l5e4d:
  16439.         ld      hl,setnormvideo ; Set call to normal video
  16440.         jr      l5e45
  16441. ;
  16442. ; Procedure LOWVIDEO
  16443. ;
  16444. l5e52:
  16445.         ld      hl,setlowvideo  ; Set call to low video
  16446.         jr      l5e45
  16447. ;
  16448. ; Procedure INSLINE
  16449. ;
  16450. l5e57:
  16451.         ld      hl,l0262        ; Set call to insert line
  16452.         jr      l5e45
  16453. ;
  16454. ; Procedure DELLINE
  16455. ;
  16456. l5e5c:
  16457.         ld      hl,l0259        ; Set call to delete line
  16458.         jr      l5e45
  16459. ;
  16460. ; Procedure EXIT
  16461. ;
  16462. l5e61:
  16463.         ld      de,OS           ; Set call to exit
  16464.         jp      l5639
  16465. ;
  16466. ; Procedure HALT
  16467. ;
  16468. l5e67:
  16469.         ld      hl,l20d4
  16470.         jp      l6b82           ; Set call to HALT program
  16471. ;
  16472. ; Procedure PORT(Integer,Integer)
  16473. ;
  16474. l5e6d:
  16475.         call    l5e8e
  16476.         call    l6b50           ; Set sequence
  16477.         db      a_L26
  16478. s_I26:
  16479.         POP     BC
  16480.         OUT     (C),L
  16481. a_L26   equ     $-s_I26
  16482.         ret
  16483. ;
  16484. ; Procedure STACKPTR
  16485. ;
  16486. l5e78:
  16487.         call    l6f7e
  16488.         call    l5e97
  16489.         call    l6b50   ; Set LD SP,HL
  16490.         db      a_L27
  16491. s_I27:
  16492.         LD      SP,HL
  16493. a_L27   equ     $-s_I27
  16494.         ret
  16495.  
  16496. l5e84:
  16497.         call    l6d2a           ; Save environment
  16498.         call    l5ee8
  16499.         call    l6d49           ; Get back environment
  16500.         ret
  16501. l5e8e:
  16502.         call    l65d5
  16503.         call    l6f7e
  16504.         call    l6b6f           ; Set PUSH HL
  16505. l5e97:
  16506.         call    l5ee8
  16507.         ld      a,b
  16508.         cp      0ah
  16509.         ret     z
  16510.         call    l72e1
  16511.         db      _IntExpr
  16512. l5ea2:
  16513.         call    l5ee8
  16514.         ld      a,b
  16515.         cp      0ah
  16516.         ret     z
  16517.         cp      9
  16518.         ret     z
  16519.         call    l72e1
  16520.         db      _NumExprExp
  16521. l5eb0:
  16522.         call    l5ee8
  16523.         ld      a,b
  16524.         cp      0bh
  16525.         ret     z
  16526.         call    l72e1
  16527.         db      _BoolExp
  16528. l5ebb:
  16529.         call    l5ee8
  16530. l5ebe:
  16531.         ld      a,b
  16532.         cp      0ah
  16533.         ret     nc
  16534.         cp      8
  16535.         call    l72da
  16536.         db      _SimpExpr
  16537.         ld      b,0ch
  16538.         ld      hl,l0996
  16539.         jp      l6b86           ; Set CALL CHECKASSIGNMENT
  16540. l5ed0:
  16541.         call    l5ee8
  16542.         ld      a,b
  16543.         cp      8
  16544.         ret     z
  16545.         cp      0ch
  16546.         call    l72da
  16547.         db      _StrgExpExp
  16548. l5edd:
  16549.         ld      b,8
  16550.         call    l6b50           ; Set sequence
  16551.         db      a_L28
  16552. s_I28:
  16553.         LD      H,L
  16554.         LD      L,1
  16555.         PUSH    HL
  16556. a_L28   equ     $-s_I28
  16557.         ret
  16558. l5ee8:
  16559.         call    l5f98
  16560. l5eeb:
  16561.         push    bc
  16562.         call    l6e5a           ; Find relation
  16563.         db      1
  16564.         dw      l7625
  16565.         pop     bc
  16566.         ret     nz              ; Nope
  16567.         ld      a,(hl)          ; Get code
  16568.         inc     a               ; Test IN
  16569.         jr      z,l5f34         ; Yeap
  16570.         dec     a
  16571.         push    af
  16572.         push    bc
  16573.         call    l6148
  16574.         ld      hl,(l7b8b)
  16575.         push    hl
  16576.         call    l5f98
  16577.         pop     hl
  16578.         ld      (l7b8d),hl
  16579.         pop     de
  16580.         call    l6160
  16581.         pop     af
  16582.         ld      e,a
  16583.         ld      d,0
  16584.         ld      hl,l5f68
  16585.         add     hl,de
  16586.         ld      a,b
  16587.         cp      3
  16588.         jr      z,l5f28
  16589.         inc     hl
  16590.         inc     hl
  16591.         cp      9
  16592.         jr      z,l5f28
  16593.         inc     hl
  16594.         inc     hl
  16595.         cp      8
  16596.         jr      z,l5f28
  16597.         inc     hl
  16598.         inc     hl
  16599. l5f28:
  16600.         ld      e,(hl)
  16601.         inc     hl
  16602.         ld      d,(hl)
  16603.         ld      a,d
  16604.         or      e
  16605.         call    l72d4
  16606.         db      _IllOps
  16607.         ex      de,hl
  16608.         jr      l5f62
  16609. l5f34:
  16610.         ld      a,b
  16611.         cp      0ah
  16612.         jr      nc,l5f47
  16613.         cp      8
  16614.         call    l72da
  16615.         db      _IllOps
  16616.         ld      hl,l0996
  16617.         call    l6b86           ; Set CALL CHECKASSIGNMENT
  16618.         ld      b,0ch
  16619. l5f47:
  16620.         push    bc
  16621.         call    l6b6f           ; Set PUSH HL
  16622.         call    l5f98
  16623.         pop     de
  16624.         ld      a,b
  16625.         cp      3
  16626.         call    l72da
  16627.         db      _IllOps
  16628.         ld      a,c
  16629.         or      a
  16630.         jr      z,l5f5f
  16631.         cp      d
  16632.         call    l72da
  16633.         db      _InvType
  16634. l5f5f:
  16635.         ld      hl,l134f
  16636. l5f62:
  16637.         call    l6b86           ; Set CALL <set>
  16638.         ld      b,0bh
  16639.         ret
  16640. l5f68:
  16641.         dw      l12e1
  16642.         dw      l0688           ; Real =
  16643.         dw      l068d           ; String =
  16644.         dw      l067f           ; Integer =
  16645.         dw      l12dd
  16646.         dw      l069b           ; Real <>
  16647.         dw      l06a0           ; String <>
  16648.         dw      l0692           ; Integer <>
  16649.         dw      l1300
  16650.         dw      l06ae           ; Real >=
  16651.         dw      l06b3           ; String >=
  16652.         dw      l06a5           ; Integer >=
  16653.         dw      l12fc
  16654.         dw      l06c2           ; Real <=
  16655.         dw      l06c7           ; String <=
  16656.         dw      l06b8           ; Integer <=
  16657.         dw      l0000
  16658.         dw      l06d6           ; Real >
  16659.         dw      l06db           ; String >
  16660.         dw      l06cc           ; Integer >
  16661.         dw      l0000
  16662.         dw      l06e9           ; Real <
  16663.         dw      l06ee           ; String <
  16664.         dw      l06e0           ; Integer <
  16665. l5f98:
  16666.         call    l6054
  16667. l5f9b:
  16668.         push    bc
  16669.         call    l6e5a           ; Find operator
  16670.         db      1
  16671.         dw      l7619
  16672.         pop     bc
  16673.         ret     nz              ; Nope
  16674.         ld      a,b
  16675.         cp      4
  16676.         call    l72d4
  16677.         db      _IllOps
  16678.         ld      a,(hl)          ; Get operator
  16679.         push    af
  16680.         push    bc
  16681.         call    l6148
  16682.         call    l6054
  16683.         pop     de
  16684.         pop     af              ; Get back operator
  16685.         push    af
  16686.         or      a               ; Test +
  16687.         jr      nz,l5fc9        ; Nope
  16688.         ld      a,b
  16689.         cp      0ch
  16690.         jr      nz,l5fc9
  16691.         call    l6b50           ; Set sequence
  16692.         db      a_L29
  16693. s_I29:
  16694.         LD      H,L
  16695.         LD      L,1
  16696.         PUSH    HL
  16697. a_L29   equ     $-s_I29
  16698.         ld      b,8
  16699. l5fc9:
  16700.         call    l6160
  16701.         pop     af              ; Get back operator
  16702.         cp      2               ; Test -
  16703.         jr      nc,l601b        ; Nope, OR or XOR
  16704.         push    af
  16705.         ld      a,b
  16706.         ld      hl,l1318
  16707.         ld      de,l1326
  16708.         cp      3
  16709.         jr      z,l6006
  16710.         ld      hl,l09e9        ; Set add reals
  16711.         ld      de,l09f2        ; Set subtract reals
  16712.         cp      9
  16713.         jr      z,l6006
  16714.         cp      8
  16715.         jr      z,l6010
  16716.         cp      0ah
  16717.         call    l72da
  16718.         db      _IllOps
  16719.         pop     af
  16720.         dec     a
  16721.         jr      z,l5ffc
  16722.         call    l6b50           ; Set ADD HL,DE
  16723.         db      a_L30
  16724. s_I30:
  16725.         ADD     HL,DE
  16726. a_L30   equ     $-s_I30
  16727.         jr      l5f9b
  16728. l5ffc:
  16729.         call    l6b50           ; Set sequence
  16730.         db      a_L31
  16731. s_I31:
  16732.         EX      DE,HL
  16733.         OR      A
  16734.         SBC     HL,DE
  16735. a_L31   equ     $-s_I31
  16736.         jr      l5f9b
  16737. l6006:
  16738.         pop     af
  16739.         dec     a
  16740.         jr      nz,l600b
  16741.         ex      de,hl
  16742. l600b:
  16743.         call    l6b86           ; Set CALL <string>
  16744.         jr      l5f9b
  16745. l6010:
  16746.         pop     af
  16747.         dec     a
  16748.         call    l72d4
  16749.         db      _IllOps
  16750.         ld      hl,l083d
  16751.         jr      l600b           ; Set add two strings
  16752. l601b:
  16753.         ld      a,b
  16754.         jr      nz,l6039        ; Must be XOR
  16755.         cp      0bh
  16756.         jr      z,l602f
  16757.         cp      0ah
  16758.         call    l72da
  16759.         db      _IllOps
  16760.         call    l6b50           ; Set OR
  16761.         db      a_L32
  16762. s_I32:
  16763.         LD      A,H
  16764.         OR      D
  16765.         LD      H,A
  16766. a_L32   equ     $-s_I32
  16767. l602f:
  16768.         call    l6b50           ; Set OR
  16769.         db      a_L33
  16770. s_I33:
  16771.         LD      A,L
  16772.         OR      E
  16773.         LD      L,A
  16774. a_L33   equ     $-s_I33
  16775.         jp      l5f9b
  16776. l6039:
  16777.         cp      0bh
  16778.         jr      z,l604a
  16779.         cp      0ah
  16780.         call    l72da
  16781.         db      _IllOps
  16782.         call    l6b50           ; Set XOR
  16783.         db      a_L34
  16784. s_I34:
  16785.         LD      A,H
  16786.         XOR     D
  16787.         LD      H,A
  16788. a_L34   equ     $-s_I34
  16789. l604a:
  16790.         call    l6b50           ; Set XOR
  16791.         db      a_L35
  16792. s_I35:
  16793.         LD      A,L
  16794.         XOR     E
  16795.         LD      L,A
  16796. a_L35   equ     $-s_I35
  16797.         jp      l5f9b
  16798. l6054:
  16799.         call    l60e9
  16800. l6057:
  16801.         push    bc
  16802.         call    l6e5a           ; Find operator
  16803.         db      1
  16804.         dw      l7600
  16805.         pop     bc
  16806.         ret     nz              ; Nope
  16807.         ld      a,b
  16808.         cp      4
  16809.         call    l72d4
  16810.         db      _IllOps
  16811.         ld      a,(hl)          ; Get operator
  16812.         push    af
  16813.         push    bc
  16814.         call    l6148
  16815.         call    l60e9
  16816.         pop     de
  16817.         pop     af              ; Get back operator
  16818.         push    af
  16819.         dec     a               ; Test /
  16820.         jr      nz,l6083        ; Nope
  16821.         ld      a,b
  16822.         cp      0ah
  16823.         jr      nz,l6083
  16824.         ld      hl,l1008
  16825.         call    l6b86           ; Set CALL INT_TO_FLP
  16826.         ld      b,9
  16827. l6083:
  16828.         call    l6160
  16829.         pop     af              ; Get back operator
  16830.         ld      e,a
  16831.         ld      a,b
  16832.         inc     e               ; Test *
  16833.         dec     e
  16834.         jr      nz,l60a9        ; Nope
  16835.         ld      hl,l1333
  16836.         cp      3
  16837.         jr      z,l60a4
  16838.         ld      hl,l06f5        ; Set integer multiply
  16839.         cp      0ah
  16840.         jr      z,l60a4
  16841.         ld      hl,l09fa        ; Set real multiply
  16842. l609e:
  16843.         cp      9
  16844.         call    l72da
  16845.         db      _IllOps
  16846. l60a4:
  16847.         call    l6b86           ; Set CALL <real>
  16848.         jr      l6057
  16849. l60a9:
  16850.         ld      hl,l09ff        ; Set real division
  16851.         dec     e               ; Test /
  16852.         jr      z,l609e         ; Yeap
  16853.         dec     e               ; Test AND
  16854.         jr      nz,l60cc        ; Nope
  16855.         cp      0bh
  16856.         jr      z,l60c3
  16857.         cp      0ah
  16858.         call    l72da
  16859.         db      _IllOps
  16860.         call    l6b50           ; Set AND
  16861.         db      a_L36
  16862. s_I36:
  16863.         LD      A,H
  16864.         AND     D
  16865.         LD      H,A
  16866. a_L36   equ     $-s_I36
  16867. l60c3:
  16868.         call    l6b50           ; Set AND
  16869.         db      a_L37
  16870. s_I37:
  16871.         LD      A,L
  16872.         AND     E
  16873.         LD      L,A
  16874. a_L37   equ     $-s_I37
  16875.         jr      l6057
  16876. l60cc:
  16877.         cp      0ah
  16878.         call    l72da
  16879.         db      _IllOps
  16880.         ld      hl,l070f        ; Set integer DIV
  16881.         dec     e               ; Test DIV
  16882.         jr      z,l60a4         ; Yeap
  16883.         ld      hl,l0745        ; Set integer MOD
  16884.         dec     e               ; Test MOD
  16885.         jr      z,l60a4
  16886.         ld      hl,l074e        ; Set SHL
  16887.         dec     e               ; Test SHL
  16888.         jr      z,l60a4
  16889.         ld      hl,l0756        ; Set SHR
  16890.         jr      l60a4
  16891. l60e9:
  16892.         call    l6e76           ; Find NOT
  16893.         dw      l7579
  16894.         jr      nz,l6112        ; Nope
  16895.         call    l6112
  16896.         ld      a,b
  16897.         cp      0ah
  16898.         jr      z,l6107
  16899.         cp      0bh
  16900.         call    l72da
  16901.         db      _IllOps
  16902.         call    l6b50           ; Set sequence
  16903.         db      a_L38
  16904. s_I38:
  16905.         LD      A,L
  16906.         XOR     1
  16907.         LD      L,A
  16908. a_L38   equ     $-s_I38
  16909.         ret
  16910. l6107:
  16911.         call    l6b50           ; Set sequence
  16912.         db      a_L39
  16913. s_I39:
  16914.         LD      A,L
  16915.         CPL
  16916.         LD      L,A
  16917.         LD      A,H
  16918.         CPL
  16919.         LD      H,A
  16920. a_L39   equ     $-s_I39
  16921.         ret
  16922. l6112:
  16923.         ld      a,(l7ba1)
  16924.         push    af
  16925.         call    l6a39
  16926.         ld      a,e
  16927.         ld      (l7ba1),a
  16928.         call    l621d
  16929.         ld      a,(l7ba1)
  16930.         ld      e,a
  16931.         call    l6a4a
  16932.         jr      z,l6143
  16933.         ld      a,b
  16934.         cp      0ah
  16935.         jr      nz,l613b
  16936.         call    l6b50           ; Set sequence
  16937.         db      a_L40
  16938. s_I40:
  16939.         LD      A,L
  16940.         CPL
  16941.         LD      L,A
  16942.         LD      A,H
  16943.         CPL
  16944.         LD      H,A
  16945.         INC     HL
  16946. a_L40   equ     $-s_I40
  16947.         jr      l6143
  16948. l613b:
  16949.         call    l6b50           ; Set sequence
  16950.         db      a_L41
  16951. s_I41:
  16952.         LD      A,B
  16953.         XOR     80H
  16954.         LD      B,A
  16955. a_L41   equ     $-s_I41
  16956. l6143:
  16957.         pop     af
  16958.         ld      (l7ba1),a
  16959.         ret
  16960. l6148:
  16961.         ld      a,b
  16962.         cp      0ah
  16963.         jr      nc,l615d
  16964.         cp      4
  16965.         jr      z,l615d
  16966.         cp      8
  16967.         ret     z
  16968.         cp      3
  16969.         ret     z
  16970.         call    l6b50           ; Set sequence
  16971.         db      a_L42
  16972. s_I42:
  16973.         PUSH    BC
  16974.         PUSH    DE
  16975. a_L42   equ     $-s_I42
  16976. l615d:
  16977.         jp      l6b6f           ; Set PUSH HL
  16978. l6160:
  16979.         ld      a,d
  16980.         cp      9
  16981.         jr      nz,l6174
  16982.         ld      a,b
  16983.         cp      0ah
  16984.         jr      nz,l6187
  16985.         ld      hl,l1008
  16986.         call    l6b86           ; Set CALL INT_TO_FLP
  16987.         ld      b,9
  16988.         jr      l6187
  16989. l6174:
  16990.         cp      8
  16991.         jr      nz,l6187
  16992.         ld      a,b
  16993.         cp      0ch
  16994.         jr      nz,l6187
  16995.         call    l6b50           ; Set sequence
  16996.         db      a_L43
  16997. s_I43:
  16998.         LD      H,L
  16999.         LD      L,1
  17000.         PUSH    HL
  17001. a_L43   equ     $-s_I43
  17002.         ld      b,8
  17003. l6187:
  17004.         ld      a,b
  17005.         cp      9
  17006.         jr      nz,l6193
  17007.         call    l6b50           ; Set EXX
  17008.         db      a_L44
  17009. s_I44:
  17010.         EXX
  17011. a_L44   equ     $-s_I44
  17012.         jr      l61a4
  17013. l6193:
  17014.         cp      8
  17015.         jr      nz,l61a4
  17016.         ld      a,d
  17017.         cp      0ch
  17018.         jr      nz,l61a4
  17019.         ld      hl,l09a2
  17020.         call    l6b86           ; Set CALL CHR_TO_STRG
  17021.         ld      d,8
  17022. l61a4:
  17023.         ld      a,d
  17024.         cp      0ah
  17025.         jr      z,l61bc
  17026.         jr      nc,l61ce
  17027.         cp      4
  17028.         jr      z,l61ce
  17029.         cp      9
  17030.         jr      c,l61d3
  17031.         call    l6b50           ; Set sequence
  17032.         db      a_L45
  17033. s_I45:
  17034.         POP     HL
  17035.         POP     DE
  17036.         POP     BC
  17037. a_L45   equ     $-s_I45
  17038.         jr      l61d3
  17039. l61bc:
  17040.         ld      a,b
  17041.         cp      9
  17042.         jr      nz,l61ce
  17043.         call    l6b73           ; Set POP HL
  17044.         ld      hl,l1008
  17045.         call    l6b86           ; Set CALL INT_TO_FLP
  17046.         ld      d,9
  17047.         jr      l61d3
  17048. l61ce:
  17049.         call    l6b50           ; Set POP DE
  17050.         db      a_L46
  17051. s_I46:
  17052.         POP     DE
  17053. a_L46   equ     $-s_I46
  17054. l61d3:
  17055.         ld      a,b
  17056.         cp      d
  17057.         call    l72da
  17058.         db      _InvType
  17059.         cp      3
  17060.         jr      nz,l61ea
  17061.         ld      a,e
  17062.         cp      c
  17063.         ret     z
  17064.         or      a
  17065.         ret     z
  17066.         ld      a,c
  17067.         ld      c,e
  17068.         or      a
  17069.         ret     z
  17070.         call    l72e1
  17071.         db      _InvType
  17072. l61ea:
  17073.         cp      4
  17074.         ret     nz
  17075.         ld      hl,(l7b8b)
  17076.         ld      a,h
  17077.         or      l
  17078.         ret     z
  17079.         ld      de,(l7b8d)
  17080.         ld      a,d
  17081.         or      e
  17082.         ret     z
  17083.         sbc     hl,de
  17084.         ret     z
  17085.         call    l72e1
  17086.         db      _InvType
  17087. l6201:
  17088.         ld      de,l5eeb
  17089.         push    de
  17090.         ld      de,l5f9b
  17091.         push    de
  17092.         ld      de,l6057
  17093.         push    de
  17094.         jr      l622d
  17095. l620f:
  17096.         ld      de,l5eeb
  17097.         push    de
  17098.         ld      de,l5f9b
  17099.         push    de
  17100.         ld      de,l6057
  17101.         push    de
  17102.         jr      l6276
  17103. l621d:
  17104.         call    l6a5c
  17105.         jr      nz,l6257
  17106.         ld      a,(l7ba1)
  17107.         ld      e,a
  17108.         call    l6a1f
  17109.         xor     a
  17110.         ld      (l7ba1),a
  17111. l622d:
  17112.         ld      a,b
  17113.         cp      9
  17114.         jr      nz,l6249
  17115.         exx
  17116.         push    bc
  17117.         push    de
  17118.         push    hl
  17119.         ld      bc,256*3+031h
  17120. l6239:
  17121.         ld      a,c
  17122.         sub     10h
  17123.         ld      c,a             ; Get byte
  17124.         call    writebyte_a_addriy              ; Store it
  17125.         pop     hl
  17126.         call    writeword_hl_addriy
  17127.         djnz    l6239
  17128.         ld      b,9
  17129.         ret
  17130. l6249:
  17131.         cp      8
  17132.         jp      nz,l6b92        ; Set LD HL,val16
  17133.         ld      hl,l054d
  17134.         call    l6b86           ; move immediate string to stack
  17135.         jp      l6b5e
  17136. l6257:
  17137.         ld      bc,256*6+0
  17138.         call    l6e54
  17139.         jr      nz,l6271
  17140.         call    l573d
  17141.         ex      de,hl
  17142.         call    l5287           ; Get name
  17143.         ld      hl,(l7b5e)      ; Get lo set limit
  17144.         ld      (l7b8b),hl
  17145.         ld      a,(l7b5c)       ; Get type
  17146.         ld      b,a
  17147.         ret
  17148. l6271:
  17149.         call    l67b2
  17150.         jr      nz,l62d2
  17151. l6276:
  17152.         ld      a,(l7b5c)       ; Get type
  17153.         cp      _String
  17154.         jr      nc,l6285
  17155.         cp      _Set
  17156.         jr      z,l6285
  17157.         cp      _Ptr
  17158.         jr      nz,l629d
  17159. l6285:
  17160.         call    l66da
  17161.         ld      hl,(l7b5e)      ; Get lo set limit
  17162.         ld      (l7b8b),hl
  17163.         ld      a,(l7b5c)       ; Get type
  17164.         ld      b,a
  17165.         cp      _Set
  17166.         ret     nz
  17167.         call    l5287           ; Get name
  17168.         ld      a,(l7b5c)       ; Get type
  17169.         ld      c,a
  17170.         ret
  17171. l629d:
  17172.         cp      _Array
  17173.         call    l72da
  17174.         db      _NoStruktVar
  17175.         call    l678b
  17176.         ld      hl,(l7b5e)      ; Get lo set limit
  17177.         ld      a,(hl)
  17178.         cp      0ch
  17179.         call    l72da
  17180.         db      _NoStruktVar
  17181.         ld      hl,(l7b60)      ; Get hi set limit
  17182.         ld      a,(hl)
  17183.         cp      0ah
  17184.         call    l72da
  17185.         db      _NoStruktVar
  17186.         ld      hl,(l7b62)      ; Get length of type
  17187.         ld      a,h
  17188.         or      a
  17189.         call    l72da
  17190.         db      _NoStruktVar
  17191.         ld      h,l
  17192.         ld      l,6
  17193.         call    writeword_hl_addriy
  17194.         ld      hl,l0638
  17195.         call    l6b86           ; Set set to stack
  17196.         ld      b,8
  17197.         ret
  17198. l62d2:
  17199.         call    l6ee0
  17200.         jr      nz,l631c
  17201.         ld      hl,l0581
  17202.         call    l6b86           ; Initialize a set on stack
  17203.         call    l6ef7           ; Test ]
  17204.         ld      bc,3*256+0 ;l0300
  17205.         ret     z               ; Yeap
  17206. l62e4:
  17207.         push    bc
  17208.         call    l5ebb
  17209.         ld      a,b
  17210.         pop     bc
  17211.         inc     c
  17212.         dec     c
  17213.         jr      nz,l62ef
  17214.         ld      c,a
  17215. l62ef:
  17216.         cp      c
  17217.         call    l72da
  17218.         db      _InvType
  17219.         push    bc
  17220.         call    l6e76           ; Find ..
  17221.         dw      l7580
  17222.         ld      hl,l0591
  17223.         jr      nz,l6310        ; Nope, init one set element
  17224.         call    l6b6f           ; Set PUSH HL
  17225.         call    l5ebb
  17226.         ld      a,b
  17227.         pop     bc
  17228.         push    bc
  17229.         cp      c
  17230.         call    l72da
  17231.         db      _InvType
  17232.         ld      hl,l059b        ; Init a contiguous set value
  17233. l6310:
  17234.         call    l6b86           ; Set CALL <set>
  17235.         pop     bc
  17236.         call    l6f13           ; Test ,
  17237.         jr      z,l62e4         ; Yeap
  17238.         jp      l6f38           ; Verify ]
  17239. l631c:
  17240.         call    l6f1b           ; Test (
  17241.         jr      nz,l6327        ; Nope
  17242.         call    l5ee8
  17243.         jp      l6f6e           ; Verify )
  17244. l6327:
  17245.         call    l6e5a           ; Find function
  17246.         db      2
  17247.         dw      l77b1
  17248.         jr      nz,l6335        ; Nope
  17249.         ld      e,(hl)
  17250.         inc     hl
  17251.         ld      d,(hl)
  17252.         ex      de,hl
  17253.         xor     a
  17254.         jp      (hl)
  17255. l6335:
  17256.         call    l6e76           ; Find NIL
  17257.         dw      l757c
  17258.         jr      nz,l6345        ; Nope
  17259.         ld      hl,l0000
  17260.         call    l6b92           ; Set LD HL,val16
  17261.         jp      l642e
  17262. l6345:
  17263.          ;jr $
  17264.         ld      bc,256*3+0
  17265.         call    l6e54 ; Find label with type in reg B
  17266.         call    l72da
  17267.         db      _Undef ;TODO fix bb:=(Txt in [Txt]);
  17268.         ld      d,(hl)
  17269.         dec     hl
  17270.         ld      e,(hl)
  17271.         ld      a,(de)
  17272.         cp      0ah
  17273.         call    l72c8
  17274.         db      _SimTyp
  17275.         push    af
  17276.         call    l65ef
  17277.         pop     af
  17278.         ld      b,a
  17279.         ret
  17280. ;
  17281. ; Function SQR(Num)
  17282. ;
  17283. l6360:
  17284.         call    l65e7
  17285.         ld      hl,l06f3        ; Set integer SQR
  17286.         ld      a,b
  17287.         cp      0ah
  17288.         jr      z,l636e
  17289.         ld      hl,l09f7        ; Set real SQR
  17290. l636e:
  17291.         jp      l6b86           ; Set CALL <real>
  17292. ;
  17293. ; Function ABS(Num)
  17294. ;
  17295. l6371:
  17296.         call    l65e7
  17297.         ld      a,b
  17298.         cp      0ah
  17299.         jr      z,l6380
  17300.         call    l6b50           ; Set RES 7,B
  17301.         db      a_L47
  17302. s_I47:
  17303.         RES     7,B
  17304. a_L47   equ     $-s_I47
  17305.         ret
  17306. l6380:
  17307.         ld      hl,l0780        ; Set integer ABS
  17308.         jr      l63cf
  17309. ;
  17310. ; Function SQRT(Num)
  17311. ;
  17312. l6385:
  17313.         ld      hl,l0c46
  17314.         jr      l63ab
  17315. ;
  17316. ; Function SIN(Num)
  17317. ;
  17318. l638a:
  17319.         ld      hl,l0c87
  17320.         jr      l63ab
  17321. ;
  17322. ; Function COS(Num)
  17323. ;
  17324. l638f:
  17325.         ld      hl,l0c7f
  17326.         jr      l63ab
  17327. ;
  17328. ; Function ARCTAN(Num)
  17329. ;
  17330. l6394:
  17331.         ld      hl,l0e46
  17332.         jr      l63ab
  17333. ;
  17334. ; Function LN(Num)
  17335. ;
  17336. l6399:
  17337.         ld      hl,l0d2b
  17338.         jr      l63ab
  17339. ;
  17340. ; Function EXP(Num)
  17341. ;
  17342. l639e:
  17343.         ld      hl,l0db6
  17344.         jr      l63ab
  17345. ;
  17346. ; Function INT(Num)
  17347. ;
  17348. l63a3:
  17349.         ld      hl,l0bfd
  17350.         jr      l63ab
  17351. ;
  17352. ; Function FRAC(Num)
  17353. ;
  17354. l63a8:
  17355.         ld      hl,l0c34
  17356. l63ab:
  17357.         push    hl
  17358.         call    l65e7
  17359.         ld      hl,l1008
  17360.         ld      a,b
  17361.         cp      0ah
  17362.         call    z,l6b86         ; Set CALL INT_TO_FLP
  17363.         pop     hl
  17364.         ld      b,9
  17365.         jp      l6b86           ; Set CALL <real>
  17366. ;
  17367. ; Function TRUNC(Num)
  17368. ;
  17369. l63be:
  17370.         ld      hl,l0fde
  17371.         jr      l63c6
  17372. ;
  17373. ; Function ROUND(Num)
  17374. ;
  17375. l63c3:
  17376.         ld      hl,l0fd0
  17377. l63c6:
  17378.         push    hl
  17379.         call    l65e7
  17380.         pop     hl
  17381.         ld      a,b
  17382.         cp      0ah
  17383.         ret     z
  17384. l63cf:
  17385.         ld      b,0ah
  17386.         jp      l6b86           ; Set CALL <real>
  17387. ;
  17388. ; Function SUCC(Num)
  17389. ;
  17390. l63d4:
  17391.         ld      a,_INC.HL       ; INC HL
  17392.         db      skip.3
  17393. ;
  17394. ; Function PRED(Num)
  17395. ;
  17396. l63d7:
  17397.         ld      a,_DEC.HL       ; DEC HL
  17398.         push    af
  17399.         call    l65ef
  17400.         pop     af              ; Get byte back
  17401.         jp      writebyte_a_addriy              ; Store it
  17402. ;
  17403. ; Function LO(Integer)
  17404. ;
  17405. l63e1:
  17406.         call    l65de
  17407.         call    l6b50           ; Set LD H,0
  17408.         db      a_L48
  17409. s_I48:
  17410.         LD      H,0
  17411. a_L48   equ     $-s_I48
  17412.         ret
  17413. ;
  17414. ; Function HI(Integer)
  17415. ;
  17416. l63eb:
  17417.         call    l65de
  17418.         call    l6b50           ; Set sequence
  17419.         db      a_L49
  17420. s_I49:
  17421.         LD      L,H
  17422.         LD      H,0
  17423. a_L49   equ     $-s_I49
  17424.         ret
  17425. ;
  17426. ; Function SWAP(Num)
  17427. ;
  17428. l63f6:
  17429.         call    l65de
  17430.         call    l6b50           ; Set sequence
  17431.         db      a_L50
  17432. s_I50:
  17433.         LD      A,L
  17434.         LD      L,H
  17435.         LD      H,A
  17436. a_L50   equ     $-s_I50
  17437.         ret
  17438. ;
  17439. ; Function ODD(Num)
  17440. ;
  17441. l6401:
  17442.         call    l65de
  17443.         ld      hl,l078b        ; Set function ODD
  17444. l6407:
  17445.         ld      b,0bh
  17446. l6409:
  17447.         jp      l6b86           ; Set CALL ODD
  17448. ;
  17449. ; Function KEYPRESSED
  17450. ;
  17451. l640c:
  17452.         ld      hl,l00a0
  17453.         jr      l6407
  17454. ;
  17455. ; Function ORD(Var)
  17456. ;
  17457. l6411:
  17458.         call    l6f66           ; Verify (
  17459.         call    l5ee8
  17460.         call    l6f6e           ; Verify )
  17461.         ld      a,b
  17462.         cp      4
  17463.         jr      z,l6422
  17464.         call    l5ebe
  17465. l6422:
  17466.         ld      b,0ah
  17467.         ret
  17468. ;
  17469. ; Function CHR(Num)
  17470. ;
  17471. l6425:
  17472.         call    l65de
  17473.         ld      b,0ch
  17474.         ret
  17475. ;
  17476. ; Function PTR(Integer)
  17477. ;
  17478. l642b:
  17479.         call    l65de
  17480. l642e:
  17481.         ld      hl,l0000
  17482.         ld      (l7b8b),hl
  17483.         ld      b,4
  17484.         ret
  17485. ;
  17486. ; Function UPCASE(Char)
  17487. ;
  17488. l6437:
  17489.         call    l65ef
  17490.         ld      b,0ch
  17491.         ld      hl,l1fe4
  17492.         jr      l6409
  17493. ;
  17494. ; Function LENGTH(String)
  17495. ;
  17496. l6441:
  17497.         call    l6f66           ; Verify (
  17498.         ld      hl,l08a3        ; Set LENGTH
  17499. l6447:
  17500.         push    hl
  17501.         call    l5ed0
  17502.         call    l6f6e           ; Verify )
  17503.         pop     hl
  17504.         jp      l63cf
  17505. ;
  17506. ; Function POS(String,String)
  17507. ;
  17508. l6452:
  17509.         call    l6f66           ; Verify (
  17510.         call    l5ed0
  17511.         call    l6f5e           ; Verify ,
  17512.         ld      hl,l08b2
  17513.         jr      l6447           ; Set POS
  17514. ;
  17515. ; Function COPY(String,Integer,Integer)
  17516. ;
  17517. l6460:
  17518.         call    l6f66           ; Verify (
  17519.         call    l5ed0
  17520.         call    l6f5e           ; Verify ,
  17521.         call    l5e97
  17522.         call    l6f5e           ; Verify ,
  17523.         call    l6b6f           ; Set PUSH HL
  17524.         call    l5e97
  17525.         call    l6f6e           ; Verify )
  17526.         ld      hl,l086b
  17527.         call    l6b86           ; Set CALL COPY
  17528. l647e:
  17529.         ld      b,8
  17530.         ret
  17531. ;
  17532. ; Function CONCAT(String,String,...)
  17533. ;
  17534. l6481:
  17535.         call    l6f66           ; Verify (
  17536.         call    l5ed0
  17537. l6487:
  17538.         call    l6f13           ; Test ,
  17539.         jr      nz,l6497        ; Nope
  17540.         call    l5ed0
  17541.         ld      hl,l083d
  17542.         call    l6b86           ; Set add two strings
  17543.         jr      l6487
  17544. l6497:
  17545.         call    l6f6e           ; Verify )
  17546.         jr      l647e
  17547. ;
  17548. ; Function PARAMCOUNT
  17549. ;
  17550. l649c:
  17551.         ld      hl,l1f9b
  17552.         jr      l64bf
  17553. ;
  17554. ; Function PARAMSTR(Integer)
  17555. ;
  17556. l64a1:
  17557.         call    l65de
  17558.         ld      hl,l1f7d
  17559.         ld      b,8
  17560.         jp      l6b86           ; Set CALL PARAMSTR
  17561. ;
  17562. ; Function RANDOM(Integer)
  17563. ;
  17564. l64ac:
  17565.         call    l6f1b           ; Test (
  17566.         ld      hl,l0fb4
  17567.         ld      b,9
  17568.         jr      nz,l64c1        ; Nope
  17569.         call    l5e97
  17570.         call    l6f6e           ; Verify )
  17571.         ld      hl,l073b        ; Set integer random
  17572. l64bf:
  17573.         ld      b,0ah
  17574. l64c1:
  17575.         jp      l6b86           ; Set CALL RANDOM
  17576. ;
  17577. ; Function IORESULT
  17578. ;
  17579. l64c4:
  17580.         ld      hl,l1ff1
  17581.         jr      l64bf
  17582. ;
  17583. ; Function EOF(FileVar)
  17584. ;
  17585. l64c9:
  17586.         call    l65f7
  17587.         ld      hl,l6615
  17588.         call    l59e9
  17589. l64d2:
  17590.         ld      b,0bh
  17591.         ret
  17592. ;
  17593. ; Function SEEKEOF(FileVar)
  17594. ;
  17595. l64d5:
  17596.         ld      hl,l17e1
  17597.         jr      l64e2
  17598. ;
  17599. ; Function SEEKEOLN(FileVar)
  17600. ;
  17601. l64da:
  17602.         ld      hl,l17d7
  17603.         jr      l64e2
  17604. ;
  17605. ; Function EOLN(TextFileVar)
  17606. ;
  17607. l64df:
  17608.         ld      hl,l17dc
  17609. l64e2:
  17610.         push    hl
  17611.         call    l65f7
  17612.         cp      6
  17613.         call    l72da
  17614.         db      _MustTextFile
  17615.         pop     hl
  17616.         call    l6b86           ; Set CALL <eoln>
  17617.         jr      l64d2
  17618. ;
  17619. ; Function FILEPOS(FileVar)
  17620. ;
  17621. l64f2:
  17622.         ld      hl,l1a55
  17623.         ld      de,l1a55
  17624.         jr      l6500
  17625. ;
  17626. ; Function FILESIZE(FileVar)
  17627. ;
  17628. l64fa:
  17629.         ld      hl,l1a5d
  17630.         ld      de,l1a5d
  17631. l6500:
  17632.         push    hl
  17633.         push    de
  17634.         call    l65f7
  17635.         pop     de
  17636.         pop     hl
  17637.         cp      6
  17638.         call    l72d4
  17639.         db      _IllTxtFile
  17640.         cp      5
  17641.         jr      z,l64bf
  17642.         ex      de,hl
  17643.         jr      l64bf
  17644. ;
  17645. ; Function MEMAVAIL
  17646. ;
  17647. l6514:
  17648.         ld      hl,l1e3d
  17649.         jr      l64bf
  17650. ;
  17651. ; Function MAXAVAIL
  17652. ;
  17653. l6519:
  17654.         ld      hl,l1e44
  17655.         jr      l64bf
  17656. ;
  17657. ; Procedure BIOS(Integer,Integer)
  17658. ; Function BIOSHL(Integer,Integer)
  17659. ;
  17660. l651e:
  17661.         db      skip
  17662. ;
  17663. ; Function BIOS(Integer,Integer)
  17664. ;
  17665. l651f:
  17666.         xor     a
  17667.         push    af
  17668.         call    l6f66           ; Verify (
  17669.         call    l5e97
  17670.         call    l6b6f           ; Set PUSH HL
  17671.         call    l6f13           ; Test ,
  17672.         jr      nz,l6538        ; Nope
  17673.         call    l5e97
  17674.         call    l6b50           ; Set sequence
  17675.         db      a_L51
  17676. s_I51:
  17677.         LD      B,H
  17678.         LD      C,L
  17679. a_L51   equ     $-s_I51
  17680. l6538:
  17681.         call    l6b50           ; Set POP DE
  17682.         db      a_L52
  17683. s_I52:
  17684.         POP     DE
  17685. a_L52   equ     $-s_I52
  17686.         ld      hl,l1fea
  17687. l6540:
  17688.         call    l6f6e           ; Verify )
  17689.         call    l6b86           ; Set CALL BIOS
  17690.         pop     af
  17691.         ld      b,0ah
  17692.         or      a
  17693.         ret     nz
  17694.         call    l6b50           ; Set sequence
  17695.         db      a_L53
  17696. s_I53:
  17697.         LD      L,A
  17698.         LD      H,0
  17699. a_L53   equ     $-s_I53
  17700.         ret
  17701. ;
  17702. ; Procedure BDOS(Integer,Integer)
  17703. ; Function BDOSHL(Integer,Integer)
  17704. ;
  17705. l6553:
  17706.         db      skip
  17707. ;
  17708. ; Function BDOS(Integer,Integer)
  17709. ;
  17710. l6554:
  17711.         xor     a
  17712.         push    af
  17713.         call    l6f66           ; Verify (
  17714.         call    l5e97
  17715.         call    l6b6f           ; Set PUSH HL
  17716.         call    l6f13           ; Test ,
  17717.         jr      nz,l656c        ; Nope
  17718.         call    l5e97
  17719.         call    l6b50           ; Set EX DE,HL
  17720.         db      a_L54
  17721. s_I54:
  17722.         EX      DE,HL
  17723. a_L54   equ     $-s_I54
  17724. l656c:
  17725.         call    l6b50           ; Set POP BC
  17726.         db      a_L55
  17727. s_I55:
  17728.         POP     BC
  17729. a_L55   equ     $-s_I55
  17730.         ld      hl,BDOS
  17731.         jr      l6540
  17732. ;
  17733. ; Function ADDR(Var)
  17734. ;
  17735. l6576:
  17736.         call    l6f66           ; Verify (
  17737.         ld      bc,256*5+0
  17738.         call    l6e54
  17739.         jr      z,l6589
  17740.         ld      bc,256*6+0
  17741.         call    l6e54
  17742.         jr      nz,l6594
  17743. l6589:
  17744.         dec     hl
  17745.         dec     hl
  17746.         ld      d,(hl)
  17747.         dec     hl
  17748.         ld      e,(hl)
  17749.         ex      de,hl
  17750. l658f:
  17751.         call    l6b92           ; Set LD HL,val16
  17752.         jr      l6597
  17753. l6594:
  17754.         call    l677f
  17755. l6597:
  17756.         call    l6f6e           ; Verify )
  17757.         ld      b,0ah
  17758.         ret
  17759. ;
  17760. ; Function SIZEOF(Var)
  17761. ;
  17762. l659d:
  17763.         call    l6f66           ; Verify (
  17764.         ld      bc,256*3+0
  17765.         call    l6e54
  17766.         jr      nz,l65b1
  17767.         ld      d,(hl)
  17768.         dec     hl
  17769.         ld      e,(hl)
  17770.         ex      de,hl
  17771.         call    l5287           ; Get name
  17772.         jr      l65ba
  17773. l65b1:
  17774.         push    iy
  17775.         call    l677f
  17776.         pop     hl
  17777.         call    l6cc2           ; Check chaining
  17778. l65ba:
  17779.         ld      hl,(l7b62)      ; Get length of type
  17780.         jr      l658f
  17781. ;
  17782. ; Function PORT(Integer)
  17783. ;
  17784. l65bf:
  17785.         call    l65d5
  17786.         call    l6b50           ; Set sequence
  17787.         db      a_L56
  17788. s_I56:
  17789.         LD      C,L
  17790.         IN      L,(C)
  17791. a_L56   equ     $-s_I56
  17792.         ret
  17793. ;
  17794. ; Function STACKPTR
  17795. ;
  17796. l65ca:
  17797.         call    l6b50           ; Set sequence
  17798.         db      a_L57
  17799. s_I57:
  17800.         LD      HL,0
  17801.         ADD     HL,SP
  17802. a_L57   equ     $-s_I57
  17803.         ld      b,0ah
  17804.         ret
  17805. l65d5:
  17806.         call    l6f30           ; Verify [
  17807.         call    l5e97
  17808.         jp      l6f38           ; Verify ]
  17809. l65de:
  17810.         call    l6f66           ; Verify (
  17811.         call    l5e97
  17812. l65e4:
  17813.         jp      l6f6e           ; Verify )
  17814. l65e7:
  17815.         call    l6f66           ; Verify (
  17816.         call    l5ea2
  17817.         jr      l65e4
  17818. l65ef:
  17819.         call    l6f66           ; Verify (
  17820.         call    l5ebb
  17821.         jr      l65e4
  17822. l65f7:
  17823.         call    l6f1b           ; Test (
  17824.         jr      z,l6608         ; Yeap
  17825.         ld      hl,l00c2
  17826.         call    l6b92           ; Set LD HL,val16
  17827.         ld      a,_TxtF
  17828.         ld      (l7b5c),a       ; Set TEXT
  17829.         ret
  17830. l6608:
  17831.         call    l5a17
  17832.         call    l72da
  17833.         db      _FileVarExp
  17834.         push    af
  17835.         call    l6f6e           ; Verify )
  17836.         pop     af
  17837.         ret
  17838. l6615:
  17839.         ld      c,c
  17840.         ld      a,(de)
  17841.         and     17h
  17842.         ld      c,c
  17843.         ld      a,(de)
  17844. ;
  17845. ;
  17846. ;
  17847. l661b:
  17848.         ld      a,(l7b57)
  17849.         ld      c,a
  17850.         ld      hl,(l7b58)      ; Get value
  17851.         ld      a,(l7b5c)       ; Get type
  17852.         cp      _Set
  17853.         jr      nz,l6634
  17854.         call    l6734
  17855.         ld      hl,l0623
  17856.         ld      de,l0612
  17857.         jr      l6648           ; Assign set variable
  17858. l6634:
  17859.         cp      _String
  17860.         jr      nz,l665e
  17861.         ld      a,(l7b62)       ; Get length of type
  17862.         dec     a
  17863.         ld      h,a
  17864.         ld      l,6
  17865.         call    writeword_hl_addriy
  17866.         ld      hl,l0601        ; Assign string from stack
  17867.         ld      de,l05e2        ; Assign string from stack
  17868. l6648:
  17869.         dec     c
  17870.         jr      z,l665b
  17871.         ex      de,hl
  17872. l664c:
  17873.         ld      a,_LD.HL
  17874.         inc     c
  17875.         jr      z,l6653
  17876.         ld      a,_LD_a_HL
  17877. l6653:
  17878.         push    hl
  17879.         ld      hl,(l7b58)      ; Get value
  17880.         call    l6b94
  17881.         pop     hl
  17882. l665b:
  17883.         jp      l6b86           ; Set CALL <call>
  17884. l665e:
  17885.         cp      _Real
  17886.         jr      nz,l6672
  17887.         call    l6b50           ; Set EXX
  17888.         db      a_L58
  17889. s_I58:
  17890.         EXX
  17891. a_L58   equ     $-s_I58
  17892.         ld      hl,l05d1        ; Save real number
  17893.         dec     c
  17894.         jr      nz,l664c
  17895.         call    l6b73           ; Set POP HL
  17896.         jr      l665b
  17897. l6672:
  17898.         cp      _Ptr
  17899.         jr      z,l669d
  17900.         ld      a,(l7b9e)       ; Get local options
  17901.         bit     _Ropt,a         ; Test $R+
  17902.         jr      z,l669d         ; Nope
  17903.         ld      hl,(l7b5e)      ; Get lo set limit
  17904.         ld      de,(l7b60)      ; Get hi set limit
  17905.         inc     de
  17906.         or      a
  17907.         sbc     hl,de
  17908.         add     hl,de
  17909.         jr      z,l669d
  17910.         dec     de
  17911.         call    l6b8e           ; Set LD DE,val16
  17912.         ex      de,hl
  17913.         or      a
  17914.         sbc     hl,de
  17915.         inc     hl
  17916.         call    l6b8a
  17917.         ld      hl,l0656
  17918.         call    l6b86           ; Index check on compiler directive {$R+}
  17919. l669d:
  17920.         dec     c
  17921.         jr      nz,l66b7
  17922.         call    l6b50           ; Set sequence
  17923.         db      a_L59
  17924. s_I59:
  17925.         EX      DE,HL
  17926.         POP     HL
  17927. a_L59   equ     $-s_I59
  17928. l66a6:
  17929.         call    l6b50           ; Set LD (HL),E
  17930.         db      a_L60
  17931. s_I60:
  17932.         LD      (HL),E
  17933. a_L60   equ     $-s_I60
  17934.         ld      a,(l7b62)       ; Get length of type
  17935.         dec     a
  17936.         ret     z
  17937.         call    l6b50           ; Set sequence
  17938.         db      a_L61
  17939. s_I61:
  17940.         INC     HL
  17941.         LD      (HL),D
  17942. a_L61   equ     $-s_I61
  17943.         ret
  17944. l66b7:
  17945.         ld      hl,(l7b58)      ; Get value
  17946.         inc     c
  17947.         jr      nz,l66cf
  17948.         ld      a,(l7b62)       ; Get length of type
  17949.         dec     a
  17950.         ld      a,_LDHL_a
  17951.         jr      nz,l66cc
  17952.         call    l6b50           ; Set LD A,L
  17953.         db      a_L62
  17954. s_I62:
  17955.         LD      A,L
  17956. a_L62   equ     $-s_I62
  17957.         ld      a,_LDA_a
  17958. l66cc:
  17959.         jp      l6b94
  17960. l66cf:
  17961.         call    l6b50           ; Set sequence
  17962.         db      a_L63
  17963. s_I63:
  17964.         EX      DE,HL
  17965.         db      _LD_a_HL
  17966. a_L63   equ     $-s_I63
  17967.         call    writeword_hl_addriy
  17968.         jr      l66a6
  17969. l66da:
  17970.         ld      a,(l7b5c)       ; Get type
  17971.         cp      _Integ
  17972.         jr      nc,l6701
  17973.         cp      _Ptr
  17974.         jr      z,l6701
  17975.         push    af
  17976.         call    l678b
  17977.         pop     af
  17978.         ld      hl,l052c        ; Set load real
  17979.         cp      _Real
  17980.         jr      z,l66fe
  17981.         ld      hl,l053a        ; move string to stack
  17982.         cp      _String
  17983.         jr      z,l66fe
  17984.         call    l6734
  17985.         ld      hl,l055d        ; Push set onto stack
  17986. l66fe:
  17987.         jp      l6b86           ; Set CALL <set>
  17988. l6701:
  17989.         ld      a,(l7bbd)
  17990.         or      a
  17991.         jr      nz,l671b
  17992.         ld      a,_LD_a_HL
  17993.         ld      hl,(l7bbe)
  17994.         call    l6b94
  17995.         ld      a,(l7b62)       ; Get length of type
  17996.         dec     a
  17997.         ret     nz
  17998. l6714:
  17999.         call    l6b50           ; Set LD H,0
  18000.         db      a_L64
  18001. s_I64:
  18002.         LD      H,0
  18003. a_L64   equ     $-s_I64
  18004.         ret
  18005. l671b:
  18006.         call    l678b
  18007.         ld      a,(l7b62)       ; Get length of type
  18008.         dec     a
  18009.         jr      nz,l672b
  18010.         call    l6b50           ; Set LD L,(HL)
  18011.         db      a_L65
  18012. s_I65:
  18013.         LD      L,(HL)
  18014. a_L65   equ     $-s_I65
  18015.         jr      l6714
  18016. l672b:
  18017.         call    l6b50           ; Set sequence
  18018.         db      a_L66
  18019. s_I66:
  18020.         LD      E,(HL)
  18021.         INC     HL
  18022.         LD      D,(HL)
  18023.         EX      DE,HL
  18024. a_L66   equ     $-s_I66
  18025.         ret
  18026. l6734:
  18027.         ld      hl,(l7b5e)      ; Get lo set limit
  18028.         call    l5271           ; Load name
  18029.         ld      hl,(l7b62)      ; Get length of type
  18030.         ld      a,(l7b6b)
  18031.         rra
  18032.         rra
  18033.         rra
  18034.         and     1fh
  18035.         ld      h,a
  18036.         jp      l6b8a
  18037. l6749:
  18038.         call    l6a0d           ; Get constant
  18039.         jr      nz,l677f
  18040.         ld      a,b
  18041.         cp      8
  18042.         call    l72da
  18043.         db      _IllConst
  18044.         ld      l,18h
  18045.         ld      h,c
  18046.         call    writeword_hl_addriy
  18047.         ld      (l7b58),iy      ; Set value
  18048.         ld      a,_Array
  18049.         ld      (l7b5c),a       ; Set ARRAY
  18050.         ld      hl,l74db+7
  18051.         ld      (l7b5e),hl      ; Set lo set limit
  18052.         ld      hl,l0000
  18053.         ld      (l7b60),hl      ; Reset hi set limit
  18054.         ld      l,c
  18055.         ld      (l7b62),hl      ; Set length of type
  18056.         call    l6b62           ; Store string
  18057.         ld      a,_LD.HL
  18058.         ld      hl,(l7b58)      ; Get value
  18059.         jp      l6b94
  18060. l677f:
  18061.         call    l6787
  18062.         ret     z
  18063.         call    l72e1
  18064.         db      _Undef
  18065. l6787:
  18066.         call    l67b2
  18067.         ret     nz
  18068. l678b:
  18069.         ld      a,(l7bbd)
  18070.         ld      hl,(l7bbe)
  18071.         bit     1,a
  18072.         jr      nz,l67a2
  18073.         bit     0,a
  18074.         ld      a,_LD.HL
  18075.         jr      z,l679d
  18076.         ld      a,_LD_a_HL
  18077. l679d:
  18078.         call    l6b94
  18079.         jr      l67b0
  18080. l67a2:
  18081.         bit     0,a
  18082.         jr      nz,l67b0
  18083.         ld      a,_LD.DE
  18084.         call    l6b94
  18085.         call    l6b50           ; Set ADD HL,DE
  18086.         db      a_L67
  18087. s_I67:
  18088.         ADD     HL,DE
  18089. a_L67   equ     $-s_I67
  18090. l67b0:
  18091.         xor     a
  18092.         ret
  18093. l67b2:
  18094.         call    l680c
  18095.         jr      z,l67d9
  18096.         ld      bc,256*4+0
  18097.         call    l6e54
  18098.         jr      nz,l67ed
  18099.         call    l5276
  18100.         ld      a,(l7b57)
  18101.         or      a
  18102.         ld      a,'!'
  18103.         ld      b,0
  18104.         jr      z,l67cf
  18105.         ld      a,'*'
  18106.         inc     b
  18107. l67cf:
  18108.         ld      hl,l7bbd
  18109.         ld      (hl),b
  18110.         ld      hl,(l7b58)      ; Get value
  18111.         ld      (l7bbe),hl
  18112. l67d9:
  18113.         call    l683a
  18114.         jr      z,l67d9
  18115.         call    l6931
  18116.         jr      z,l67d9
  18117.         call    l6974
  18118.         jr      z,l67d9
  18119.         call    l699f
  18120.         xor     a
  18121.         ret
  18122. l67ed:
  18123.         call    l6e76           ; Find MEM
  18124.         dw      l78fa
  18125.         ret     nz              ; Nope
  18126.         call    l65d5
  18127.         ld      a,_Integ
  18128.         ld      (l7b5c),a       ; Set INTEGER
  18129.         ld      hl,l0001
  18130.         ld      (l7b62),hl      ; Set length of type
  18131.         dec     l
  18132.         ld      (l7b5e),hl      ; Set lo set limit
  18133.         dec     l
  18134.         ld      (l7b60),hl      ; Set hi set limit
  18135.         jp      l6903
  18136. l680c:
  18137.         ld      a,(l7bc9)
  18138.         ld      b,a
  18139. l6810:
  18140.         dec     b
  18141.         ret     m
  18142.         push    bc
  18143.         ld      e,b
  18144.         ld      d,0
  18145.         ld      hl,l7bcc
  18146.         add     hl,de
  18147.         ld      a,(hl)
  18148.         ld      c,a
  18149.         ld      b,4
  18150.         call    l6e54
  18151.         pop     bc
  18152.         jr      nz,l6810
  18153.         push    hl
  18154.         ld      a,b
  18155.         add     a,a
  18156.         ld      e,a
  18157.         ld      d,0
  18158.         ld      hl,(l7bca)
  18159.         add     hl,de
  18160.         ld      (l7bbe),hl
  18161.         ld      hl,l7bbd
  18162.         ld      (hl),1
  18163.         pop     hl
  18164.         jp      l6948
  18165. l683a:
  18166.         ld      a,(l7b5c)       ; Get type
  18167.         cp      _Array
  18168.         ret     nz
  18169.         call    l6ee0
  18170.         ret     nz
  18171.         call    l678b
  18172. l6847:
  18173.         call    l6b6f           ; Set PUSH HL
  18174.         call    l5e84
  18175.         ld      hl,(l7b60)      ; Get hi set limit
  18176.         call    l5271           ; Load name
  18177.         ld      a,(l7b69)
  18178.         cp      b
  18179.         call    l72da
  18180.         db      _InvType
  18181.         ld      hl,(l7b6b)
  18182.         ld      a,h
  18183.         or      a
  18184.         jr      nz,l6874
  18185.         ld      a,l
  18186.         cp      4
  18187.         jr      nc,l6888
  18188. l6867:
  18189.         or      a
  18190.         jr      z,l6893
  18191.         push    af
  18192.         call    l6b50           ; Set DEC HL
  18193.         db      a_L68
  18194. s_I68:
  18195.         DEC     HL
  18196. a_L68   equ     $-s_I68
  18197.         pop     af
  18198.         dec     a
  18199.         jr      l6867
  18200. l6874:
  18201.         inc     a
  18202.         jr      nz,l6888
  18203.         ld      a,l
  18204.         cp      0fdh
  18205.         jr      c,l6888
  18206. l687c:
  18207.         push    af
  18208.         call    l6b50           ; Set INC HL
  18209.         db      a_L69
  18210. s_I69:
  18211.         INC     HL
  18212. a_L69   equ     $-s_I69
  18213.         pop     af
  18214.         inc     a
  18215.         jr      nz,l687c
  18216.         jr      l6893
  18217. l6888:
  18218.         call    l6a30
  18219.         call    l6b8e           ; Set LD DE,val16
  18220.         call    l6b50           ; Set ADD HL,DE
  18221.         db      a_L70
  18222. s_I70:
  18223.         ADD     HL,DE
  18224. a_L70   equ     $-s_I70
  18225. l6893:
  18226.         ld      a,(l7b9e)       ; Get local options
  18227.         bit     _Ropt,a         ; Test $R+
  18228.         jr      z,l68ae
  18229.         ld      hl,(l7b6d)      ; Get last memory address
  18230.         ld      de,(l7b6b)
  18231.         or      a
  18232.         sbc     hl,de
  18233.         inc     hl
  18234.         call    l6b8e           ; Set LD DE,val16
  18235.         ld      hl,l064c
  18236.         call    l6b86           ; Index check on compiler directive {$R+}
  18237. l68ae:
  18238.         ld      hl,(l7b5e)      ; Get lo set limit
  18239.         call    l5287           ; Get name
  18240.         ld      hl,(l7b62)      ; Get length of type
  18241.         ld      a,h
  18242.         or      a
  18243.         jr      nz,l68d8
  18244.         ld      a,l
  18245.         dec     a
  18246.         jr      z,l68ed
  18247.         dec     a
  18248.         jr      nz,l68c9
  18249.         call    l6b50           ; Set ADD HL,HL
  18250.         db      a_L71
  18251. s_I71:
  18252.         ADD     HL,HL
  18253. a_L71   equ     $-s_I71
  18254.         jr      l68ed
  18255. l68c9:
  18256.         cp      4
  18257.         jr      nz,l68d8
  18258.         call    l6b50           ; Set sequence
  18259.         db      a_L72
  18260. s_I72:
  18261.         ADD     HL,HL
  18262.         LD      E,L
  18263.         LD      D,H
  18264.         ADD     HL,HL
  18265.         ADD     HL,DE
  18266. a_L72   equ     $-s_I72
  18267.         jr      l68ed
  18268. l68d8:
  18269.         ld      a,(l7b9e)       ; Get local options
  18270.         bit     _Xopt,a         ; Test $X+
  18271.         jr      nz,l68ea        ; Yeap
  18272.         call    l6b8e           ; Set LD DE,val16
  18273.         ld      hl,l06f5        ; Set integer multiply
  18274.         call    l6b86
  18275.         jr      l68ed
  18276. l68ea:
  18277.         call    l690a
  18278. l68ed:
  18279.         call    l6b50           ; Set sequence
  18280.         db      a_L73
  18281. s_I73:
  18282.         POP     DE
  18283.         ADD     HL,DE
  18284. a_L73   equ     $-s_I73
  18285.         ld      a,(l7b5c)       ; Get type
  18286.         cp      _Array
  18287.         jr      nz,l6900
  18288.         call    l6f13           ; Test ,
  18289.         jp      z,l6847         ; Yeap
  18290. l6900:
  18291.         call    l6f38           ; Verify ]
  18292. l6903:
  18293.         ld      a,3
  18294.         ld      (l7bbd),a
  18295.         xor     a
  18296.         ret
  18297. l690a:
  18298.         ld      b,1
  18299. l690c:
  18300.         ld      a,h
  18301.         or      a
  18302.         jr      nz,l6914
  18303.         ld      a,l
  18304.         dec     a
  18305.         jr      z,l6927
  18306. l6914:
  18307.         bit     0,l
  18308.         jr      z,l691c
  18309.         call    l6b6f           ; Set PUSH HL
  18310.         inc     b
  18311. l691c:
  18312.         call    l6b50           ; Set ADD HL,HL
  18313.         db      a_L74
  18314. s_I74:
  18315.         ADD     HL,HL
  18316. a_L74   equ     $-s_I74
  18317.         srl     h
  18318.         rr      l
  18319.         jr      l690c
  18320. l6927:
  18321.         dec     b
  18322.         ret     z
  18323.         call    l6b50           ; Set sequence
  18324.         db      a_L75
  18325. s_I75:
  18326.         POP     DE
  18327.         ADD     HL,DE
  18328. a_L75   equ     $-s_I75
  18329.         jr      l6927
  18330. l6931:
  18331.         ld      a,(l7b5c)       ; Get type
  18332.         cp      _Record
  18333.         ret     nz
  18334.         call    l6f17
  18335.         ret     nz
  18336.         ld      a,(l7b5d)
  18337.         ld      c,a
  18338.         ld      b,4
  18339.         call    l6e54
  18340.         call    l72da
  18341.         db      _Undef
  18342. l6948:
  18343.         call    l5276
  18344.         ld      hl,(l7b58)      ; Get value
  18345.         ld      a,h
  18346.         or      l
  18347.         ret     z
  18348.         ld      hl,l7bbd
  18349.         bit     0,(hl)
  18350.         jr      z,l6967
  18351.         push    hl
  18352.         call    l678b
  18353.         pop     hl
  18354.         ld      (hl),2
  18355.         ld      hl,(l7b58)      ; Get value
  18356.         ld      (l7bbe),hl
  18357.         xor     a
  18358.         ret
  18359. l6967:
  18360.         ld      hl,(l7bbe)
  18361.         ld      de,(l7b58)      ; Get value
  18362.         add     hl,de
  18363.         ld      (l7bbe),hl
  18364.         xor     a
  18365.         ret
  18366. l6974:
  18367.         ld      a,(l7b5c)       ; Get type
  18368.         cp      _Ptr
  18369.         ret     nz
  18370.         call    l6f27
  18371.         ret     nz
  18372.         ld      hl,l7bbd
  18373.         ld      a,(hl)
  18374.         or      a
  18375.         jr      nz,l6988
  18376.         inc     (hl)
  18377.         jr      l6997
  18378. l6988:
  18379.         push    hl
  18380.         call    l678b
  18381.         pop     hl
  18382.         ld      (hl),3
  18383.         call    l6b50           ; Set sequence
  18384.         db      a_L76
  18385. s_I76:
  18386.         LD      E,(HL)
  18387.         INC     HL
  18388.         LD      D,(HL)
  18389.         EX      DE,HL
  18390. a_L76   equ     $-s_I76
  18391. l6997:
  18392.         ld      hl,(l7b5e)      ; Get lo set limit
  18393.         call    l5287           ; Get name
  18394.         xor     a
  18395.         ret
  18396. l699f:
  18397.         ld      a,(l7b5c)       ; Get type
  18398.         cp      _String
  18399.         ret     nz
  18400.         call    l6ee0
  18401.         ret     nz
  18402.         call    l678b
  18403.         call    l6b6f           ; Set PUSH HL
  18404.         ld      hl,(l7b62)      ; Get length of type
  18405.         push    hl
  18406.         call    l5e97
  18407.         pop     hl
  18408.         ld      a,(l7b9e)       ; Get local options
  18409.         bit     _Ropt,a         ; Test $R+
  18410.         jr      z,l69c7         ; Nope
  18411.         call    l6b8e           ; Set LD DE,val16
  18412.         ld      hl,l064c
  18413.         call    l6b86           ; Index check on compiler directive {$R+}
  18414. l69c7:
  18415.         call    l6b50           ; Set sequence
  18416.         db      a_L77
  18417. s_I77:
  18418.         POP     DE
  18419.         ADD     HL,DE
  18420. a_L77   equ     $-s_I77
  18421.         call    l6f38           ; Verify ]
  18422.         ld      a,_Char
  18423.         ld      (l7b5c),a       ; Set CHAR
  18424.         ld      hl,l0001
  18425.         ld      (l7b62),hl      ; Set length of type
  18426.         dec     hl
  18427.         ld      (l7b5e),hl      ; Set lo set limit
  18428.         dec     l
  18429.         ld      (l7b60),hl      ; Set hi set limit
  18430.         ld      a,3
  18431.         ld      (l7bbd),a
  18432.         xor     a
  18433.         ret
  18434. ;
  18435. ; Get constant
  18436. ;
  18437. l69ea:
  18438.         call    l6a0d           ; Get constant
  18439.         ret     z
  18440.         call    l72e1
  18441.         db      _Undef
  18442. ;
  18443. ; Get integer constant
  18444. ;
  18445. l69f2:
  18446.         call    l69ea           ; Get constant
  18447.         ld      a,b
  18448.         cp      0ah
  18449.         ret     z
  18450.         call    l72e1
  18451.         db      _IntConst
  18452. ;
  18453. ; Get string constant
  18454. ;
  18455. l69fd:
  18456.         call    l69ea           ; Get constant
  18457.         ld      a,b
  18458.         cp      8
  18459.         ret     z
  18460.         cp      0ch
  18461.         call    l72da
  18462.         db      _StrgConExp
  18463.         ld      b,8
  18464.         ret
  18465. ;
  18466. ; Get constant
  18467. ;
  18468. l6a0d:
  18469.         call    l6a39
  18470.         push    de
  18471.         call    l6a5c
  18472.         pop     de
  18473.         jr      z,l6a1f
  18474.         inc     e
  18475.         dec     e
  18476.         call    l72da
  18477.         db      _IntRealCexp
  18478.         dec     e
  18479.         ret
  18480. l6a1f:
  18481.         call    l6a4a
  18482.         ret     z
  18483.         ld      a,b
  18484.         cp      9
  18485.         jr      nz,l6a30
  18486.         exx
  18487.         ld      a,b
  18488.         xor     80h
  18489.         ld      b,a
  18490.         exx
  18491.         xor     a
  18492.         ret
  18493. l6a30:
  18494.         ld      a,h
  18495.         cpl
  18496.         ld      h,a
  18497.         ld      a,l
  18498.         cpl
  18499.         ld      l,a
  18500.         inc     hl
  18501.         xor     a
  18502.         ret
  18503. l6a39:
  18504.         ld      e,0ffh
  18505.         ld      a,(ix+0)
  18506.         cp      '-'
  18507.         jr      z,l6a47
  18508.         inc     e
  18509.         cp      '+'
  18510.         ret     nz
  18511.         inc     e
  18512. l6a47:
  18513.         jp      l6f92           ; Process line
  18514. l6a4a:
  18515.         inc     e
  18516.         dec     e
  18517.         ret     z
  18518.         ld      a,b
  18519.         cp      0ah
  18520.         jr      z,l6a56
  18521.         cp      9
  18522.         jr      nz,l6a58
  18523. l6a56:
  18524.         dec     e
  18525.         ret
  18526. l6a58:
  18527.         call    l72e1
  18528.         db      _IntRealCexp
  18529. l6a5c:
  18530.         call    l6a99           ; Sample constant
  18531.         ret     z               ; Got one
  18532.         ld      bc,256*2+0
  18533.         call    l6e54
  18534.         ret     nz
  18535.         ld      b,(hl)
  18536.         ld      a,b
  18537.         dec     hl
  18538.         cp      0ah
  18539.         jr      c,l6a74
  18540.         ld      d,(hl)
  18541.         dec     hl
  18542.         ld      e,(hl)
  18543.         ex      de,hl
  18544.         xor     a
  18545.         ret
  18546. l6a74:
  18547.         cp      9
  18548.         jr      nz,l6a88
  18549.         push    bc
  18550.         ld      b,(hl)
  18551.         dec     hl
  18552.         ld      c,(hl)
  18553.         dec     hl
  18554.         ld      d,(hl)
  18555.         dec     hl
  18556.         ld      e,(hl)
  18557.         dec     hl
  18558.         ld      a,(hl)
  18559.         dec     hl
  18560.         ld      l,(hl)
  18561.         ld      h,a
  18562.         exx
  18563.         pop     bc
  18564.         ret
  18565. l6a88:
  18566.         ld      c,(hl)
  18567.         ld      de,l7a57
  18568.         push    bc
  18569.         inc     c
  18570. l6a8e:
  18571.         dec     c
  18572.         jr      z,l6a97
  18573.         dec     hl
  18574.         ld      a,(hl)
  18575.         ld      (de),a
  18576.         inc     de
  18577.         jr      l6a8e
  18578. l6a97:
  18579.         pop     bc
  18580.         ret
  18581. ;
  18582. ; Sample constant - Z set indicates constant
  18583. ;
  18584. ; Reg B holds type of constant
  18585. ; Reg C holds length of constant
  18586. ;
  18587. l6a99:
  18588.         ld      a,(ix+0)        ; Get character
  18589.         cp      ''''            ; Test string
  18590.         jr      z,l6aa8
  18591.         cp      '^'             ; Test control character prefix
  18592.         jr      z,l6aa8
  18593.         cp      '#'             ; Test character prefix
  18594.         jr      nz,l6b0e
  18595. l6aa8:
  18596.         ld      hl,l7a57        ; Init parameter buffer
  18597.         ld      c,0             ; Init length
  18598. l6aad:
  18599.         ld      a,(ix+0)
  18600.         cp      '^'             ; Test control character prefix
  18601.         jr      z,l6ad8
  18602.         cp      '#'             ; Test character prefix
  18603.         jr      z,l6aee
  18604.         cp      ''''            ; Test string
  18605.         jr      nz,l6afe
  18606. l6abc:
  18607.         inc     ix
  18608.         ld      a,(ix+0)
  18609.         or      a
  18610.         call    l72d4
  18611.         db      _StrConLong
  18612.         cp      ''''
  18613.         jr      nz,l6ad3
  18614.         inc     ix
  18615.         ld      a,(ix+0)
  18616.         cp      ''''
  18617.         jr      nz,l6aad
  18618. l6ad3:
  18619.         ld      (hl),a
  18620.         inc     hl
  18621.         inc     c
  18622.         jr      l6abc
  18623. l6ad8:
  18624.         inc     ix
  18625.         ld      a,(ix+0)
  18626.         call    l04a6           ; Convert to upper case
  18627.         or      a
  18628.         call    l72d4
  18629.         db      _StrConLong
  18630.         xor     '@'
  18631.         inc     ix
  18632. l6ae9:
  18633.         ld      (hl),a
  18634.         inc     hl
  18635.         inc     c
  18636.         jr      l6aad
  18637. l6aee:
  18638.         inc     ix
  18639.         push    bc
  18640.         push    hl
  18641.         call    l07f7           ; Convert ASCII to integer
  18642.         ld      a,l
  18643.         pop     hl
  18644.         pop     bc
  18645.         call    l72c8
  18646.         db      _IntegErr
  18647.         jr      l6ae9
  18648. l6afe:
  18649.         ld      b,8
  18650.         ld      a,c
  18651.         dec     a
  18652.         jr      nz,l6b0b
  18653.         ld      h,a
  18654.         ld      a,(l7a57)
  18655.         ld      l,a
  18656.         ld      b,0ch
  18657. l6b0b:
  18658.         jp      l6f95           ; Process line
  18659. l6b0e:
  18660.         cp      '$'
  18661.         jr      z,l6b45
  18662.         call    l7286           ; Test digit
  18663.         jr      nc,l6b1a
  18664.         xor     a
  18665.         dec     a
  18666.         ret
  18667. l6b1a:
  18668.         push    ix
  18669.         pop     de
  18670. l6b1d:
  18671.         inc     de
  18672.         ld      a,(de)
  18673.         call    l7286           ; Test digit
  18674.         jr      nc,l6b1d
  18675.         call    l04a6           ; Convert to upper case
  18676.         cp      'E'
  18677.         jr      z,l6b39
  18678.         cp      '.'
  18679.         jr      nz,l6b45
  18680.         inc     de
  18681.         ld      a,(de)
  18682.         cp      '.'
  18683.         jr      z,l6b45
  18684.         cp      ')'
  18685.         jr      z,l6b45
  18686. l6b39:
  18687.         call    l11a3
  18688.         call    l72c8
  18689.         db      _RealErr
  18690.         exx
  18691.         ld      b,9
  18692.         jr      l6b0b
  18693. l6b45:
  18694.         call    l07f7           ; Convert ASCII to integer
  18695.         call    l72c8
  18696.         db      _IntegErr
  18697.         ld      b,0ah
  18698.         jr      l6b0b
  18699. ;
  18700. ; Transfer immediate opcodes
  18701. ; Sequence starts with length
  18702. ;
  18703. l6b50:
  18704.         ex      (sp),hl
  18705.         push    bc
  18706.         ld      b,(hl)          ; Get length
  18707.         inc     hl
  18708. l6b54:
  18709.         ld      a,(hl)          ; Get byte
  18710.         call    writebyte_a_addriy              ; Store it
  18711.         inc     hl
  18712.         djnz    l6b54
  18713.         pop     bc
  18714.         ex      (sp),hl
  18715.         ret
  18716. l6b5e:
  18717.         ld      a,c             ; Get byte
  18718.         call    writebyte_a_addriy              ; Store it
  18719. ;
  18720. ; Store string
  18721. ;
  18722. l6b62:
  18723.         ld      hl,l7a57
  18724.         inc     c
  18725. l6b66:
  18726.         dec     c
  18727.         ret     z
  18728.         ld      a,(hl)          ; Get character
  18729.         inc     hl
  18730.         call    writebyte_a_addriy              ; Store it
  18731.         jr      l6b66
  18732. ;
  18733. ; Set PUSH HL
  18734. ;
  18735. l6b6f:
  18736.         ld      a,_PUSH.HL
  18737.         jr      writebyte_a_addriy
  18738. ;
  18739. ; Set POP HL
  18740. ;
  18741. l6b73:
  18742.         ld      a,_POP.HL
  18743.         jr      writebyte_a_addriy
  18744. ;
  18745. ; Set JP
  18746. ;
  18747. l6b77:
  18748.         ld      a,_JP
  18749.         jr      writebyte_a_addriy
  18750. ;
  18751. ; Set word in reg DE
  18752. ;
  18753. writeword_de_addriy:
  18754.         ld      a,e
  18755.         call    writebyte_a_addriy
  18756.         ld      a,d
  18757.         jr      writebyte_a_addriy
  18758. ;
  18759. ; Set JP WORD
  18760. ;
  18761. l6b82:
  18762.         ld      a,_JP
  18763.         jr      l6b94
  18764. ;
  18765. ; Set CALL WORD
  18766. ;
  18767. l6b86:
  18768.         ld      a,_CALL
  18769.         jr      l6b94
  18770. ;
  18771. ; Set LD BC,WORD
  18772. ;
  18773. l6b8a:
  18774.         ld      a,_LD.BC
  18775.         jr      l6b94
  18776. ;
  18777. ; Set LD DE,WORD
  18778. ;
  18779. l6b8e:
  18780.         ld      a,_LD.DE
  18781.         jr      l6b94
  18782. ;
  18783. ; Set LD HL,WORD
  18784. ;
  18785. l6b92:
  18786.         ld      a,_LD.HL
  18787. ;
  18788. ; Insert opcodes in Accu, reg L and reg H
  18789. ;
  18790. l6b94:
  18791.         call    writebyte_a_addriy
  18792. ;
  18793. ; Insert word in reg HL
  18794. ;
  18795. writeword_hl_addriy:
  18796.         ld      a,l
  18797.         call    writebyte_a_addriy
  18798.         ld      a,h
  18799. ;
  18800. ; Insert byte in Accu
  18801. ;
  18802. writebyte_a_addriy:
  18803.         push    bc
  18804.         ld      b,a
  18805.         ld      a,(l7900)       ; Get compile flag
  18806.         or      a               ; Test mode
  18807.         jr      nz,l6ba7        ; Searching or compiling       
  18808.         ld      (iy+0),b        ; Store byte into memory
  18809. l6ba7:
  18810.         inc     iy              ; Update PC
  18811.         or      a               ; Test compile to memory
  18812.         jr      z,l6bc6         ; Yeap
  18813.         push    hl
  18814.         push    de
  18815.         dec     a               ; Test search
  18816.         jr      z,l6bc1         ; Nope
  18817.         push    iy
  18818.         pop     de
  18819.         dec     de
  18820.         ld      hl,(l00ce)      ; Get current PC
  18821.         or      a
  18822.         sbc     hl,de
  18823.         call    l72d4
  18824.         db      _FndRTerr
  18825.         jr      l6bc4
  18826. l6bc1:
  18827.         call    savebyte_b              ; Put byte to file
  18828. l6bc4:
  18829.         pop     de
  18830.         pop     hl
  18831. l6bc6:
  18832.         pop     bc
  18833. ;
  18834. ; Check enough memory
  18835. ;
  18836. l6bc7:
  18837.         push    hl
  18838.         push    de
  18839.         push    iy
  18840.         pop     de
  18841.         ld      a,(l7900)       ; Get compile flag
  18842.         or      a
  18843.         jr      z,l6be7         ; Skip if compiling to memory
  18844.         ld      de,(l7bdf)      ; Get memory top
  18845.         dec     a
  18846.         jr      nz,l6be7
  18847.         ld      de,(l7be1)      ; Get top of .COM file
  18848.         ld      a,(l790e)       ; Test memory read
  18849.         or      a
  18850.         jr      z,l6be7         ; Yeap
  18851.         ld      de,(l7be6)
  18852. l6be7:
  18853.         ld      hl,(l7b73)      ; Get label pointer
  18854.         scf
  18855.         sbc     hl,de
  18856.         call    l72c8
  18857.         db      _CompOvfl
  18858.         push    iy
  18859.         pop     de
  18860.         ld      hl,(l7908)      ; Get start of data
  18861.         dec     h
  18862.         dec     h
  18863.         sbc     hl,de
  18864.         call    l72c8
  18865.         db      _MemOvfl
  18866.         pop     de
  18867.         pop     hl
  18868.         ret
  18869. ;
  18870. ; Put byte in reg B to file
  18871. ;
  18872. savebyte_b:
  18873.         ld      hl,l7bdb        ; Point to file access
  18874.         set     1,(hl)          ; Set write enabled
  18875.         bit     0,(hl)          ; Test re-read
  18876.         jr      z,l6c12         ; Nope
  18877.         res     0,(hl)          ; Clear it
  18878.         push    bc
  18879.         call    readrecord_l7957                ; Re-read record
  18880.         pop     bc
  18881. l6c12:
  18882.         ld      a,(l7bdc)       ; Get record pointer
  18883.         ld      e,a
  18884.         ld      d,0
  18885.         ld      hl,l7957
  18886.         add     hl,de           ; Build buffer address
  18887.         ld      (hl),b          ; Store byte
  18888.         inc     a               ; Advance record pointer
  18889.         jp      p,l6c2c         ; Still within limits
  18890.         call    writerecord_l7957               ; Write record
  18891.         ld      hl,(l7933+_rrn)
  18892.         inc     hl              ; Advance record count
  18893.         ld      (l7933+_rrn),hl
  18894.         xor     a
  18895. l6c2c:
  18896.         ld      (l7bdc),a       ; Set record pointer
  18897.         ret
  18898. ;
  18899. ; Allocate space in reg DE
  18900. ;
  18901. l6c30:
  18902.         ld      hl,(l7908)      ; Get start of data
  18903.         or      a
  18904.         sbc     hl,de
  18905.         call    l72c8
  18906.         db      _MemOvfl
  18907.         ld      (l7908),hl      ; Set start of data
  18908.         jr      l6bc7           ; Check enough memory
  18909. ;
  18910. ; Store back current PC to ^HL
  18911. ;
  18912. storeback_iy_to_addrhl:
  18913.         push    iy              ; Get PC
  18914.         pop     de
  18915. ;
  18916. ; Store back reg DE to ^HL
  18917. ;
  18918. storeback_de_to_addrhl:
  18919.         ld      a,(l7900)       ; Get compile flag
  18920.         dec     a               ; Test compiling to memory
  18921.         jr      z,l6c53         ; nope
  18922.         push    iy
  18923.         push    hl
  18924.         pop     iy
  18925.         call    writeword_de_addriy             ; Set word
  18926.         pop     iy
  18927.         ret
  18928. flushunfinished
  18929.         ld a,(l7bdc)    ; Get record pointer
  18930.         or a
  18931.         ret z
  18932.          push bc
  18933.          push de
  18934.          push hl
  18935.         ;ld a,h
  18936.         ;and l
  18937.         ;inc a ;-1=fake record number
  18938.         ;jr z,flushunfinished_skip
  18939.          call flushunfinishedpp
  18940. ;flushunfinished_skip
  18941. ;close, open to force flush???
  18942.         ;ld de,l7933
  18943.         ;ld c,_close
  18944.         ;call l7265             ; BDOS with keep ix,iy
  18945.         ;ld de,l7933
  18946.         ;ld c,_open
  18947.         ;call l7265             ; BDOS with keep ix,iy
  18948.          pop hl
  18949.          pop de
  18950.          pop bc
  18951.          ret
  18952. l6c53:
  18953.          call flushunfinished
  18954.         push    bc
  18955.         push    de
  18956.         push    hl
  18957.         ld      hl,(l7bdf)      ; Get memory top
  18958.         ld      a,(l7be3)       ; Get back fix level
  18959.         ld      b,a
  18960.         inc     b
  18961. l6c5e:
  18962.         dec     b
  18963.         jr      z,l6c84
  18964.         ld      e,(hl)
  18965.         inc     hl
  18966.         ld      d,(hl)
  18967.         ex      (sp),hl
  18968.         or      a
  18969.         sbc     hl,de
  18970.         add     hl,de
  18971.         ex      (sp),hl
  18972.         jr      c,l6c71
  18973.         inc     hl
  18974.         inc     hl
  18975.         inc     hl
  18976.         jr      l6c5e
  18977. l6c71:
  18978.         dec     hl
  18979.         ex      de,hl
  18980.         ld      l,b
  18981.         ld      h,0
  18982.         add     hl,hl
  18983.         add     hl,hl
  18984.         ld      b,h
  18985.         ld      c,l
  18986.         add     hl,de
  18987.         ld      d,h
  18988.         ld      e,l
  18989.         dec     hl
  18990.         inc     de
  18991.         inc     de
  18992.         inc     de
  18993.         lddr
  18994.         inc     hl
  18995. l6c84:
  18996.         pop     de
  18997.         ld      (hl),e
  18998.         inc     hl
  18999.         ld      (hl),d
  19000.         inc     hl
  19001.         pop     de
  19002.         ld      (hl),e
  19003.         inc     hl
  19004.         ld      (hl),d
  19005.         pop     bc
  19006.         ld      hl,l7be3        ; Point to back fix level
  19007.         inc     (hl)
  19008.         ret     nz
  19009.         xor     a
  19010.         jr      l6c9b
  19011. ;
  19012. ; Fix back level
  19013. ;
  19014. l6c96:
  19015.         ld      a,(l7be3)       ; Get back fix level
  19016.         or      a
  19017.         ret     z
  19018. l6c9b:
  19019.         push    bc
  19020.         push    de
  19021.         push    iy
  19022.         ld      b,a
  19023.         ld      hl,(l7bdf)      ; Get memory top
  19024. l6ca3:
  19025.         push    bc
  19026.         ld      e,(hl)
  19027.         inc     hl
  19028.         ld      d,(hl)
  19029.         inc     hl
  19030.         push    hl
  19031.         ex      de,hl
  19032.         call    l6cc2           ; Check chaining
  19033.         pop     hl
  19034.         ld      b,(hl)
  19035.         inc     hl
  19036.         push    hl
  19037.         call    savebyte_b              ; Put byte to file
  19038.         pop     hl
  19039.         ld      b,(hl)
  19040.         inc     hl
  19041.         push    hl
  19042.         call    savebyte_b              ; Put byte to file
  19043.         pop     hl
  19044.         pop     bc
  19045.         djnz    l6ca3
  19046.         pop     hl
  19047.         pop     de
  19048.         pop     bc
  19049. ;
  19050. ; Check chaining
  19051. ;
  19052. l6cc2:
  19053.          ld     a,(l7900)       ; Get compile flag
  19054.          dec    a               ; Test compiling to memory
  19055.          call z,flushunfinished ;nope
  19056.         push    hl
  19057.         pop     iy
  19058.         ld      a,(l7900)       ; Get compile flag
  19059.         dec     a               ; Test compiling to memory
  19060.         ret     nz              ; yes
  19061.         push    de
  19062.         push    bc
  19063.         ld      de,(l7902)      ; Get code pointer
  19064.         or      a
  19065.         sbc     hl,de
  19066.         ld      a,l
  19067.         and     7fh
  19068.         ld      (l7bdc),a       ; Set record pointer
  19069.         add     hl,hl
  19070.         ld      l,h
  19071.         rla
  19072.         and     1
  19073.         ld      h,a
  19074.         ld      de,(l7bdd)      ; Get record base
  19075.         add     hl,de           ; Calculate new record
  19076.         ld      de,(l7933+_rrn)
  19077.         or      a
  19078.         sbc     hl,de
  19079.         add     hl,de
  19080.         jr      z,l6cf6
  19081.         push    hl
  19082.         call    writerecord_l7957               ; Write record
  19083.         pop     hl
  19084.         ld      (l7933+_rrn),hl ; Reset record
  19085. l6cf6:
  19086.         pop     bc
  19087.         pop     de
  19088.         ret
  19089.  
  19090. ;
  19091. ; Read a record
  19092. ;
  19093. readrecord_l7957:
  19094.          ;ld hl,(l7933+_rrn)
  19095.          ;jr $
  19096.         ld      c,_rndrd
  19097.         jr      l6d09
  19098. ;
  19099. ; Write a record
  19100. ;
  19101. writerecord_l7957:
  19102.         ld      hl,l7bdb        ; Point to file access
  19103.         set     0,(hl)          ; Set re-read enabled
  19104.         bit     1,(hl)          ; Test record to be written
  19105.         ret     z               ; Nope
  19106.         res     1,(hl)          ; Reset it
  19107. flushunfinishedpp
  19108. ;write unfinished last sector???
  19109.         ld      c,_rndwr
  19110. l6d09:
  19111.         push    bc              ; Save function
  19112.         ld      de,l7957
  19113.         ld      c,_setdma
  19114.         call    l7265           ; Set disk buffer
  19115.         pop     bc
  19116.         ld      de,l7933
  19117.         call    l7265           ; Read or write record
  19118.         or      a
  19119.         ret     z
  19120.         ;dec    a
  19121.         ;ret    z
  19122.         ;cp     3
  19123.         ;ret    z
  19124.          cp 128 ;fail
  19125.          ret nz ;not fail
  19126.         call    l72e1
  19127.         db      _DskFull
  19128. l6d24:
  19129.         exx
  19130.         ld      de,l7b64
  19131.         jr      l6d2e
  19132. ;
  19133. ; Save environment
  19134. ;
  19135. l6d2a:
  19136.         exx
  19137.         ld      de,l7b57
  19138. l6d2e:
  19139.         pop     hl
  19140.         ld      (l7bd5),hl
  19141.         ld      hl,lfff3
  19142.         add     hl,sp
  19143.         ld      sp,hl
  19144.         ex      de,hl
  19145.         ld      bc,l000d
  19146.         ldir
  19147. l6d3d:
  19148.         ld      hl,(l7bd5)
  19149.         push    hl
  19150.         exx
  19151.         ret
  19152. l6d43:
  19153.         exx
  19154.         ld      de,l7b64
  19155.         jr      l6d4d
  19156. ;
  19157. ; Get back environment
  19158. ;
  19159. l6d49:
  19160.         exx
  19161.         ld      de,l7b57
  19162. l6d4d:
  19163.         pop     hl
  19164.         ld      (l7bd5),hl
  19165.         ld      hl,l0000
  19166.         add     hl,sp
  19167.         ld      bc,l000d
  19168.         ldir
  19169.         ld      sp,hl
  19170.         jr      l6d3d
  19171. l6d5d:
  19172.         exx
  19173.         ld      de,l7b64
  19174.         jr      l6d67
  19175. l6d63:
  19176.         exx
  19177.         ld      de,l7b57
  19178. l6d67:
  19179.         ld      hl,l0002
  19180.         add     hl,sp
  19181.         ld      bc,l000d
  19182.         ldir
  19183.         exx
  19184.         ret
  19185. ;
  19186. ; Put current PC to table
  19187. ;
  19188. puttolabel_i_y:
  19189.         push    iy
  19190.         pop     de
  19191. puttolabel_d_e:
  19192.         ld      a,d
  19193.         call    puttolabel
  19194.         ld      a,e
  19195. puttolabel:
  19196.         push    hl
  19197.         ld      hl,(l7b73)      ; Get label pointer
  19198.         ld      (hl),a
  19199.         dec     hl
  19200.         ld      (l7b73),hl      ; Set label pointer
  19201.         pop     hl
  19202.         jp      l6bc7           ; Check enough memory
  19203. ;
  19204. ; Get label
  19205. ;
  19206. l6d87:
  19207.         ld      a,(ix+0)
  19208.         call    l7271           ; Test label character
  19209. ;
  19210. ; Build label
  19211. ;
  19212. l6d8d:
  19213.         call    l72c8
  19214.         db      _IllChar
  19215.         call    l6ed0
  19216. l6d94:
  19217.         call    l6eb8
  19218.         ld      a,(ix+0)
  19219. l6d9a:
  19220.         cp      'a'
  19221.         jr      c,l6da4
  19222.         cp      'z'+1
  19223.         jr      nc,l6da4
  19224.         sub     'a'-'A'
  19225. l6da4:
  19226.         call    puttolabel
  19227.         inc     ix
  19228.         ld      a,(ix+0)
  19229.         call    l7282           ; Test valid character
  19230.         jr      nc,l6d9a        ; Yeap
  19231.         ld      hl,(l7b73)      ; Get label pointer
  19232.         inc     hl
  19233.         set     7,(hl)
  19234.         jp      l6f95           ; Process line
  19235. l6dba:
  19236.         ld      a,(ix+0)
  19237.         call    l7271           ; Test label character
  19238.         call    l72c8
  19239.         db      _IllChar
  19240.         jr      l6d94
  19241. ;
  19242. ; Set label pointer
  19243. ;
  19244. l6dc6:
  19245.         ld      hl,(l7b75)      ; Get previous label pointer
  19246.         ld      de,(l7b73)      ; Get label pointer
  19247.         or      a
  19248.         sbc     hl,de
  19249.         ex      de,hl
  19250.         call    puttolabel_d_e          ; Put to table
  19251.         ld      hl,(l7b73)      ; Get label pointer
  19252.         ld      (l7b75),hl      ; Unpack into previous
  19253.         ret
  19254. l6ddb:
  19255.         ld      hl,(l7b7b)      ; Get current label pointer
  19256.         jr      l6de3
  19257. ;
  19258. ;
  19259. ;
  19260. l6de0:
  19261.         ld      hl,(l7b77)      ; Get top of available memory
  19262. l6de3:
  19263.         ld      (l7b7d),hl
  19264.         ld      a,(l7bc0)
  19265.         cp      c
  19266.         jr      z,l6e48
  19267.         ld      a,c
  19268.         ld      (l7bc0),a
  19269.         ld      hl,(l7b75)      ; Get previous label pointer
  19270. l6df3:
  19271.         ld      de,(l7b7d)
  19272.         xor     a
  19273.         sbc     hl,de
  19274.         add     hl,de
  19275.         jr      nz,l6e03
  19276.         xor     a
  19277.         ld      (l7bc1),a
  19278.         dec     a
  19279.         ret
  19280. l6e03:
  19281.         inc     hl
  19282.         ld      e,(hl)
  19283.         inc     hl
  19284.         ld      d,(hl)
  19285.         add     hl,de
  19286.         ld      a,(hl)
  19287.         or      a
  19288.         jr      z,l6df3
  19289.         dec     hl
  19290.         ld      a,(hl)
  19291.         inc     hl
  19292.         cp      c
  19293.         jr      nz,l6df3
  19294.         push    ix
  19295.         pop     de
  19296.         push    bc
  19297.         push    hl
  19298.         dec     hl
  19299.         dec     hl
  19300. l6e19:
  19301.         ld      b,(hl)
  19302.         ld      a,(de)
  19303.         dec     hl
  19304.         inc     de
  19305.         ld      c,b
  19306.         res     7,b
  19307.         cp      'a'
  19308.         jr      c,l6e2a
  19309.         cp      'z'+1
  19310.         jr      nc,l6e2a
  19311.         sub     'a'-'A'
  19312. l6e2a:
  19313.         cp      b
  19314.         jr      nz,l6e37
  19315.         bit     7,c
  19316.         jr      z,l6e19
  19317.         ld      a,(de)
  19318.         call    l7282           ; Test valid character
  19319.         jr      c,l6e3b         ; Nope
  19320. l6e37:
  19321.         pop     hl
  19322.         pop     bc
  19323.         jr      l6df3
  19324. l6e3b:
  19325.         ld      (l7bc2),hl
  19326.         ld      (l7bc4),de
  19327.         pop     hl
  19328.         pop     bc
  19329.         ld      a,(hl)
  19330.         ld      (l7bc1),a
  19331. l6e48:
  19332.         ld      hl,(l7bc2)
  19333.         ld      de,(l7bc4)
  19334.         ld      a,(l7bc1)
  19335.         cp      b
  19336.         ret
  19337. ;
  19338. ; Find label with type in reg B
  19339. ;
  19340. l6e54:
  19341.         call    l6de0
  19342.         ret     nz
  19343.         jr      l6e96
  19344. ;
  19345. ; Find constant string list ^PC
  19346. ; Z set says found
  19347. ;
  19348. l6e5a:
  19349.         ex      (sp),hl
  19350.         ld      c,(hl)          ; Get length of data following string
  19351.         inc     hl
  19352.         ld      e,(hl)          ; Get address of string
  19353.         inc     hl
  19354.         ld      d,(hl)
  19355.         inc     hl
  19356.         ex      (sp),hl
  19357.         ex      de,hl
  19358. l6e63:
  19359.         call    l6e7d           ; Find string
  19360.         ret     z               ; Got it
  19361.         dec     hl              ; Postion to previous character
  19362. l6e68:
  19363.         bit     _MB,(hl)        ; Find end of string
  19364.         inc     hl
  19365.         jr      z,l6e68
  19366.         ld      b,0
  19367.         add     hl,bc           ; Position to next string in list
  19368.         ld      a,(hl)
  19369.         or      a               ; Test more in list
  19370.         jr      nz,l6e63        ; Yeap
  19371.         dec     a               ; Set string not found
  19372.         ret
  19373. ;
  19374. ; Find constant string ^PC
  19375. ; Z set says found
  19376. ;
  19377. l6e76:
  19378.         ex      (sp),hl
  19379.         ld      e,(hl)          ; Get address of string
  19380.         inc     hl
  19381.         ld      d,(hl)
  19382.         inc     hl
  19383.         ex      (sp),hl
  19384.         ex      de,hl
  19385. ;
  19386. ; Find string ^HL
  19387. ;
  19388. l6e7d:
  19389.         push    ix              ; Copy source pointer
  19390.         pop     de
  19391.         ld      a,(hl)          ; Get character from searched string
  19392.         call    l7271           ; Test label character
  19393.         jr      c,l6e92         ; Nope
  19394.         call    l6e9c           ; Compare
  19395.         ret     nz              ; Not found
  19396.         ld      a,(de)          ; Get character from source
  19397.         call    l7282           ; Test valid character
  19398.         jr      c,l6e96         ; Nope
  19399.         or      a
  19400.         ret
  19401. l6e92:
  19402.         call    l6e9c           ; Compare
  19403.         ret     nz              ; Not found
  19404. l6e96:
  19405.         push    de              ; Set resulting source pointer
  19406.         pop     ix
  19407.         jp      l6f95           ; Process line
  19408. ;
  19409. ; Compare reference ^HL: source ^DE
  19410. ; Z set says match
  19411. ;
  19412. l6e9c:
  19413.         push    bc
  19414. l6e9d:
  19415.         ld      b,(hl)          ; Get from reference
  19416.         ld      a,(de)          ; Get from source
  19417.         inc     hl
  19418.         inc     de
  19419.         ld      c,b             ; Save reference
  19420.         res     _MB,b           ; Strip off MSB
  19421.         cp      'a'             ; Test range
  19422.         jr      c,l6eae
  19423.         cp      'z'+1
  19424.         jr      nc,l6eae
  19425.         sub     'a'-'A'         ; Convert to UPPER case
  19426. l6eae:
  19427.         cp      b               ; Compare
  19428.         jr      nz,l6eb6        ; No match
  19429.         bit     _MB,c           ; Test end of reference
  19430.         jr      z,l6e9d         ; Nope
  19431.         xor     a               ; Force match
  19432. l6eb6:
  19433.         pop     bc
  19434.         ret
  19435. l6eb8:
  19436.         ld      hl,l7513
  19437. l6ebb:
  19438.         ld      c,(hl)
  19439.         inc     c
  19440.         ret     z
  19441.         dec     c
  19442.         inc     hl
  19443.         ld      e,(hl)
  19444.         inc     hl
  19445.         ld      d,(hl)
  19446.         inc     hl
  19447.         push    hl
  19448.         ex      de,hl
  19449.         call    l6e63
  19450.         pop     hl
  19451.         jr      nz,l6ebb
  19452.         call    l72e1
  19453.         db      _ResWord
  19454. l6ed0:
  19455.         ld      a,(l7b91)       ; Get ???
  19456.         ld      c,a
  19457.         call    l6ddb
  19458.         ld      a,(l7bc1)
  19459.         or      a
  19460.         ret     z
  19461.         call    l72e1
  19462.         db      _DoubleLab
  19463. l6ee0:
  19464.         ld      a,'['
  19465.         call    l6f29
  19466.         ret     z
  19467.         ld      a,(ix+0)
  19468.         cp      '('
  19469.         ret     nz
  19470.         ld      a,(ix+1)
  19471.         cp      '.'
  19472.         ret     nz
  19473. l6ef2:
  19474.         inc     ix
  19475.         jp      l6f92           ; Process line
  19476. ;
  19477. ; Test ] - Z set says found
  19478. ;
  19479. l6ef7:
  19480.         ld      a,']'
  19481.         call    l6f29
  19482.         ret     z
  19483. ;;:::
  19484.         ld      a,(ix+0)
  19485.         cp      '.'
  19486.         ret     nz
  19487.         ld      a,(ix+1)
  19488.         cp      ')'
  19489.         ret     nz
  19490.         jr      l6ef2
  19491. ;
  19492. ; Test colon : - Z set says found
  19493. ;
  19494. l6f0b:
  19495.         ld      a,':'
  19496.         jr      l6f29
  19497. ;
  19498. ; Test semicolon ; - Z set says found
  19499. ;
  19500. l6f0f:
  19501.         ld      a,';'
  19502.         jr      l6f29
  19503. ;
  19504. ; Test comma , - Z set says found
  19505. ;
  19506. l6f13:
  19507.         ld      a,','
  19508.         jr      l6f29
  19509. l6f17:
  19510.         ld      a,'.'
  19511.         jr      l6f29
  19512. ;
  19513. ; Test left parenthesis ( - Z set says found
  19514. ;
  19515. l6f1b:
  19516.         ld      a,'('
  19517.         jr      l6f29
  19518. l6f1f:
  19519.         ld      a,')'
  19520.         jr      l6f29
  19521. ;
  19522. ; Test equate = - Z set says found
  19523. ;
  19524. l6f23:
  19525.         ld      a,'='
  19526.         jr      l6f29
  19527. l6f27:
  19528.         ld      a,'^'
  19529. l6f29:
  19530.         cp      (ix+0)
  19531.         ret     nz
  19532.         jp      l6f92           ; Process line
  19533. ;
  19534. ; Verify [
  19535. ;
  19536. l6f30:
  19537.         call    l6ee0
  19538.         ret     z
  19539.         call    l72e1
  19540.         db      _LftBrExp
  19541. ;
  19542. ; Verify ]
  19543. ;
  19544. l6f38:
  19545.         call    l6ef7           ; Test ]
  19546.         ret     z
  19547.         call    l72e1
  19548.         db      _RgtBrExp
  19549. ;
  19550. ; Verify :
  19551. ;
  19552. l6f40:
  19553.         call    l6f0b           ; Test :
  19554.         ret     z
  19555.         call    l72e1
  19556.         db      _SemiExp
  19557. ;
  19558. ; Verify ;
  19559. ;
  19560. l6f48:
  19561.         call    l6f0f           ; Test ;
  19562.         ret     z               ; Yeap
  19563. l6f4c:
  19564.         call    l72e1
  19565.         db      _ColExp
  19566. l6f50:
  19567.         call    l6f0f           ; Test ;
  19568.         ret     z               ; Yeap
  19569.         ld      a,(l7b98)
  19570.         or      a
  19571.         jr      z,l6f4c
  19572.         call    l72e1
  19573.         db      _Undef
  19574. ;
  19575. ; Verify ,
  19576. ;
  19577. l6f5e:
  19578.         call    l6f13           ; Test ,
  19579.         ret     z               ; Yeap
  19580.         call    l72e1
  19581.         db      _CommaExp
  19582. ;
  19583. ; Verify (
  19584. ;
  19585. l6f66:
  19586.         call    l6f1b           ; Test (
  19587.         ret     z               ; Yeap
  19588.         call    l72e1
  19589.         db      _LftPar
  19590. ;
  19591. ; Verify )
  19592. ;
  19593. l6f6e:
  19594.         call    l6f1f
  19595.         ret     z
  19596.         call    l72e1
  19597.         db      _RgtPar
  19598. ;
  19599. ; Verify =
  19600. ;
  19601. l6f76:
  19602.         call    l6f23           ; Find =
  19603.         ret     z
  19604.         call    l72e1
  19605.         db      _EquExp
  19606. l6f7e:
  19607.         call    l6e76           ; Find :=
  19608.         dw      l7582
  19609.         ret     z               ; Yeap
  19610.         call    l72e1
  19611.         db      _AssigExp
  19612. l6f88:
  19613.         call    l6e76           ; Find OF
  19614.         dw      l7560
  19615.         ret     z               ; Yeap
  19616.         call    l72e1
  19617.         db      _NoOF
  19618. ;
  19619. ; Process source line
  19620. ;
  19621. l6f92:
  19622.         call    l7124           ; Get character from file
  19623. l6f95:
  19624.         xor     a
  19625.         ld      (l7b98),a
  19626.         dec     a
  19627.         ld      (l7bc0),a
  19628.         ld      a,(ix+0)        ; Get a character
  19629.         or      a               ; Test empty
  19630.         jr      z,l6f92         ; Yeap, so get next
  19631.         cp      ' '             ; Skip blanks
  19632.         jr      z,l6f92
  19633.         cp      tab             ; Skip tabs
  19634.         jr      z,l6f92
  19635.         cp      '('             ; Test possible comment
  19636.         jr      z,l6fb5
  19637.         cp      '{'             ; Test real comment
  19638.         jr      z,l6fbf
  19639. l6fb3:
  19640.         xor     a
  19641.         ret
  19642. l6fb5:
  19643.         ld      a,(ix+1)        ; Get next
  19644.         cp      '*'             ; Test comment
  19645.         jr      nz,l6fb3        ; Nope
  19646.         call    l7124           ; Get next character
  19647. l6fbf:
  19648.         push    bc
  19649.         ld      b,(ix+0)        ; Get comment indicator
  19650.         ld      a,(ix+1)        ; Get next character
  19651.         cp      '$'             ; Test compiler directive
  19652.         jr      z,l6feb         ; Maybe
  19653. l6fca:
  19654.         call    l7124           ; Get next character
  19655. l6fcd:
  19656.         ld      a,b
  19657.         cp      '*'             ; Test two character indicators
  19658.         ld      a,(ix+0)
  19659.         jr      nz,l6fe4        ; Nope
  19660.         cp      b
  19661.         jr      nz,l6fca
  19662.         ld      a,(ix+1)
  19663.         cp      ')'
  19664.         jr      nz,l6fca
  19665.         call    l7124           ; Get character from file
  19666.         jr      l6fe8
  19667. l6fe4:
  19668.         cp      '}'             ; Test end of comment
  19669.         jr      nz,l6fca        ; Nope, wait for
  19670. l6fe8:
  19671.         pop     bc
  19672.         jr      l6f92
  19673. l6feb:
  19674.         push    bc
  19675.         push    de
  19676.         push    hl
  19677.         call    l7124           ; Get character from file
  19678. l6ff1:
  19679.         call    l7124           ; Get character from file
  19680.         ld      a,(ix+0)
  19681.         call    l04a6           ; Convert to upper case
  19682.         cp      'I'             ; Test include or I/O error
  19683.         ld      b,00000001b
  19684.         jr      z,l704d
  19685.         cp      'R'             ; Test index range test
  19686.         ld      b,00000010b
  19687.         jr      z,l704d
  19688.         cp      'A'             ; Test absolute code
  19689.         ld      b,00000100b
  19690.         jr      z,l704d
  19691.         cp      'U'             ; Test user break
  19692.         ld      b,00001000b
  19693.         jr      z,l704d
  19694.         cp      'X'             ; Test arry optimization
  19695.         ld      b,00010000b
  19696.         jr      z,l704d
  19697.         cp      'V'             ; Test var type test
  19698.         ld      b,00100000b
  19699.         jr      z,l704d
  19700.         cp      'B'             ; Test I/O mode
  19701.         ld      b,01000000b
  19702.         jr      z,l704d
  19703.         cp      'C'             ; Test keyboard interrupt
  19704.         ld      b,10000000b
  19705.         jr      z,l704d
  19706.         cp      'W'             ; Test WITH check
  19707.         jr      z,l707a
  19708. ;
  19709. ; Next directives used by MS-DOS only.
  19710. ; They will be checked for compatibility only
  19711. ;
  19712.         ld      b,00000000b
  19713.         cp      'K'             ; Test stack check ([$K+, $K-])
  19714.         jr      z,l704d
  19715.         cp      'D'             ; Test device check ([$D+, $D-])
  19716.         jr      z,l704d
  19717.         cp      'F'             ; Test number of open files ([$Fnum])
  19718.         jr      z,l708e
  19719.         cp      'G'             ; Test input buffer ([$Gnum])
  19720.         jr      z,l708e
  19721.         cp      'P'             ; Test output buffer ([$Pnum])
  19722.         jr      z,l708e
  19723.         call    l72e1           ; Invalid directive
  19724.         db      _CompDirec
  19725. l7048:
  19726.         pop     hl
  19727.         pop     de
  19728.         pop     bc
  19729.         jr      l6fcd
  19730. ;
  19731. ; Set or reset directive $x+ or $x-
  19732. ;
  19733. ; Bit to be attached held in reg B
  19734. ;
  19735. l704d:
  19736.         call    l7124           ; Get character from file
  19737.         ld      a,(ix+0)
  19738.         ld      c,0             ; Init for set
  19739.         cp      '+'             ; Test it
  19740.         jr      z,l7065         ; Yeap
  19741.         dec     c               ; Prepare for reset - all bits set
  19742.         cp      '-'
  19743.         jr      z,l7065
  19744.         dec     b               ; Remember $I is 00000001b - used multiple
  19745.         call    l72da           ; Else error
  19746.         db      _CompDirec
  19747.         jr      l709b           ; Now process include
  19748. l7065:
  19749.         ld      hl,l7b9d        ; Point to options
  19750.         ld      a,(hl)          ; Get current bits
  19751.         xor     c               ; Toggle bits or let in tact
  19752.         or      b               ; Insert bit
  19753.         xor     c               ; Set result
  19754.         ld      (hl),a
  19755. l706d:
  19756.         call    l7124           ; Get character from file
  19757. l7070:
  19758.         ld      a,(ix+0)
  19759.         cp      ','             ; Test more
  19760.         jp      z,l6ff1         ; Yeap
  19761.         jr      l7048
  19762. l707a:
  19763.         call    l7124           ; Get character from file
  19764.         ld      a,(ix+0)
  19765.         call    l7286           ; Test digit
  19766.         call    l72c8
  19767.         db      _CompDirec
  19768.         sub     '0'
  19769.         ld      (l7bc7),a       ; Change depth for WITH
  19770.         jr      l706d
  19771. ;
  19772. ; Process MS-DOS compatible directives
  19773. ;
  19774. l708e:
  19775.         call    l7124           ; Get character from file
  19776.         ld      a,(ix+0)
  19777.         call    l7286           ; Test digit
  19778.         jr      nc,l708e        ; Yeap, skip over
  19779.         jr      l7070
  19780. l709b:
  19781.         cp      ' '
  19782.         jr      nz,l70a7        ; Skip over directive
  19783.         call    l7124           ; Get character from file
  19784.         ld      a,(ix+0)
  19785.         jr      l709b
  19786. l70a7:
  19787.         ld      a,(l790e)       ; Get memory read flag
  19788.         or      a
  19789.         call    l72da           ; Should be memory read
  19790.         db      _INCLerr
  19791.         push    ix
  19792.         pop     de
  19793.         call    l2d2a           ; Prepare .PAS file
  19794.         push    de
  19795.         pop     ix
  19796.         ld      de,l005c
  19797.         push    de
  19798.         ld      c,_open
  19799.         call    l7265           ; Open file
  19800.         pop     hl
  19801.         inc     a
  19802.         call    l72d4
  19803.         db      _NoFileErr
  19804.         ld      de,l790f
  19805.         ld      bc,FCBlen
  19806.         ldir                    ; Unpack file
  19807.         ld      a,(l7900)       ; Get compile flag
  19808.         dec     a               ; Test compiling to file
  19809.         jr      z,l70e2         ; Yeap
  19810.         ld      hl,l7957
  19811.         ld      (l7be4),hl      ; Save top of .COM file
  19812.         ld      hl,l79d7        ; Get start of source line
  19813.         ld      a,1
  19814.         jr      l7103
  19815. l70e2:
  19816.         ld      hl,(l7b73)      ; Get label pointer
  19817.         ld      de,(l7be1)      ; Get top of .COM file
  19818.         ld      (l7be4),de      ; Save it
  19819.         or      a
  19820.         sbc     hl,de           ; Calculate difference
  19821.         srl     h
  19822.         rr      l
  19823.         ld      a,h
  19824.         or      a
  19825.         call    l72d4           ; If hi zero, no memory
  19826.         db      _CompOvfl
  19827.         ld      a,l
  19828.         and     RecLng
  19829.         ld      l,a
  19830.         push    hl
  19831.         add     hl,hl
  19832.         ld      a,h
  19833.         pop     hl
  19834.         add     hl,de
  19835. l7103:
  19836.         ld      (l7be6),hl
  19837.         ld      (l7be9),hl
  19838.         ld      (l7be8),a
  19839.         ld      (l790e),a       ; Re/Set memory read flag
  19840.         ld      hl,l0000
  19841.         ld      (l7beb),hl
  19842.         ld      a,(l7b9d)       ; Get options
  19843.         ld      (l7b9f),a
  19844.         ld      a,(l7bc7)       ; Get depth for WITH
  19845.         ld      (l7bc8),a
  19846.         jp      l7048
  19847. ;
  19848. ; Get character from file
  19849. ;
  19850. l7124:
  19851.         ld      a,(ix+0)
  19852.         inc     ix
  19853.         or      a
  19854.         ret     nz
  19855.         push    bc
  19856.         push    de
  19857.         push    hl
  19858.         ld      a,(l7ba2)       ; Get end of file
  19859.         or      a
  19860.         call    l72da
  19861.         db      _IllSrcEnd
  19862.         ld      hl,(l7bd7)      ; Get source pointer
  19863.         ld      (l7bd9),hl      ; Unpack it
  19864.         ld      hl,(l7beb)
  19865.         ld      (l7bed),hl
  19866.         ld      hl,l79d7        ; Get start of source line
  19867.         push    hl
  19868.         pop     ix              ; Copy it
  19869.         ld      b,RecLng-1      ; Set max length
  19870. l714a:
  19871.         push    hl
  19872.         push    bc
  19873.         call    l71f3
  19874.          push af
  19875.          push ix
  19876.          push iy
  19877.          PRCHAR
  19878.          pop iy
  19879.          pop ix
  19880.          pop af
  19881.         pop     bc
  19882.         pop     hl
  19883.         cp      cr
  19884.         jr      z,l7175
  19885.         cp      eof
  19886.          ;jr z,$ ;never
  19887.         jr      z,l716a
  19888.         cp      tab
  19889.         jr      z,l7161
  19890.         cp      ' '
  19891.         jr      c,l714a
  19892. l7161:
  19893.         djnz    l7166
  19894.         inc     b
  19895.         jr      l714a
  19896. l7166:
  19897.         ld      (hl),a
  19898.         inc     hl
  19899.         jr      l714a
  19900. l716a:
  19901.         ld      (l7ba2),a       ; Set end of file
  19902.         call    l717e
  19903.         call    l718f           ; Test abort
  19904.         jr      l7178
  19905. l7175:
  19906.         call    l717e ;compile_newline
  19907. l7178:
  19908.         ld      (hl),0
  19909.         pop     hl
  19910.         pop     de
  19911.         pop     bc
  19912.         ret
  19913. l717e: ;compile_newline
  19914.         push    af
  19915.         push    hl
  19916.         ld      hl,(l7bef)
  19917.         inc     hl              ; Advance line count
  19918.         ld      (l7bef),hl
  19919.         ld      a,l
  19920.         and     0fh
  19921.         ;jr     z,l7191
  19922.         pop     hl
  19923.         pop     af
  19924.         ret
  19925. ;
  19926. ; Test abortion of compilation
  19927. ;
  19928. l718f:
  19929.         push    af
  19930.         push    hl
  19931. l7191:
  19932.         push    bc
  19933.         push    de
  19934.         push    ix
  19935.         push    iy
  19936.         ld      a,cr
  19937.         call    puttoconsole_a          ; Put to console
  19938.         ld      a,(l790e)       ; Test memory read
  19939.         or      a
  19940.         jr      z,l71a6         ; Yeap
  19941.         ld      a,'I'
  19942.         jr      l71a8
  19943. l71a6:
  19944.         ld      a,' '
  19945. l71a8:
  19946.         call    puttoconsole_a          ; Put to console
  19947.         ld      a,' '
  19948.         call    puttoconsole_a          ; Put to console
  19949.         ld      hl,(l7bef)      ; Get line count
  19950.         call    l2e61           ; Print number
  19951.         call    l00a0           ; Test key pressed
  19952.         or      a
  19953.         jr      z,l71ea
  19954.         call    l0200
  19955.         db      '   *** Abort compilation'
  19956.         db      null
  19957.         call    l2d01           ; Ask for YES or NO
  19958.         call    l72da
  19959.         db      _ABORT
  19960.         ld      b,32
  19961. l71e1:
  19962.         call    l0200
  19963.         db      bs,' ',bs
  19964.         db      null
  19965.         djnz    l71e1
  19966. l71ea:
  19967.         pop     iy
  19968.         pop     ix
  19969.         pop     de
  19970.         pop     bc
  19971.         pop     hl
  19972.         pop     af
  19973.         ret
  19974. ;
  19975. ; Read character from file
  19976. ;
  19977. l71f3:
  19978.         ld      a,(l790e)       ; Test memory read
  19979.         or      a
  19980.         jr      nz,l7205        ; Nope
  19981. l71f9:
  19982.         ld      hl,(l7bd7)      ; Get source pointer
  19983.         ld      a,(hl)
  19984.         cp      eof             ; Test end of file
  19985.         ret     z               ; Yeap
  19986.         inc     hl
  19987.         ld      (l7bd7),hl
  19988.         ret
  19989. l7205:
  19990.         ld      hl,(l7be9)
  19991.         ld      de,(l7be6)
  19992.         or      a
  19993.         sbc     hl,de
  19994.         add     hl,de
  19995.         jr      c,l7242
  19996.         ld      de,(l7be4)      ; Get top of .COM file
  19997.         ld      a,(l7be8)
  19998.         ld      b,a
  19999. l721a:
  20000.         push    bc
  20001.         push    de
  20002.         ld      c,_setdma
  20003.         call    l7265           ; Set disk buffer
  20004.         ld      de,l790f
  20005.         ld      c,_rdseq
  20006.         call    l7265           ; Read record
  20007.         pop     de
  20008.         pop     bc
  20009.         ;or     a
  20010.         ;jr     nz,l7237
  20011.          xor 128 ;EOF in NedoOS
  20012.          jr z,l7237
  20013.         ;ld     hl,RecLng
  20014.          ld l,a
  20015.          ld h,0
  20016. ;CP/M has eofs in the end of last sector?
  20017. ;do this by hand:
  20018.         xor 128
  20019.         jr z,readchar_load_noaddzeros ;full sector
  20020. ;a=128+bytes loaded
  20021.         neg
  20022. ;a=128-bytes loaded
  20023.         push bc
  20024.         push de
  20025.         ld b,a
  20026.         ld a,e
  20027.         add a,127
  20028.         ld e,a
  20029.         adc a,d
  20030.         sub e
  20031.         ld d,a
  20032.         ;de= Point to buffer end
  20033.         ld a,eof;-1
  20034.         ld (de),a
  20035.         dec de
  20036.         djnz $-2
  20037.         pop de
  20038.         pop bc
  20039. readchar_load_noaddzeros
  20040.         add     hl,de           ; Advance buffer
  20041.         ex      de,hl
  20042.         djnz    l721a
  20043.         jr      l723f
  20044. l7237:
  20045.         ld      a,eof           ; Set end of file
  20046.         ld      (de),a
  20047.         inc     de
  20048.         ld      (l7be6),de
  20049. l723f:
  20050.         ld      hl,(l7be4)      ; Get top of .COM file
  20051. l7242:
  20052.         ld      a,(hl)
  20053.         inc     hl
  20054.         ld      (l7be9),hl
  20055.         cp      eof
  20056.         jr      nz,l725d
  20057.         xor     a
  20058.         ld      (l790e),a       ; Enable memory read
  20059.         ld      a,(l7b9f)
  20060.         ld      (l7b9d),a       ; Reset options
  20061.         ld      a,(l7bc8)
  20062.         ld      (l7bc7),a       ; Set depth for WITH
  20063.         jr      l71f9
  20064. l725d:
  20065.         ld      hl,(l7beb)
  20066.         inc     hl
  20067.         ld      (l7beb),hl
  20068.         ret
  20069. ;
  20070. ; Perform OS call
  20071. ;
  20072. l7265:
  20073.         push    ix              ; Preserve index registers
  20074.         push    iy
  20075.         call    BDOS            ; Call system
  20076.         pop     iy
  20077.         pop     ix
  20078.         ret
  20079. ;
  20080. ; Test label character
  20081. ; C set says no
  20082. ;
  20083. l7271:
  20084.         cp      'A'
  20085.         ret     c
  20086.         cp      'Z'+1
  20087.         ccf
  20088.         ret     nc
  20089.         cp      '_'
  20090.         ret     z
  20091.         cp      'a'
  20092.         ret     c
  20093.         cp      'z'+1
  20094.         ccf
  20095.         ret
  20096. ;
  20097. ; Test valid character
  20098. ; C set says no
  20099. ;
  20100. l7282:
  20101.         call    l7271           ; Test label character
  20102.         ret     nc              ; Yeap
  20103. ;
  20104. ; Test character a digit
  20105. ; C set says no
  20106. ;
  20107. l7286:
  20108.         cp      '0'             ; Test digit
  20109.         ret     c
  20110.         cp      '9'+1
  20111.         ccf
  20112.         ret
  20113. ;
  20114. ; Compare signed integers HL:DE
  20115. ;
  20116. ; C set if HL<DE
  20117. ; Z set if HL=DE
  20118. ;
  20119. l728d:
  20120.         ld      a,h
  20121.         xor     d
  20122.         ld      a,h
  20123.         jp      m,l7298
  20124.         cp      d
  20125.         ret     nz
  20126.         ld      a,l
  20127.         cp      e
  20128.         ret
  20129. l7298:
  20130.         rla
  20131.         ret
  20132. ;
  20133. ; HL:=HL*DE - C set on overflow
  20134. ;
  20135. l729a:
  20136.         ld      b,h
  20137.         ld      c,l
  20138.         ld      hl,0            ; Init product
  20139.         ld      a,16
  20140. l72a1:
  20141.         add     hl,hl
  20142.         ret     c
  20143.         ex      de,hl
  20144.         add     hl,hl
  20145.         ex      de,hl
  20146.         jr      nc,l72aa
  20147.         add     hl,bc
  20148.         ret     c
  20149. l72aa:
  20150.         dec     a
  20151.         jr      nz,l72a1
  20152.         ret
  20153. ;
  20154. ; HL:=HL DIV DE                         *** NOT USED HERE
  20155. ; HL:=HL MOD DE
  20156. ;
  20157.         ld      b,d
  20158.         ld      c,e
  20159.         ex      de,hl
  20160.         xor     a
  20161.         ld      h,a
  20162.         ld      l,a
  20163.         ld      a,17
  20164. l72b6:
  20165.         adc     hl,hl
  20166.         sbc     hl,bc
  20167.         jr      nc,l72be
  20168.         add     hl,bc
  20169.         scf
  20170. l72be:
  20171.         ccf
  20172.         rl      e
  20173.         rl      d
  20174.         dec     a
  20175.         jr      nz,l72b6
  20176.         ex      de,hl
  20177.         ret
  20178. ;
  20179. ; Process error if entry C
  20180. ;
  20181. l72c8:
  20182.         ex      (sp),hl
  20183.         inc     hl              ; Fix caller's address
  20184.         ex      (sp),hl
  20185.         ret     nc              ; No error
  20186.         jr      l72de
  20187. l72ce:: ;;**
  20188.         ex      (sp),hl
  20189.         inc     hl              ; Fix caller's address
  20190.         ex      (sp),hl
  20191.         ret     c               ; No error
  20192.         jr      l72de
  20193. ;
  20194. ; Process error if entry Z
  20195. ;
  20196. l72d4:
  20197.         ex      (sp),hl
  20198.         inc     hl              ; Fix caller's address
  20199.         ex      (sp),hl
  20200.         ret     nz              ; No error
  20201.         jr      l72de
  20202. ;
  20203. ; Process error if entry NZ
  20204. ;
  20205. l72da:
  20206.         ex      (sp),hl
  20207.         inc     hl              ; Fix caller's address
  20208.         ex      (sp),hl
  20209.         ret     z               ; No error
  20210. ;
  20211. ; Common entry of error routine
  20212. ;
  20213. l72de:
  20214.         pop     hl              ; Get back caller
  20215.         dec     hl              ; Fix pointer
  20216.         push    hl
  20217. ;
  20218. ; Process error
  20219. ;
  20220. l72e1:
  20221.         pop     hl              ; Get pointer
  20222.         ld      a,(hl)          ; Fetch error number
  20223. l72e3:
  20224.         call    l718f           ; Test abort
  20225.         ld      (l7901),a
  20226.         or      a
  20227.         jr      z,l730c
  20228.         push    ix
  20229.         pop     hl
  20230.         ld      de,l79d7        ; Get start of source line
  20231.         sbc     hl,de
  20232.         ld      de,(l7bed)
  20233.         ld      a,(l790e)       ; Test memory read
  20234.         or      a
  20235.         jr      nz,l7308        ; Nope
  20236.         ld      de,(l4544)      ; Get start of text
  20237.         sbc     hl,de
  20238.         ld      de,(l7bd9)      ; Get back source pointer
  20239. l7308:
  20240.         add     hl,de
  20241.         ld      (l790c),hl      ; Save current editor address
  20242. l730c:
  20243.         ld      a,(l7900)       ; Get compile flag
  20244.         dec     a               ; Test compiling to file
  20245.         jr      nz,l731a        ; Nope
  20246.         ld      de,l7933
  20247.         ld      c,_close
  20248.         call    l7265           ; Close file
  20249. l731a:
  20250.         ld      sp,(l7b71)      ; Get back stack
  20251.         ret                     ; Exit compiler
  20252. ;
  20253. ; Compiler tables
  20254. ; Internal label table
  20255. ;
  20256. ; -->> INTEGER
  20257. ;
  20258. l731f:
  20259.         dw      _.INT
  20260. ssINT:
  20261.         dw      l74d3+7
  20262.         db      'R'+MSB,'EGETNI'
  20263.         db      0,_Type
  20264. _.INT   equ     $-ssINT
  20265. ;
  20266. ; -->> CHAR
  20267. ;
  20268.         dw      _.CHAR
  20269. ssCHAR:
  20270.         dw      l74db+7
  20271.         db      'R'+MSB,'AHC'
  20272.         db      0,_Type
  20273. _.CHAR  equ     $-ssCHAR
  20274. ;
  20275. ; -->> REAL
  20276. ;
  20277.         dw      _.REAL
  20278. ssREAL:
  20279.         dw      l74e3+7
  20280.         db      'L'+MSB,'AER'
  20281.         db      0,_Type
  20282. _.REAL  equ     $-ssREAL
  20283. ;
  20284. ; -->> BOOLEAN
  20285. ;
  20286.         dw      _.BOOL
  20287. ssBOOL:
  20288.         dw      l74eb+7
  20289.         db      'N'+MSB,'AELOOB'
  20290.         db      0,_Type
  20291. _.BOOL  equ     $-ssBOOL
  20292. ;
  20293. ; -->> TEXT
  20294. ;
  20295.         dw      _.TEXT
  20296. ssTEXT:
  20297.         dw      l74f3+7 ;text file type???
  20298.         db      'T'+MSB,'XET'
  20299.         db      0,_Type
  20300. _.TEXT  equ     $-ssTEXT
  20301. ;
  20302. ; -->> BYTE
  20303. ;
  20304.         dw      _.BYTE
  20305. ssBYTE:
  20306.         dw      l74fb+7 ;byte type
  20307.         db      'E'+MSB,'TYB'
  20308.         db      0,_Type
  20309. _.BYTE  equ     $-ssBYTE
  20310. ;
  20311. ; -->> TRUE
  20312. ;
  20313.         dw      _.TRUE
  20314. ssTRUE:
  20315.         dw      _TRUE
  20316.         db      _Bool
  20317.         db      'E'+MSB,'URT'
  20318.         db      0,_Const
  20319. _.TRUE  equ     $-ssTRUE
  20320. ;
  20321. ; -->> FALSE
  20322. ;
  20323.         dw      _.FALSE
  20324. ssFALSE:
  20325.         dw      FALSE
  20326.         db      _Bool
  20327.         db      'E'+MSB,'SLAF'
  20328.         db      0,_Const
  20329. _.FALSE equ     $-ssFALSE
  20330. ;
  20331. ; -->> MAXINT
  20332. ;
  20333.         dw      _.MXINT
  20334. ssMAXINT:
  20335.         dw      MAXINT
  20336.         db      _Integ
  20337.         db      'T'+MSB,'NIXAM'
  20338.         db      0,_Const
  20339. _.MXINT equ     $-ssMAXINT
  20340. ;
  20341. ; -->> PI
  20342. ;
  20343.         dw      _.PI
  20344. ssPI:
  20345.         db      082h,021h,0a2h,0dah,00fh,049h
  20346.         db      _Real
  20347.         db      'I'+MSB,'P'
  20348.         db      0,_Const
  20349. _.PI    equ     $-ssPI
  20350. ;
  20351. ; -->> OUTPUT
  20352. ;
  20353.         dw      _.OUTP
  20354. ssOUTP:
  20355.         dw      l74f3+7 ;text file type???
  20356.         dw      l00c2
  20357.         db      0
  20358.         db      'T'+MSB,'UPTUO'
  20359.         db      0,4
  20360. _.OUTP  equ     $-ssOUTP
  20361. ;
  20362. ; -->> INPUT
  20363. ;
  20364.         dw      _.INPT
  20365. ssINPT:
  20366.         dw      l74f3+7 ;text file type???
  20367.         dw      l00c2
  20368.         db      0
  20369.         db      'T'+MSB,'UPNI'
  20370.         db      0,_Ptr
  20371. _.INPT  equ     $-ssINPT
  20372. ;
  20373. ; -->> CON
  20374. ;
  20375.         dw      _.CON
  20376. ssCON:
  20377.         dw      l74f3+7 ;text file type???
  20378.         dw      l00b8
  20379.         db      0
  20380.         db      'N'+MSB,'OC'
  20381.         db      0,_Ptr
  20382. _.CON   equ     $-ssCON
  20383. ;
  20384. ; -->> TRM
  20385. ;
  20386.         dw      _.TRM
  20387. ssTRM:
  20388.         dw      l74f3+7 ;text file type???
  20389.         dw      l00b8
  20390.         db      0
  20391.         db      'M'+MSB,'RT'
  20392.         db      0,_Ptr
  20393. _.TRM   equ     $-ssTRM
  20394. ;
  20395. ; -->> KBD
  20396. ;
  20397.         dw      _.KBD
  20398. ssKBD:
  20399.         dw      l74f3+7 ;text file type???
  20400.         dw      l00ba
  20401.         db      0
  20402.         db      'D'+MSB,'BK'
  20403.         db      0,_Ptr
  20404. _.KBD   equ     $-ssKBD
  20405. ;
  20406. ; -->> LST
  20407. ;
  20408.         dw      _.LST
  20409. ssLST:
  20410.         dw      l74f3+7 ;text file type???
  20411.         dw      l00bc
  20412.         db      0
  20413.         db      'T'+MSB,'SL'
  20414.         db      0,_Ptr
  20415. _.LST   equ     $-ssLST
  20416. ;
  20417. ; -->> AUX
  20418. ;
  20419.         dw      _.AUX
  20420. ssAUX:
  20421.         dw      l74f3+7 ;text file type???
  20422.         dw      l00be
  20423.         db      0
  20424.         db      'X'+MSB,'UA'
  20425.         db      0,_Ptr
  20426. _.AUX   equ     $-ssAUX
  20427. ;
  20428. ; -->> USR
  20429. ;
  20430.         dw      _.USR
  20431. ssUSR:
  20432.         dw      l74f3+7 ;text file type???
  20433.         dw      l00c0
  20434.         db      0
  20435.         db      'R'+MSB,'SU'
  20436.         db      0,_Ptr
  20437. _.USR   equ     $-ssUSR
  20438. ;
  20439. ; -->> BUFLEN
  20440. ;
  20441.         dw      _.BUFL
  20442. ssBUFL:
  20443.         dw      l74fb+7 ;byte type
  20444.         dw      l00d1
  20445.         db      0
  20446.         db      'N'+MSB,'ELFUB'
  20447.         db      0,_Ptr
  20448. _.BUFL  equ     $-ssBUFL
  20449. ;
  20450. ; -->> HEAPPTR
  20451. ;
  20452.         dw      _.HEAP
  20453. ssHEAP:
  20454.         dw      l74d3+7 ;integer type
  20455.         dw      l00c4
  20456.         db      0
  20457.         db      'R'+MSB,'TPPAEH'
  20458.         db      0,_Ptr
  20459. _.HEAP  equ     $-ssHEAP
  20460. ;
  20461. ; -->> RECURPTR
  20462. ;
  20463.         dw      _.RECUR
  20464. ssRECUR:
  20465.         dw      l74d3+7 ;integer type
  20466.         dw      l00c6
  20467.         db      0
  20468.         db      'R'+MSB,'TPRUCER'
  20469.         db      0,_Ptr
  20470. _.RECUR equ     $-ssRECUR
  20471. ;
  20472. ; -->> CONSTPTR
  20473. ;
  20474.         dw      _.CONSP
  20475. ssCONSP:
  20476.         dw      l74d3+7 ;integer type
  20477.         dw      l00a0+1
  20478.         db      0
  20479.         db      'R'+MSB,'TPTSNOC'
  20480.         db      0,_Ptr
  20481. _.CONSP equ     $-ssCONSP
  20482. ;
  20483. ; -->> CONINPTR
  20484. ;
  20485.         dw      _.CONIP
  20486. ssCONIP:
  20487.         dw      l74d3+7 ;integer type
  20488.         dw      l00a3+1
  20489.         db      0
  20490.         db      'R'+MSB,'TPNINOC'
  20491.         db      0,_Ptr
  20492. _.CONIP equ     $-ssCONIP
  20493. ;
  20494. ; -->> CONOUTPTR
  20495. ;
  20496.         dw      _.CONOP
  20497. ssCONOP:
  20498.         dw      l74d3+7 ;integer type
  20499.         dw      l00a6+1
  20500.         db      0
  20501.         db      'R'+MSB,'TPTUONOC'
  20502.         db      0,_Ptr
  20503. _.CONOP equ     $-ssCONOP
  20504. ;
  20505. ; -->> LSTOUTPTR
  20506. ;
  20507.         dw      _.LSTOP
  20508. ssLSTOP:
  20509.         dw      l74d3+7 ;integer type
  20510.         dw      l00a9+1
  20511.         db      0
  20512.         db      'R'+MSB,'TPTUOTSL'
  20513.         db      0,_Ptr
  20514. _.LSTOP equ     $-ssLSTOP
  20515. ;
  20516. ; -->> AUXINPTR
  20517. ;
  20518.         dw      _.AUXIP
  20519. ssAUXIP:
  20520.         dw      l74d3+7 ;integer type
  20521.         dw      l00af+1
  20522.         db      0
  20523.         db      'R'+MSB,'TPNIXUA'
  20524.         db      0,_Ptr
  20525. _.AUXIP equ     $-ssAUXIP
  20526. ;
  20527. ; -->> AUXOUTPTR
  20528. ;
  20529.         dw      _.AUXOP
  20530. ssAUXOP:
  20531.         dw      l74d3+7 ;integer type
  20532.         dw      l00ac+1
  20533.         db      0
  20534.         db      'R'+MSB,'TPTUOXUA'
  20535.         db      0,_Ptr
  20536. _.AUXOP equ     $-ssAUXOP
  20537. ;
  20538. ; -->> USRINPTR
  20539. ;
  20540.         dw      _.USRIP
  20541. ssUSRIP:
  20542.         dw      l74d3+7 ;integer type
  20543.         dw      l00b5+1
  20544.         db      0
  20545.         db      'R'+MSB,'TPNIRSU'
  20546.         db      0,_Ptr
  20547. _.USRIP equ     $-ssUSRIP
  20548. ;
  20549. ; -->> USROUTPTR
  20550. ;
  20551.         dw      _.USROP
  20552. ssUSROP:
  20553.         dw      l74d3+7 ;integer type
  20554.         dw      l00b2+1
  20555.         db      0
  20556.         db      'R'+MSB,'TPTUORSU'
  20557.         db      0,_Ptr
  20558. _.USROP equ     $-ssUSROP
  20559. ;
  20560. ; -->> ERRORPTR
  20561. ;
  20562.         dw      _.ERRPT
  20563. ssERRPT:
  20564.         dw      l74d3+7 ;integer type
  20565.         dw      l00da
  20566.         db      0
  20567.         db      'R'+MSB,'TPRORRE'
  20568.         db      0,_Ptr
  20569. _.ERRPT equ     $-ssERRPT
  20570. ;
  20571. ; -->> CBREAK
  20572. ;
  20573.         dw      _.CBRK
  20574. ssCBRK:
  20575.         dw      l74eb+7
  20576.         dw      l00dd
  20577.         db      0
  20578.         db      'K'+MSB,'AERBC'
  20579.         db      0,_Ptr
  20580. _.CBRK  equ     $-ssCBRK
  20581. IntLabTab:
  20582. LenLab  equ     IntLabTab-l731f
  20583. ;
  20584. ; Standard type length table
  20585. ; Note HI-LO entries of definition words
  20586. ;
  20587.  
  20588. dww     macro   val
  20589.         db      HIGH val
  20590.         db      LOW  val
  20591.         endm
  20592.  
  20593. l74d3:
  20594.         dww     2               ; Length for this type
  20595.         dww     MAXINT          ; Max value
  20596.         dww     (-MAXINT-1)     ; Min value
  20597.         dww     _Integ          ; Type
  20598. l74db:
  20599.         dww     1
  20600.         dww     255
  20601.         dww     0
  20602.         dww     _Char
  20603. l74e3:
  20604.         dww     6
  20605.         dww     0
  20606.         dww     0
  20607.         dww     _Real
  20608. l74eb:
  20609.         dww     1
  20610.         dww     _TRUE
  20611.         dww     FALSE
  20612.         dww     _Bool
  20613. l74f3:
  20614.         dww     (FIBlen+RecLng)
  20615.         dww     0
  20616.         dww     0
  20617.         dww     _TxtF
  20618. l74fb:
  20619.         dww     1
  20620.         dww     255
  20621.         dww     0
  20622.         dww     _Integ
  20623. ;
  20624.         dww     (DefSTR+1)
  20625.         dww     0
  20626.         dww     0
  20627.         dww     _String
  20628. l750b:
  20629.         dww     0
  20630.         dww     0
  20631.         dww     0
  20632.         dww     0
  20633. ;
  20634. ; Table of reserved words
  20635. ;
  20636. l7513:
  20637.         db      0
  20638.         dw      l7529
  20639.         db      _Byte
  20640.         dw      l7584
  20641.         db      _Addr
  20642.         dw      l75bb
  20643.         db      _Byte
  20644.         dw      l75f5
  20645.         db      _Byte
  20646.         dw      l7604
  20647.         db      _Byte
  20648.         dw      l761d
  20649.         db      _Byte
  20650.         dw      l7634
  20651.         db      -1
  20652. ;
  20653. ; Keywords
  20654. ;
  20655. l7529:
  20656.         dc      'PROGRAM'
  20657. l7530:
  20658.         dc      'END'
  20659. l7533:
  20660.         dc      'FORWARD'
  20661. l753a:
  20662.         dc      'EXTERNAL'
  20663. l7542:
  20664.         dc      'PACKED'
  20665. l7548:
  20666.         dc      'ARRAY'
  20667. l754d:
  20668.         dc      'FILE'
  20669. l7551:
  20670.         dc      'SET'
  20671. l7554:
  20672.         dc      'RECORD'
  20673. l755a:
  20674.         dc      'STRING'
  20675. l7560:
  20676.         dc      'OF'
  20677. l7562:
  20678.         dc      'ABSOLUTE'
  20679. l756a:
  20680.         dc      'THEN'
  20681. l756e:
  20682.         dc      'ELSE'
  20683. l7572:
  20684.         dc      'DO'
  20685. l7574:
  20686.         dc      'UNTIL'
  20687. l7579:
  20688.         dc      'NOT'
  20689. l757c:
  20690.         dc      'NIL'
  20691.         db      0
  20692. l7580:
  20693.         dc      '..'
  20694. l7582:
  20695.         dc      ':='
  20696. ;
  20697. ; Main block table
  20698. ; -->> Code is type
  20699. ;
  20700. l7584:
  20701.         dc      'LABEL'
  20702.         db      1
  20703.         dc      'CONST'
  20704.         db      2
  20705.         dc      'TYPE'
  20706.         db      3
  20707. l7595:
  20708.         dc      'VAR'
  20709.         db      4
  20710.         dc      'BEGIN'
  20711.         db      8
  20712. l759f:
  20713.         dc      'OVERLAY'
  20714.         db      7
  20715. l75a7:
  20716.         dc      'PROCEDURE'
  20717.         db      5
  20718.         dc      'FUNCTION'
  20719.         db      6
  20720.         db      0
  20721. ;
  20722. ; Statement table
  20723. ;
  20724. l75bb:
  20725.         dc      'BEGIN'
  20726.         dw      l5377
  20727.         dc      'IF'
  20728.         dw      l53ef
  20729.         dc      'WHILE'
  20730.         dw      l5424
  20731.         dc      'REPEAT'
  20732.         dw      l544c
  20733.         dc      'FOR'
  20734.         dw      l546b
  20735. l75da:
  20736.         dc      'CASE'
  20737.         dw      l5521
  20738.         dc      'GOTO'
  20739.         dw      l5626
  20740.         dc      'WITH'
  20741.         dw      l564e
  20742.         dc      'INLINE'
  20743.         dw      l5698
  20744.         db      0
  20745. l75f5:
  20746.         dc      'TO'
  20747.         inc     hl
  20748.         dc      'DOWNTO'
  20749.         dec     hl
  20750.         db      0
  20751. l7600:
  20752.         db      '*'+0x80
  20753.         db      0
  20754.         db      '/'+0x80
  20755.         db      1
  20756. l7604:
  20757.         dc      'AND'
  20758.         db      2
  20759.         dc      'DIV'
  20760.         db      3
  20761.         dc      'MOD'
  20762.         db      4
  20763.         dc      'SHL'
  20764.         db      5
  20765.         dc      'SHR'
  20766.         db      6
  20767.         db      0
  20768. l7619:
  20769.         db      '+'+0x80
  20770.         db      0
  20771.         db      '-'+0x80
  20772.         db      1
  20773. l761d:
  20774.         dc      'OR'
  20775.         db      2
  20776.         dc      'XOR'
  20777.         db      3
  20778.         db      0
  20779. l7625:
  20780.         db      '='+0x80
  20781.         db      00000000b
  20782.         db      '<','>'+0x80
  20783.         db      00001000b
  20784.         db      '>','='+0x80
  20785.         db      00010000b
  20786.         db      '<','='+0x80
  20787.         db      00011000b
  20788.         db      '>'+0x80
  20789.         db      00100000b
  20790.         db      '<'+0x80
  20791.         db      00101000b
  20792. l7634:
  20793.         dc      'IN'
  20794.         db      11111111b
  20795.         db      0
  20796. l7638:
  20797.         dc      'WRITELN'
  20798.         dw      l5ae7
  20799.         dc      'WRITE'
  20800.         dw      l5ae8
  20801.         dc      'READLN'
  20802.         dw      l5a32
  20803.         dc      'READ'
  20804.         dw      l5a33
  20805.         dc      'DELETE'
  20806.         dw      l5c66
  20807.         dc      'INSERT'
  20808.         dw      l5c87
  20809.         dc      'ASSIGN'
  20810.         dw      l5943
  20811.         dc      'RESET'
  20812.         dw      l59b9
  20813.         dc      'REWRITE'
  20814.         dw      l59be
  20815.         dc      'CLOSE'
  20816.         dw      l59db
  20817.         dc      'ERASE'
  20818.         dw      l5971
  20819.         dc      'RENAME'
  20820.         dw      l5966
  20821.         dc      'SEEK'
  20822.         dw      l598c
  20823.         dc      'GETMEM'
  20824.         dw      l5d94
  20825.         dc      'NEW'
  20826.         dw      l5d9f
  20827.         dc      'FREEMEM'
  20828.         dw      l5db4
  20829.         dc      'DISPOSE'
  20830.         dw      l5dbf
  20831.         dc      'MARK'
  20832.         dw      l5dd4
  20833.         dc      'RELEASE'
  20834.         dw      l5dd9
  20835.         dc      'OVRDRIVE'
  20836.         dw      l5df9
  20837.         dc      'CRTINIT'
  20838.         dw      l5e38
  20839.         dc      'CRTEXIT'
  20840.         dw      l5e3d
  20841.         dc      'GOTOXY'
  20842.         dw      l5d6d
  20843.         dc      'CLRSCR'
  20844.         dw      l5e42
  20845.         dc      'CLREOL'
  20846.         dw      l5e48
  20847.         dc      'NORMVIDEO'
  20848.         dw      l5e4d
  20849.         dc      'HIGHVIDEO'
  20850.         dw      l5e4d
  20851.         dc      'LOWVIDEO'
  20852.         dw      l5e52
  20853.         dc      'INSLINE'
  20854.         dw      l5e57
  20855.         dc      'DELLINE'
  20856.         dw      l5e5c
  20857.         dc      'DELAY'
  20858.         dw      l5d89
  20859.         dc      'BLOCKREAD'
  20860.         dw      l5c16
  20861.         dc      'BLOCKWRITE'
  20862.         dw      l5c1e
  20863.         dc      'RANDOMIZE'
  20864.         dw      l5d83
  20865.         dc      'MOVE'
  20866.         dw      l5e05
  20867.         dc      'FILLCHAR'
  20868.         dw      l5e1a
  20869.         dc      'EXIT'
  20870.         dw      l5e61
  20871.         dc      'HALT'
  20872.         dw      l5e67
  20873.         dc      'PORT'
  20874.         dw      l5e6d
  20875.         dc      'STACKPTR'
  20876.         dw      l5e78
  20877.         dc      'FLUSH'
  20878.         dw      l59ab
  20879.         dc      'EXECUTE'
  20880.         dw      l597e
  20881.         dc      'CHAIN'
  20882.         dw      l5979
  20883.         dc      'STR'
  20884.         dw      l5cba
  20885.         dc      'VAL'
  20886.         dw      l5d22
  20887.         dc      'BDOS'
  20888.         dw      l6553
  20889.         dc      'BIOS'
  20890.         dw      l651e
  20891.         db      0
  20892. l77b1:
  20893.         dc      'CHR'
  20894.         dw      l6425
  20895.         dc      'ORD'
  20896.         dw      l6411
  20897.         dc      'COPY'
  20898.         dw      l6460
  20899.         dc      'LENGTH'
  20900.         dw      l6441
  20901.         dc      'POS'
  20902.         dw      l6452
  20903.         dc      'CONCAT'
  20904.         dw      l6481
  20905.         dc      'SUCC'
  20906.         dw      l63d4
  20907.         dc      'PRED'
  20908.         dw      l63d7
  20909.         dc      'UPCASE'
  20910.         dw      l6437
  20911.         dc      'TRUNC'
  20912.         dw      l63be
  20913.         dc      'ROUND'
  20914.         dw      l63c3
  20915.         dc      'ODD'
  20916.         dw      l6401
  20917.         dc      'ABS'
  20918.         dw      l6371
  20919.         dc      'SQR'
  20920.         dw      l6360
  20921.         dc      'SQRT'
  20922.         dw      l6385
  20923.         dc      'SIN'
  20924.         dw      l638a
  20925.         dc      'COS'
  20926.         dw      l638f
  20927.         dc      'ARCTAN'
  20928.         dw      l6394
  20929.         dc      'LN'
  20930.         dw      l6399
  20931.         dc      'EXP'
  20932.         dw      l639e
  20933.         dc      'INT'
  20934.         dw      l63a3
  20935.         dc      'FRAC'
  20936.         dw      l63a8
  20937.         dc      'RANDOM'
  20938.         dw      l64ac
  20939.         dc      'PARAMCOUNT'
  20940.         dw      l649c
  20941.         dc      'PARAMSTR'
  20942.         dw      l64a1
  20943.         dc      'LO'
  20944.         dw      l63e1
  20945.         dc      'HI'
  20946.         dw      l63eb
  20947.         dc      'SWAP'
  20948.         dw      l63f6
  20949.         dc      'PTR'
  20950.         dw      l642b
  20951.         dc      'IORESULT'
  20952.         dw      l64c4
  20953.         dc      'EOF'
  20954.         dw      l64c9
  20955.         dc      'EOLN'
  20956.         dw      l64df
  20957.         dc      'SEEKEOF'
  20958.         dw      l64d5
  20959.         dc      'SEEKEOLN'
  20960.         dw      l64da
  20961.         dc      'FILESIZE'
  20962.         dw      l64fa
  20963.         dc      'FILEPOS'
  20964.         dw      l64f2
  20965.         dc      'KEYPRESSED'
  20966.         dw      l640c
  20967.         dc      'MEMAVAIL'
  20968.         dw      l6514
  20969.         dc      'MAXAVAIL'
  20970.         dw      l6519
  20971.         dc      'PORT'
  20972.         dw      l65bf
  20973.         dc      'STACKPTR'
  20974.         dw      l65ca
  20975.         dc      'ADDR'
  20976.         dw      l6576
  20977.         dc      'SIZEOF'
  20978.         dw      l659d
  20979.         dc      'BDOSHL'
  20980.         dw      l6553
  20981.         dc      'BDOS'
  20982.         dw      l6554
  20983.         dc      'BIOSHL'
  20984.         dw      l651e
  20985.         dc      'BIOS'
  20986.         dw      l651f
  20987.         db      0
  20988. l78fa:
  20989.         dc      'MEM'
  20990.         dw      0
  20991.         db      0
  20992. ;
  20993. ; Start of dynamic data
  20994. ; - originally at page boundary - here : 7900h
  20995. ;
  20996. ; Dynamic data area starts - shared by editor and compiler most
  20997. ;
  20998. l7900:
  20999.         db      1ah             ; Compile flag:
  21000.                                 ; 0: Compile to memory
  21001.                                 ; 1: Compile to .COM/.CHN file
  21002.                                 ; 2: Searching
  21003. l7901:
  21004.         db      'd'             ; Error code
  21005. l7902:
  21006.         db      'SE'            ; Code pointer
  21007. l7904:
  21008.         db      'EK'            ; Code start address
  21009. l7906:
  21010.         db      'EO'            ; Code end address
  21011. l7908:
  21012.         db      'L',0ceh        ; Start of data
  21013. l790a:
  21014.         db      0dah,'d'        ; End of code address
  21015. l790c:
  21016.         db      'FI'            ; Current editor address
  21017. l790e:
  21018.         db      'L'             ; Memory read flag (0 is read)
  21019. l790f:
  21020.         db      'ESIZ',0c5h,0fah,'dFILEPO',0d3h,0f2h
  21021.         db      'dKEYPRESSE',0c4h,0ch,'dMEMAVAI',0cch
  21022. ;
  21023. ; FCB of source file
  21024. ;
  21025. l7933:
  21026.         db      14h
  21027.         db      'eMAXAVAI'
  21028.         db      0cch
  21029.         db      19h,'ePOR',0d4h,0bfh,'eSTACKPT'
  21030.         db      0d2h,0cah,'eADD',0d2h,'v'
  21031.         db      'eSI'
  21032. ;
  21033. ; DISK BUFFER
  21034. ;
  21035. l7957:
  21036.         db      'ZEO',0c6h,9dh,'eBDOS'
  21037.         db      'H',0cch,'SeBDO',0d3h,'TeBIOSH'
  21038.         db      0cch,1eh,'eBIO',0d3h,1fh,'e'
  21039.         db      0,'ME',0cdh,0,0,0
  21040. l7980:: ;;**
  21041.  
  21042. l79d7   equ     l7957+RecLng    ; Start of source line
  21043. l7a57   equ     l79d7+RecLng
  21044. l7ad7   equ     l7a57+RecLng    ; Top of used memory on start
  21045. l7b57   equ     l7ad7+RecLng
  21046. l7b58   equ     l7b57+1         ; Value of symbol
  21047. l7b59   equ     l7b58+1
  21048. l7b5a   equ     l7b59+1         ; Type table
  21049. l7b5c   equ     l7b5a+2         ; Type
  21050. l7b5d   equ     l7b5c+1
  21051. l7b5e   equ     l7b5d+1         ; Lo set limit
  21052. l7b60   equ     l7b5e+2         ; Hi set limit
  21053. l7b62   equ     l7b60+2         ; Length of type
  21054. l7b64   equ     l7b62+2
  21055. l7b65   equ     l7b64+1
  21056. l7b69   equ     l7b65+4
  21057. l7b6b   equ     l7b69+2
  21058. l7b6d   equ     l7b6b+2         ; Last memory address
  21059. l7b6f   equ     l7b6d+2         ; TEMP
  21060. l7b71   equ     l7b6f+2         ; TEMP
  21061. l7b72   equ     l7b71+1         ; EDT: Pointer to delimters
  21062. l7b73   equ     l7b72+1         ; Label pointer
  21063. l7b74   equ     l7b73+1         ; EDT: Edited line
  21064. l7b75   equ     l7b74+1         ; Previous label pointer
  21065. l7b77   equ     l7b75+2         ; Top of available memory
  21066. l7b79   equ     l7b77+2
  21067. l7b7b   equ     l7b79+2         ; Current label pointer
  21068. l7b7d   equ     l7b7b+2
  21069. l7b7f   equ     l7b7d+2
  21070. l7b81   equ     l7b7f+2
  21071. l7b83   equ     l7b81+2
  21072. l7b85   equ     l7b83+2
  21073. l7b87   equ     l7b85+2
  21074. l7b88   equ     l7b87+1
  21075. l7b89   equ     l7b88+1
  21076. l7b8b   equ     l7b89+2
  21077. l7b8d   equ     l7b8b+2
  21078. l7b8f   equ     l7b8d+2
  21079. l7b90   equ     l7b8f+1
  21080. l7b91   equ     l7b90+1         ; ???
  21081. l7b92   equ     l7b91+1         ; ???
  21082. curtype_l7b93   equ     l7b92+1         ; Type
  21083. l7b94   equ     curtype_l7b93+1         ; ???
  21084. l7b95   equ     l7b94+1
  21085. l7b96   equ     l7b95+1         ; OVERLAY number
  21086. l7b97   equ     l7b96+1         ; PROCEDURE (=0) or FUNCTION (<>0)
  21087. l7b98   equ     l7b97+1
  21088. l7b99   equ     l7b98+1         ; Overlay flag (-1)
  21089. l7b9a   equ     l7b99+1
  21090. l7b9b   equ     l7b9a+1
  21091. l7b9c   equ     l7b9b+1
  21092. l7b9d   equ     l7b9c+1         ; Option bits
  21093. l7b9e   equ     l7b9d+1         ; Local PROCEDURE/FUNCTION options
  21094. l7b9f   equ     l7b9e+1
  21095. l7ba0   equ     l7b9f+1         ; End on break
  21096. l7ba1   equ     l7ba0+1
  21097. l7ba2   equ     l7ba1+1         ; End of file
  21098. l7ba3   equ     l7ba2+1
  21099. l7ba4   equ     l7ba3+1
  21100. l7ba6   equ     l7ba4+2
  21101. l7ba7   equ     l7ba6+1
  21102. l7ba9   equ     l7ba7+2
  21103. l7bab   equ     l7ba9+2         ; Data pointer for overlay
  21104. l7bb0   equ     l7bab+5         ; Length of overlay
  21105. l7bb2   equ     l7bb0+2         ; OVERLAY file name
  21106. l7bbd   equ     l7bb2+11
  21107. l7bbe   equ     l7bbd+1
  21108. l7bc0   equ     l7bbe+2
  21109. l7bc1   equ     l7bc0+1
  21110. l7bc2   equ     l7bc1+1
  21111. l7bc4   equ     l7bc2+2
  21112. l7bc6   equ     l7bc4+2
  21113. l7bc7   equ     l7bc6+1         ; Depth for WITH
  21114. l7bc8   equ     l7bc7+1
  21115. l7bc9   equ     l7bc8+1
  21116. l7bca   equ     l7bc9+1
  21117. l7bcc   equ     l7bca+2
  21118. l7bd5   equ     l7bcc+9
  21119. l7bd7   equ     l7bd5+2         ; Source pointer
  21120. l7bd9   equ     l7bd7+2         ; Dtto.
  21121. l7bdb   equ     l7bd9+2         ; File access
  21122. l7bdc   equ     l7bdb+1         ; Record pointer
  21123. l7bdd   equ     l7bdc+1         ; Record base
  21124. l7bdf   equ     l7bdd+2
  21125. l7be1   equ     l7bdf+2         ; Top of .COM file
  21126. l7be3   equ     l7be1+2         ; Back fix level
  21127. l7be4   equ     l7be3+1         ; Saved top of .COM file
  21128. l7be6   equ     l7be4+2
  21129. l7be8   equ     l7be6+2
  21130. l7be9   equ     l7be8+1
  21131. l7beb   equ     l7be9+2
  21132. l7bed   equ     l7beb+2
  21133. l7bef   equ     l7bed+2         ; Line count
  21134. l7bf5   equ     l7bef+6         ; Start of text
  21135.  
  21136. end
  21137.         savebin "tp.com",begin,end-begin
  21138.        
  21139.         LABELSLIST "../../us/user.l"
  21140.