?login_element?

Subversion Repositories NedoOS

Rev

Rev 732 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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. TERM equ _TRUE;FALSE
  29.  
  30. OS      equ     0000h
  31. DU      equ     0004h ;TODO change to GETPATH and subdirs
  32. BDOS    equ     0005h
  33. ;TPAtop equ     BDOS+1
  34. NEDOOSMEMTOP=0xff00;0xdc06 ;TODO 0x0000?
  35. Number  equ     005dh
  36.  
  37. ;TPA    equ     0100h
  38.  
  39. ;CP/M function codes:
  40. ;_resdsk        equ     13 ;TODO
  41. ;_seldsk        equ     14 ;
  42. _open   equ     15 ;
  43. _close  equ     16 ;
  44. _srcfrs equ     17 ;
  45. _srcnxt equ     18 ;
  46. _delete equ     19 ;
  47. _rdseq  equ     20 ;
  48. _wrseq  equ     21 ;
  49. _make   equ     22 ;
  50. _rename equ     23 ;TODO
  51. _retdsk equ     25 ;removed TODO (return A=current drive)
  52. _setdma equ     26 ;
  53. _getalv equ     27 ;removed TODO
  54. _getdpb equ     31 ;removed TODO
  55. _rndrd  equ     33 ;
  56. _rndwr  equ     34 ;
  57. _filsiz equ     35 ;TODO (lib?)
  58.  
  59. RecLng          equ     128     ; Standard record length
  60. Dirlng          equ     15
  61.  
  62. MaxParams       equ     31
  63.  
  64. a_const         equ      2
  65. a_conin         equ      3
  66. a_conout        equ      4
  67. a_list          equ      5
  68. a_auxout        equ      6
  69. a_auxin         equ      7
  70.  
  71. _.const         equ     (a_const-1)*3
  72. _.conin         equ     (a_conin-1)*3
  73. _.conout        equ     (a_conout-1)*3
  74. _.list          equ     (a_list-1)*3
  75. _.auxout        equ     (a_auxout-1)*3
  76. _.auxin         equ     (a_auxin-1)*3
  77.  
  78. Fdrv            equ      1
  79. Fname           equ      8
  80. Fext            equ      3
  81. _SYS            equ     10
  82. _ex             equ     12
  83. DIRlen          equ     16
  84. _rrn            equ     33 ;shift to random record number in FCB
  85. FCBlen          equ     36
  86.  
  87. FIB.rec         equ     4               ; Pointer #records
  88. FIB.reclen      equ     6               ; Pointer record length
  89. FIB.cur         equ     8               ; Pointer to current record
  90. FIB.FCB         equ     12              ; Pointer to FCB
  91. FIBlen          equ     FIB.FCB+FCBlen  ; FIB length less buffer
  92. FIB.buff        equ     FIBlen          ; Pointer to buffer
  93.  
  94. FIBtype         equ     00001111b
  95.  
  96. rd.bit          equ     4
  97. wr.bit          equ     5
  98. out.bit         equ     6
  99. in.bit          equ     7
  100.  
  101. _.in            equ     10000000b
  102. _.out           equ     01000000b
  103. _.read          equ     00010000b
  104.  
  105. FixRecLen       equ     4       ; Fixed record length
  106. Rec.Wr.bit      equ     0
  107. Rec.New.bit     equ     1
  108. Rec.Wr          equ     01b
  109. Rec.New         equ     10b
  110.  
  111. RAMdevice       equ     6
  112.  
  113. HeapLen         equ     4       ; Heap administration
  114. HeapLOadr       equ     0       ; Address location
  115. HeapHIadr       equ     1
  116. HeapLOlen       equ     2       ; Length location
  117. HeapHIlen       equ     3
  118.  
  119. null    equ     00h
  120. bs      equ     08h
  121. tab     equ     09h
  122. lf      equ     0ah
  123. cr      equ     0dh
  124. eof     equ     1ah
  125. esc     equ     1bh
  126. CtrlC   equ     'C'-'@'
  127. Xoff    equ     'S'-'@'
  128. a_CAN   equ     'U'-'@'
  129. CtrlX   equ     'X'-'@'
  130. ;DEL    equ     7fh
  131.  
  132. LoMask  equ     00001111b
  133. DPBMASK equ     00011111b
  134. NOMSB   equ     01111111b
  135. MSB     equ     10000000b
  136. LSB     equ     00000001b
  137. MMSB    equ     1000000000000000b
  138.  
  139. MINWID  equ     56                      ; Min width for filename
  140.  
  141. MAXINT  equ     32767
  142. DefSTR  equ     8
  143.  
  144. _LB     equ     0
  145. _MB     equ     7
  146.  
  147. sgn.bit         equ     7
  148. sign.bit        equ     10000000b
  149.  
  150. mant.len        equ     5               ; Byte length  of mantissa
  151. Real.Len        equ     6               ; Length of real
  152. bit.len         equ     8               ; Bits in a byte
  153. exp.offset      equ     080h            ; Offset in exponent
  154. Exp.One         equ     exp.offset+1    ; Exponent for >=1.0
  155. int.max         equ     exp.offset+15   ; Max exponent for an integer
  156. mant.bits       equ     mant.len*bit.len
  157. real.dig        equ     24              ; Length of mantissa
  158. real.field      equ     7               ; Real field size
  159. real.ASCII      equ     12              ; Decimal places
  160. ExpFix          equ     77              ; Exponent fix for real to ASCII
  161. ExpRange        equ     0d9h            ; Exponent range
  162. sqr.exp         equ     014h            ; SQRT exponent fix
  163. sin.min         equ     06ch            ; SIN/COS minimum exponent
  164. ln.min          equ     067h            ; LN  minimum exponent
  165. exp.max         equ     088h            ; EXP maximum exponent
  166.  
  167. dot.bit         equ     6               ; Status of dot in real
  168. exps.bit        equ     5               ; Sign of exponent
  169. exp.bit         equ     4               ; Exponent
  170.  
  171. l00fe   equ     254             ; Mystery editor size
  172.  
  173. MEMGAP  equ      708            ; Memory gap at top of memory
  174. StkSpc  equ     1024            ; Stack space
  175. _SavLen equ     8192
  176.  
  177. _RST    equ     7               ; ** CAUTION **
  178. RSTADDR equ     _RST*8 ;SHL 3   ; RST address     (0x0038H)
  179. RST     equ     11000111b + RSTADDR; RST instruction (0xFFH)
  180.  
  181. a_OVLADR        equ     9000h           ; Overlay load address
  182.  
  183. _LD.A           equ     03eh    ; LD A,xx
  184. _LD.BC          equ     001h    ; LD BC,xxxx
  185. _LD.DE          equ     011h    ; LD DE,xxxx
  186. _LD.HL          equ     021h    ; LD HL,xxxx
  187. _LD.SP          equ     031h    ; LD SP,xxxx
  188. _LD_a_DE                equ     5bedh   ; LD DE,(xxxx)
  189. _LD_a_HL                equ     02ah    ; LD HL,(xxxx)
  190. _LDHL_a         equ     022h    ; LD (xxxx),HL
  191. _LDA_a          equ     032h    ; LD (xxxx),A
  192. _JP             equ     0c3h    ; JP xxxx
  193. _CALL           equ     0cdh    ; CALL addr
  194. _JPZ            equ     0cah    ; JP Z,xxxx
  195. _EXX            equ     0d9h    ; EXX
  196. _POP.HL         equ     0e1h    ; POP HL
  197. _PUSH.HL        equ     0e5h    ; PUSH HL
  198. _INC.HL         equ     023h    ; PUSH HL
  199. _DEC.HL         equ     02bh    ; PUSH HL
  200. ;
  201. skip            equ     03eh    ; LD A,xx
  202. skip.2          equ     001h    ; LD BC,xx
  203. skip.3          equ     011h    ; LD DE,xx
  204.  
  205. _LinLen         equ     127
  206.  
  207. _MaxBuf         equ     126     ; Max line input
  208. _MaxSamp        equ      30     ; Max sample input
  209.  
  210. _Ahead          equ     20      ; Size of ahead buffer
  211.  
  212. set.len         equ     32
  213.  
  214. DefWITH         equ     2
  215.  
  216. _Byte           equ     1
  217. _Addr           equ     2
  218.  
  219. _Array          equ      1
  220. _Record         equ      2
  221. _Set            equ      3
  222. _Ptr            equ      4
  223. _RecF           equ      5
  224. _TxtF           equ      6
  225. _UntF           equ      7
  226. _String         equ      8
  227. _Real           equ      9
  228. _Integ          equ     10
  229. _Bool           equ     11
  230. _Char           equ     12
  231. ;13=element of a set?
  232.  
  233. _Label          equ     1
  234. _Const          equ     2
  235. _Type           equ     3
  236. _Var            equ     4
  237. _Proc           equ     5
  238. _Overly         equ     7
  239. _Begin          equ     8
  240. ;
  241. ; Option selection bits
  242. ;
  243. __Ropt          equ     00000010b
  244. __Uopt          equ     00001000b
  245. ;
  246. _Iopt           equ     0
  247. _Ropt           equ     1
  248. _Aopt           equ     2
  249. _Uopt           equ     3
  250. _Xopt           equ     4
  251. _Vopt           equ     5
  252. _Bopt           equ     6
  253. _Copt           equ     7
  254. ;
  255. ; Search option list
  256. ;
  257. _W              equ     0
  258. _N              equ     1
  259. _U              equ     2
  260. _G              equ     3
  261. _B              equ     4
  262. ;
  263. ; Error levels
  264. ;
  265. _BRK            equ     0       ; User break
  266. _IO             equ     1       ; I/O error
  267. _RT             equ     2       ; Run time error
  268. ;
  269. ; BREAK error
  270. ;
  271. _CBRK           equ     1
  272. ;
  273. ; Compiler errors
  274. ;
  275. _ColExp         equ       1
  276. _SemiExp        equ       2
  277. _CommaExp       equ       3
  278. _LftPar         equ       4
  279. _RgtPar         equ       5
  280. _EquExp         equ       6
  281. _AssigExp       equ       7
  282. _LftBrExp       equ       8
  283. _RgtBrExp       equ       9
  284. _DotExp         equ      10
  285. _TwoDots        equ      11
  286. _BEGINexp       equ      12
  287. _NoDO           equ      13
  288. _End            equ      14
  289. _NoOF           equ      15
  290. _SUBexp         equ      16
  291. _StrIdx         equ      17
  292. _NoDOWN_TO      equ      18
  293. _BoolExp        equ      20
  294. _FileVarExp     equ      21
  295. _IntConst       equ      22
  296. _IntExpr        equ      23
  297. _IntVarExp      equ      24
  298. _IntRealCexp    equ      25
  299. _NumExprExp     equ      26
  300. _NumVarExp      equ      27
  301. _PtrVarExp      equ      28
  302. _RecVarExp      equ      29
  303. _SimTyp         equ      30
  304. _SimpExpr       equ      31
  305. _StrgConExp     equ      32
  306. _StrgExpExp     equ      33
  307. _StrgVarExp     equ      34
  308. _MustTextFile   equ      35
  309. _TypeExp        equ      36
  310. _UntFileExp     equ      37
  311. _UnkLabel       equ      40
  312. _Undef          equ      41
  313. _InkPointer     equ      42
  314. _DoubleLab      equ      43
  315. _InvType        equ      44
  316. _ConstRange     equ      45
  317. _IllCASE        equ      46
  318. _IllOps         equ      47
  319. _InvResult      equ      48
  320. _IllStrgLen     equ      49
  321. _StrConst       equ      50
  322. _IllSkalar      equ      51
  323. _IllLimit       equ      52
  324. _ResWord        equ      53
  325. _IllAss         equ      54
  326. _StrConLong     equ      55
  327. _IntegErr       equ      56
  328. _RealErr        equ      57
  329. _IllChar        equ      58
  330. _IllConst       equ      60
  331. _InvFilPtr      equ      61
  332. _NoStruktVar    equ      62
  333. _IllTxtFile     equ      63
  334. _IllFileType    equ      64
  335. _NoUntypeFile   equ      65
  336. _InvIO          equ      66
  337. _VarFile        equ      67
  338. _FileF          equ      68
  339. _InvSetOrder    equ      69
  340. _IllSetRange    equ      70
  341. _IllGOTO        equ      71
  342. _IllLabel       equ      72
  343. _UndefFORW      equ      73
  344. _IllINLINE      equ      74
  345. _InvalABS       equ      75
  346. _OvlFORW        equ      76
  347. _OvlDirErr      equ      77
  348. _NoFileErr      equ      90
  349. _IllSrcEnd      equ      91
  350. _NoOvl          equ      92
  351. _CompDirec      equ      93
  352. _INCLerr        equ      96
  353. _TooManyWITH    equ      97
  354. _MemOvfl        equ      98
  355. _CompOvfl       equ      99
  356. _IndxErr        equ     144
  357. _RngErr         equ     145
  358. _ABORT          equ     202
  359. _FndRTerr       equ     200
  360. _DskFull        equ     250
  361. ;
  362. ; Run-Time errors
  363. ;
  364. _FLPovfl        equ       1     ; 0x01
  365. _DivZero        equ       2     ; 0x02
  366. _NegSqrt        equ       3     ; 0x03
  367. _LNerr          equ       4     ; 0x04
  368. _StrLenErr      equ      16     ; 0x10
  369. _TruncOvl       equ     146     ; 0x92
  370. _OVLerr         equ     240     ; 0xf0
  371. _HeapErr        equ     255     ; 0xff
  372. ;
  373. ; Run-Time I/O errors
  374. ;
  375. _NoFile         equ       1     ; 0x01
  376. _NoRead         equ       2     ; 0x02
  377. _NoWrite        equ       3     ; 0x03
  378. _BlkErr         equ       4     ; 0x04
  379. _IllNum         equ      16     ; 0x10
  380. _IllIO          equ      32     ; 0x20
  381. _DirErr         equ      33     ; 0x21
  382. _StdAssErr      equ      34     ; 0x22
  383. _InvRec         equ     144     ; 0x90
  384. _SeekEOF        equ     145     ; 0x91
  385. _IllEOF         equ     153     ; 0x99
  386. _WrErr          equ     240     ; 0xF0
  387. _DirFull        equ     241     ; 0xF1
  388. _OvflErr        equ     242     ; 0xF2
  389. _NoClose        equ     255     ; 0xFF
  390.  
  391. TPhead          equ     21      ; Header code length for ERROR
  392.  
  393. _Video          equ     7       ; Status
  394.  
  395. a_DUMMY equ     04d2h
  396.  
  397. ;l0300  equ     0300h
  398. ;l0800  equ     0800h
  399. l07d0   equ     07d0h
  400.  
  401. l00a0   equ     00a0h           ; Keypressed
  402. l00a3   equ     00a3h           ; Read KBD
  403. l00a6   equ     00a6h           ; Console output
  404. l00a9   equ     00a9h           ; List output
  405. l00ac   equ     00ach           ; Auxiliary output
  406. l00af   equ     00afh           ; Auxiliary input
  407. l00b2   equ     00b2h           ; Console output
  408. l00b5   equ     00b5h           ; Read USR
  409.  
  410. l00b8   equ     00b8h           ; Base FIB
  411. l00ba   equ     00bah           ; ConinFIB
  412. l00bc   equ     00bch           ; LstFIB
  413. l00be   equ     00beh           ; AuxFIB
  414. l00c0   equ     00c0h           ; UsrFIB
  415. l00c2   equ     00c2h           ; StdIOdev
  416. l00c4   equ     00c4h           ; Heap pointer
  417. l00c6   equ     00c6h           ; Recursion pointer
  418. l00c8   equ     00c8h           ; Four byte random value
  419. l00cc   equ     00cch           ; Base PC
  420. l00ce   equ     00ceh           ; Current PC
  421. l00d0   equ     00d0h           ; I/O result
  422. l00d1   equ     00d1h           ; Buffer length
  423. l00d2   equ     00d2h           ; RTL top of memory
  424. l00d4   equ     00d4h           ; Current pointer
  425. l00d6   equ     00d6h           ; Top pointer
  426. l00d8   equ     00d8h           ; Run mode
  427. l00d9   equ     00d9h           ; + JP xxxx
  428. l00da   equ     00dah           ; + Restart vector
  429. l00dc   equ     00dch           ; Overlay drive
  430. l00dd   equ     00ddh           ; $C mode
  431. l00e0   equ     00e0h           ; Video mode
  432. l00e8   equ     00e8h           ; Pointer ????
  433. l00f4   equ     00f4h           ; Available memory
  434.  
  435. l0000   equ     00h
  436. l0001   equ     01h
  437. l0002   equ     02h
  438. l0005   equ     05h
  439. l0008   equ     08h
  440. l000c   equ     0ch
  441. l000d   equ     0dh ;for save environment
  442. l0015   equ     15h
  443. ;l0019  equ     19h
  444. l0024   equ     24h
  445. l0030   equ     30h
  446. l005c   equ     5ch
  447. l0080   equ     80h
  448. l0081   equ     81h
  449.  
  450. l00b0   equ     00b0h
  451. l00de   equ     0deh
  452. l00e2   equ     0e2h
  453. l00e4   equ     0e4h
  454. l00e6   equ     0e6h
  455. l00e9   equ     0e9h
  456. l00ea   equ     0eah
  457. l00ec   equ     0ech
  458. l00ed   equ     0edh
  459. l00f0   equ     0f0h
  460. l00f2   equ     0f2h
  461. l00f6   equ     0f6h
  462. l00f8   equ     0f8h
  463.  
  464. lfff3   equ     0fff3h
  465. lfffc   equ     0fffch
  466. lffff   equ     0ffffh
  467.  
  468. l0100:
  469.         if TERM
  470.         call initstdio
  471.         else
  472.         OS_HIDEFROMPARENT
  473.         ld e,6 ;textmode
  474.         OS_SETGFX
  475.         endif
  476. progstartaddr=$+1
  477.         jp      l20e2           ; Jump over Run Time Library
  478. ;
  479. ; %%%%%%%%%%%%%%%%%%%%%%%%%
  480. ; %%% RUN TIME ROUTINES %%%
  481. ; %%%%%%%%%%%%%%%%%%%%%%%%%
  482. ;
  483.         db      0cdh,0abh
  484.         db      'Copyright (C) 1985 BORLAND Inc',null
  485. l0124:
  486.         db      4               ; CPU speed
  487.         db      0,0a1h,'B'
  488. ;
  489. ; &&&&&&&&&&&&&&&&&&
  490. ; &&& PATCH AREA &&&
  491. ; &&&&&&&&&&&&&&&&&&
  492. ;
  493. l0128:
  494.         cp      0fch            ; Test special key
  495.         jp      z,l2e8f
  496.         cp      esc             ; Test ESCape
  497.         jp      z,l2e8f
  498.         jp      l2e88
  499. ;
  500.         ds      30
  501. ;
  502. l0153:
  503.         db      TermLen
  504.         db      'NedoOS BDOS';'Schneider Joyce'
  505. TermLen equ     $-l0153-1
  506.         db      '12864'
  507. l0168:
  508.         db      80;90           ; Screen columns
  509. l0169:
  510.         dw      25;31           ; Screen lines
  511. ;
  512. ; Lead in sequence: Leave 24x80 mode
  513. ;
  514. l016b:
  515.         db 0;db 2,esc,'y'
  516. ;
  517.         db      1bh,'Y  ',1,1,1dh
  518.         db      3,3,1bh,1bh,1bh,0d5h
  519. ;
  520. ; Lead out sequence: Enter 24x80 mode
  521. ;
  522. l017b:
  523.         db 0;db 2,esc,'x'
  524. ;
  525.         db      0,0,1ch,0,17h,17h
  526.         db      1dh,17h,17h,0efh,9eh,0cdh,0bdh
  527. ;
  528. ;setxy sequence
  529. ;not used in NedoOS
  530. l018b:
  531.         db      4,esc,'Y',0,0
  532.         ds      11
  533. ll018b  equ     $-l018b
  534.  
  535. l019b:
  536.         db      1               ; Binary indicator (1 is binary)
  537. l019c:
  538.         db      ' '             ; Offset for column
  539. l019d:
  540.         db      ' '             ; Offset for row
  541. l019e:
  542.         db      4               ; Position of column
  543. l019f:
  544.         db      3               ; Position of row
  545. l01a0:
  546.         dw      0
  547. ;
  548. ; Clear display
  549. ;not used in NedoOS
  550. l01a2:
  551.         db      2,esc,'E'
  552.         ds      3
  553. ;
  554. ; Home cursor
  555. ;not used in NedoOS
  556. l01a8:
  557.         db      2,esc,'H'
  558.         ds      3
  559. ;
  560. ; Insert line
  561. ;if zero in first byte, function not implemented in this terminal
  562. l01ae:
  563.         db 0;db 2,esc,'L'
  564.         ds      3
  565. ;
  566. ; Delete line
  567. ;if zero in first byte, function not implemented in this terminal
  568. l01b4:
  569.         db 0;db 2,esc,'M'
  570.         ds      3
  571. l01ba:
  572.         dw      0
  573. ;
  574. ; Clear to end of line
  575. ;if zero in first byte, function not implemented in this terminal
  576. l01bc:
  577.         if TERM
  578.         db 1
  579.         else
  580.         db 0;db 2,esc,'K'
  581.         endif
  582.         ds      3
  583. ;
  584. ; Turn off inverse
  585. ;
  586. l01c2:
  587.         db      2,esc,'q'
  588.         ds      3
  589. ;
  590. ; Turn on inverse
  591. ;
  592. l01c8:
  593.         db      2,esc,'p'
  594.         ds      3
  595. l01ce:
  596.         dw      0
  597. ;
  598. ; Print control string ^HL on console
  599. ; C set if control not defined
  600. ;
  601. l01d0:
  602.         ld      a,(hl)          ; Get character
  603.         or      a               ; Test defined
  604.         scf
  605.         ret     z               ; Nope as C set says
  606. l01d4:
  607.         inc     hl
  608.         push    af
  609.         push    hl
  610.         push ix ;TODO remove?
  611.         push iy
  612.         ld      a,(hl)          ; Get character
  613.         if TERM
  614.         PRCHAR_ ;call   l01e8           ; Put to console
  615.         else
  616.         PRCHAR ;call    l01e8           ; Put to console
  617.         endif
  618.         pop iy
  619.         pop ix ;TODO remove?
  620.         pop     hl
  621.         pop     af
  622.         dec     a
  623.         ret     z
  624.         jr      l01d4
  625. ;
  626. ; Give new line on console
  627. ;
  628. l01e1:
  629.         call    l0200
  630.         db      cr,lf,null
  631.         ret
  632. ;
  633. ; Put character on console
  634. ;
  635. l01e8:
  636.         push ix ;TODO remove?
  637.         push iy
  638.         ;ld     l,a
  639.         ;push   hl              ; Push onto stack
  640.         if TERM
  641.         PRCHAR_ ;call   l00a6           ; Put to console
  642.         else
  643.         PRCHAR ;call    l00a6           ; Put to console
  644.         endif
  645.         pop iy
  646.         pop ix ;TODO remove?
  647.         ret
  648.  
  649. ;
  650. ; Check character for attribute
  651. ; MSB set for normal output
  652. ;
  653. l01ee:
  654.         cp      MSB             ; Test attribute set
  655.         call    c,setlowvideo           ; Nope, set invers video
  656.         call    nc,setnormvideo ; Yeap, set normal video
  657.         and     NOMSB           ; Strip off attribute
  658.         jr      l01e8
  659. ;
  660. ; Print immediate control string on console
  661. ;
  662. l01fa:
  663.         push    hl
  664.         ld      hl,l01ee        ; Get new output routine
  665.         jr      l0204
  666. ;
  667. ; Print immediate string on console
  668. ;
  669. l0200:
  670.         push    hl
  671.         ld      hl,l01e8        ; Get new output routine
  672. l0204:
  673.         ld      (l0213),hl      ; Change output vector
  674.         pop     hl
  675.         ex      (sp),hl         ; Get pointer to string
  676.         push    af
  677.         push    bc
  678.         push    de
  679. l020c:
  680.         ld      a,(hl)          ; Get character
  681.         inc     hl
  682.         or      a               ; Test end
  683.         jr      z,l0218         ; Yeap
  684.         push    hl
  685. l0213   equ     $+1
  686.         call    a_DUMMY         ; Process output
  687.         pop     hl
  688.         jr      l020c
  689. l0218:
  690.         pop     de
  691.         pop     bc
  692.         pop     af
  693.         ex      (sp),hl
  694.         ret
  695. ;
  696. ; Delay by value in reg HL
  697. ;
  698. l021d:
  699.         ld      a,l
  700.         or      h               ; Test any value given
  701.         ret     z               ; Nope
  702.         ld      a,(l0124)       ; Get CPU speed
  703.         add     a,a
  704.         add     a,a
  705.         add     a,a             ; Build delay value
  706. l0226:
  707.         ex      (sp),hl         ;  5 cycles
  708.         ex      (sp),hl         ; 10 cycles
  709.         ex      (sp),hl         ; 15 cycles
  710.         ex      (sp),hl         ; 20 cycles
  711.         push    bc              ; 23 cycles
  712.         ld      bc,1234         ; 26 cycles
  713.         pop     bc              ; 29 cycles
  714.         dec     a               ; 30 cycles
  715.         jr      nz,l0226
  716.         dec     hl
  717.         jr      l021d
  718. ;
  719. ; Give control and delay if control defined
  720. ;
  721. l0235:
  722.         call    l01d0           ; Give control
  723.         ret     c               ; Not defined
  724.         ld      hl,(l01ce)      ; Get value
  725.         jr      l021d           ; Delay
  726. ;
  727. ; Clear screen
  728. ;
  729. l023e:
  730.         push    af
  731.         push    bc
  732.         push    de
  733.         push    hl
  734.        if 1==1
  735.         push ix ;TODO remove?
  736.         push iy ;needed!!!
  737.         if TERM
  738.         ld de,0
  739.         SETXY_
  740.         CLS_ ;print 25 lines of spaces except one
  741.         else
  742.         ld e,0
  743.         OS_CLS
  744.         endif
  745.         pop iy
  746.         pop ix ;TODO remove?
  747.        else
  748.         ld      hl,l01a8
  749.         call    l0235           ; Home cursor
  750.         ld      hl,l01a2
  751. l024b:
  752.         call    l01d0           ; Clear display
  753.        endif
  754.         ld      hl,(l01ba)
  755.         call    nc,l021d        ; Delay if defined
  756.         pop     hl
  757.         pop     de
  758.         pop     bc
  759.         pop     af
  760.         ret
  761. ;
  762. ; Delete line
  763. ;
  764. l0259:
  765.         if 1==1
  766.         ;jr $ ;TODO
  767.         else
  768.         push    af
  769.         push    bc
  770.         push    de
  771.         push    hl
  772.         ld      hl,l01b4
  773.         jr      l024b           ; Delete line
  774.         endif
  775. ;
  776. ; Insert line
  777. ;
  778. l0262:
  779.         if 1==1
  780.         ;jr $ ;TODO
  781.         else
  782.         push    af
  783.         push    bc
  784.         push    de
  785.         push    hl
  786.         ld      hl,l01ae
  787.         jr      l024b           ; Insert line
  788.         endif
  789. ;
  790. ; Set low video
  791. ;
  792. setlowvideo:
  793.         push    af
  794.         ld      a,(l00e0)       ;ok ;FIXME ; Get video mode
  795.         or      a               ; Test low mode already set
  796.         jr      z,l0282         ; Yeap, skip
  797.         if 1==1
  798.         push bc
  799.         push de
  800.         push hl
  801.         push ix
  802.         push iy
  803.         xor     a
  804.         ld      (l00e0),a       ;ok ;FIXME ; Set video mode
  805.         if TERM
  806.         ld de,0x0007
  807.         else
  808.         ld e,0x07;0x38
  809.         endif
  810. l027c:
  811.         if TERM
  812.         SETCOLOR_
  813.         else
  814.         OS_SETCOLOR
  815.         endif
  816.         pop iy
  817.         pop ix
  818.         pop hl
  819.         pop de
  820.         pop bc
  821.         else
  822.         push    bc
  823.         push    de
  824.         push    hl
  825.         xor     a
  826.         ld      (l00e0),a       ;ok ;FIXME ; Set video mode
  827.         ld      hl,l01c8        ; Set attribute
  828. l027c:
  829.         call    l0235           ; Give control
  830.         pop     hl
  831.         pop     de
  832.         pop     bc
  833.         endif
  834. l0282:
  835.         pop     af
  836.         ret
  837. ;
  838. ; Set normal video
  839. ;
  840. setnormvideo:
  841.         push    af
  842.         ld      a,(l00e0)       ;ok ;FIXME ; Get video mode
  843.         cp      -1              ; Test normal mode already set
  844.         jr      z,l0282         ; Yeap, skip
  845.         if 1==1
  846.         push bc
  847.         push de
  848.         push hl
  849.         push ix
  850.         push iy
  851.         ld a,-1
  852.         ld (l00e0),a    ;ok ;FIXME ; Set video mode
  853.         if TERM
  854.         ld de,0x000f
  855.         else
  856.         ld e,0x47;0x07
  857.         endif
  858.         jr l027c
  859.         else
  860.         push    bc
  861.         push    de
  862.         push    hl
  863.         ld      a,-1
  864.         ld      (l00e0),a       ;ok ;FIXME ; Set video mode
  865.         ld      hl,l01c2        ; Reset attribute
  866.         jr      l027c
  867.         endif
  868. ;
  869. ; Erase to end of line
  870. ;
  871. l0299:
  872.         if 1==1
  873.         push af
  874.         push bc
  875.         push de
  876.         push hl
  877.         if TERM
  878.          push ix
  879.          push iy
  880.         call clearrestofline
  881.          pop iy
  882.          pop ix
  883.         endif
  884.         pop hl
  885.         pop de
  886.         pop bc
  887.         pop af
  888.         ret
  889.         else
  890.         push    af
  891.         push    bc
  892.         push    de
  893.         push    hl
  894.         ld      hl,l01bc        ; Clear to end of line
  895.         jr      l027c
  896.         endif
  897. ;
  898. ; Position cursor with X (column) in reg H and y (row) in reg L
  899. ;
  900. l02a2:
  901.         if 1==1
  902.         push af
  903.         push bc
  904.         push de
  905.         push hl
  906.         push ix
  907.         push iy
  908.         ld d,l
  909.         ld e,h
  910.         ;dec d
  911.         ;dec e
  912.         if TERM
  913.         SETXY_
  914.         else
  915.         OS_SETXY
  916.         endif
  917.         pop iy
  918.         pop ix
  919.         pop hl
  920.         pop de
  921.         pop bc
  922.         pop af
  923.         ret
  924.         else
  925.         push    af
  926.         push    bc
  927.         push    de
  928.         push    hl
  929.         push    hl
  930.         ld      de,l00f0
  931.         ld      hl,l018b
  932.         ld      bc,ll018b
  933.         ldir                    ; Unpack control string
  934.         pop     de              ; Get back coordinates
  935.         ld      a,(l019e)       ; Get position of column
  936.         ld      c,a
  937.         ld      a,(l019c)       ; Get offset for column
  938.         add     a,d             ; Build real value
  939.         push    de
  940.         call    l02dc           ; Store it
  941.         pop     de
  942.         ld      a,(l019f)       ; Get position of row
  943.         ld      c,a
  944.         ld      a,(l019d)       ; Get offset for row
  945.         add     a,e             ; Build real value
  946.         call    l02dc           ; Store it
  947.         ld      hl,l00f0
  948.         call    l01d0           ; Give control
  949.         ld      hl,(l01a0)      ; Get delay value
  950.         call    l021d           ; Delay a bit
  951.         pop     hl
  952.         pop     de
  953.         pop     bc
  954.         pop     af
  955.         ret
  956.         endif
  957. ;
  958. ; Store Accu in position in reg C
  959. ;
  960. l02dc:
  961.         ld      hl,l00f0
  962.         ld      b,0
  963.         add     hl,bc           ; Position in string
  964.         ex      de,hl
  965.         ld      hl,l019b
  966.         inc     (hl)            ; Test binary
  967.         dec     (hl)
  968.         jr      z,l02ec         ; Nope, build ASCII
  969.         ld      (de),a          ; Store value
  970.         ret
  971. l02ec:
  972.         dec     de              ; Fix for hi ASCII
  973.         dec     de
  974.         ld      hl,l0307+3      ; Point to divisor
  975.         ld      b,3             ; Set length
  976. l02f3:
  977.         dec     hl
  978.         ld      c,'0'-1         ; Init ASCII
  979. l02f6:
  980.         inc     c               ; Fix quotient
  981.         sub     (hl)            ; Divide
  982.         jr      nc,l02f6
  983.         add     a,(hl)          ; Build last value
  984.         push    af
  985.         ld      a,c
  986.         cp      '0'             ; Test zero
  987.         jr      z,l0302         ; Skip if so
  988.         ld      (de),a          ; Store ASCII
  989. l0302:
  990.         inc     de
  991.         pop     af
  992.         djnz    l02f3
  993.         ret
  994. ;
  995. l0307:
  996.         db      1,10,100
  997. ;
  998. ; Set lead in
  999. ;
  1000. l030a:
  1001.         ld      hl,l016b                ; Give lead in
  1002.         jp      l0235
  1003. ;
  1004. ; Set lead out
  1005. ;
  1006. l0310:
  1007.         ld      hl,l017b                ; Give lead out
  1008.         jp      l0235
  1009. ;
  1010. ; Test key pressed
  1011. ; EXIT  Reg HL holds 1 if key pressed
  1012. ;
  1013. l0316:
  1014.         ;ld     de,_.const
  1015.         ;call   l035f           ; Get state
  1016.         ;and    1               ; Extract the bit
  1017.         xor a ;TODO
  1018.         jr      l0326 ; Expand result to 16 bit
  1019. ;
  1020. ; Read character from console
  1021. ; EXIT  Reg HL holds character
  1022. ;
  1023. l0320:
  1024.         ld      de,_.conin
  1025. l0323:
  1026.         ;call   l035f           ; Get input
  1027.         push ix ;TODO remove?
  1028.         push iy
  1029.         if TERM
  1030. l0323_nokey
  1031.         GETKEY_
  1032.         or a
  1033.         jr z,l0323_nokey
  1034.         else
  1035.         GET_KEY
  1036.         endif
  1037.         pop iy
  1038.         pop ix ;TODO remove?
  1039. l0326:
  1040.         ld      l,a             ; Expand result to 16 bit
  1041.         ld      h,0
  1042.         ret
  1043. ;
  1044. ; Read character from auxiliary device
  1045. ; EXIT  Reg HL holds character
  1046. ;
  1047. l032a:
  1048.          jr l0320 ;??? from console
  1049.         ;ld     de,_.auxin      ; Set function
  1050.         ;jr     l0323           ; Do thru BIOS
  1051. ;
  1052. ; Write character to list device
  1053. ; ENTRY Character on stack
  1054. ;
  1055. l032f:
  1056.          jr l0339 ;??? to screen
  1057.         ;ld     de,_.list       ; Set function
  1058.         ;jr     l033c           ; Do thru BIOS
  1059. ;
  1060. ; Write character to auxiliary device
  1061. ; ENTRY Character on stack
  1062. ;
  1063. l0334:
  1064.          jr l0339 ;??? to screen
  1065.         ;ld     de,_.auxout     ; Set function
  1066.         ;jr     l033c           ; Do thru BIOS
  1067. ;
  1068. ; Write character to console
  1069. ; ENTRY Character on stack
  1070. ;
  1071. l0339:
  1072.         pop     hl
  1073.         pop     bc              ; Get character
  1074.         push    hl
  1075.         ld a,c
  1076.         push af
  1077.         push bc
  1078.         push de
  1079.         push hl
  1080.         push ix
  1081.         push iy
  1082.         if TERM
  1083.         PRCHAR_
  1084.         else
  1085.         PRCHAR
  1086.         endif
  1087.         pop iy
  1088.         pop ix
  1089.         pop hl
  1090.         pop de
  1091.         pop bc
  1092.         pop af
  1093.         ret
  1094.  
  1095.         if TERM
  1096.         include "../_sdk/stdio.asm"
  1097.         endif
  1098.  
  1099.         if 1==0
  1100.         ;ld     de,_.conout     ; Set function
  1101. l033c:
  1102.         pop     hl
  1103.         pop     bc              ; Get character
  1104.         push    hl
  1105.         ld      a,(l00dd)       ;ok ;FIXME ; Get $C mode
  1106.         or      a
  1107.         jr      z,l035f         ; $C-, so skip testing
  1108.         push    de
  1109.         push    bc
  1110.         call    l00a0           ; Test key pressed
  1111.         ld      a,h
  1112.         or      l               ; Nope
  1113.         jr      z,l035d
  1114.         call    readfromkbd             ; Read character
  1115.         cp      Xoff            ; Test XOFF
  1116.         jr      nz,l035d
  1117.         call    readfromkbd
  1118.         cp      CtrlC           ; Test abort
  1119.         jp      z,l20d4         ; Halt if so
  1120. l035d:
  1121.         pop     bc
  1122.         pop     de
  1123. ;
  1124. ; Do BIOS internal call
  1125. ;de=jp addr
  1126. l035f:
  1127.         ret
  1128.         ;ld     hl,(OS+1)       ; Fetch base vector
  1129.         ;add    hl,de           ; Add osffset
  1130.         ;jp     (hl)            ; Go
  1131.         endif
  1132. ;
  1133. ; Init TURBO program
  1134. ; ENTRY Reg HL holds top of RAM
  1135. ;       Reg B holds break mode
  1136. ;               ($C- B=00)
  1137. ;               ($C+ B=FF)
  1138. ;       Reg C holds interrupt mode
  1139. ;               ($U- C=00)
  1140. ;               ($U+ C=rst)
  1141. ;       [rst may be the opcode for the requested
  1142. ;        RST opcode, typically F7 or EF]
  1143. ;
  1144. l0364:
  1145.         ld      (l00d2),hl      ;ok ;FIXME ; Save address
  1146.         ld      a,b
  1147.         ld      (l00dd),a       ;ok ;FIXME ; Set $C mode
  1148.         ld      a,c             ; Get $U
  1149.         or      a
  1150.         jr      z,l037a         ; No interrupt
  1151.         ;ld     a,_JP           ; Set JP to interrupt
  1152.         ;ld     (RSTADDR),a
  1153.         ;ld     hl,l1ffb
  1154.         ;ld     (RSTADDR+1),hl  ; Change vector ;???
  1155. l037a:
  1156.         ld      hl,l03a5
  1157.         ld      de,l00a0
  1158.         ld      bc,ll0018
  1159.         ldir                    ; Unpack I/O
  1160.         ld      hl,l03bd
  1161.         ld      de,l00b8
  1162.         ld      bc,ll000c
  1163.         ldir                    ; Init FIB
  1164.         xor     a
  1165.         ld      l,a
  1166.         ld      h,a
  1167.         ld      (l00d0),a       ;ok ;FIXME ; Clear I/O error
  1168.         ld      (l00d4),hl      ;ok ;FIXME ; Clear some pointers
  1169.         ld      (l00d6),hl ;ok ;FIXME
  1170.         ld      a,_MaxBuf
  1171.         ld      (l00d1),a       ;ok ;FIXME ; Set buffer length
  1172.         ld      (l00e0),a       ;ok ;FIXME ; Set video mode
  1173.         ret
  1174. ;
  1175. ; Character I/O table moved into 0x00A0
  1176. ;
  1177. l03a5:
  1178.         jp      l0316           ; 0x00A0 : Keypressed
  1179.         jp      l0320           ; 0x00A3 : Read KBD
  1180.         jp      l0339           ; 0x00A6 : Console output
  1181.         jp      l032f           ; 0x00A9 : List output
  1182.         jp      l0334           ; 0x00AC : Auxiliary output
  1183.         jp      l032a           ; 0x00AF : Auxiliary input
  1184.         jp      l0339           ; 0x00B2 : Console output
  1185.         jp      l0320           ; 0x00B5 : Read KBD
  1186. ll0018  equ     $-l03a5
  1187. ;
  1188. ; Standard IO control table
  1189. ;
  1190. l03bd:
  1191.         db      11000001b       ; 0x00B8 : Input Output for CON
  1192.         db      0
  1193.         db      10000010b       ; 0x00BA : Input for KBD
  1194.         db      0
  1195.         db      01000011b       ; 0x00BC : Output for LST
  1196.         db      0
  1197.         db      11000100b       ; 0x00BE : Input Output for AUX
  1198.         db      0
  1199.         db      11000101b       ; 0x00C0 : Input Output for USR
  1200.         db      0
  1201.         db      11000001b       ; 0x00C2 : Input Output for CON
  1202.         db      0
  1203. ll000c  equ     $-l03bd
  1204. ;
  1205. ; Put character to console
  1206. ;
  1207. puttoconsole_a:
  1208.         push    bc
  1209.         push    de
  1210.         push    hl
  1211.         push    ix
  1212.         push    iy
  1213.        
  1214.         push    af
  1215.         if TERM
  1216.         PRCHAR_
  1217.         else
  1218.         PRCHAR
  1219.         endif
  1220.         ;ld     l,a
  1221.         ;ld     h,0
  1222.         ;push   hl
  1223.         ;call   l00a6           ; Put to console
  1224.         pop     af
  1225.        
  1226. l03d9:
  1227.         pop     iy
  1228.         pop     ix
  1229.         pop     hl
  1230.         pop     de
  1231.         pop     bc
  1232.         ret
  1233. ;
  1234. ; Read character from keyboard
  1235. ;
  1236. readfromkbd:
  1237.         push    bc
  1238.         push    de
  1239.         push    hl
  1240.         push    ix
  1241.         push    iy
  1242.          if TERM
  1243. readfromkbd_nokey
  1244.         call yieldgetkeyloop ;YIELDGETKEYLOOP
  1245.         or a
  1246.         jr z,readfromkbd_nokey
  1247.          else
  1248.          ld e,0x78
  1249.          OS_PRATTR
  1250.          YIELDGETKEYLOOP
  1251.          push af
  1252.          ld e,0x47
  1253.          OS_PRATTR
  1254.          pop af
  1255.          endif
  1256.         ;call   l00a3           ; Read KBD
  1257.         ;ld     a,l
  1258.         jr      l03d9
  1259. ;
  1260. ; Parse file, allow wildcards
  1261. ;
  1262. l03ee:
  1263.         ld      c,0xff-FALSE    ; Set flag
  1264.         jr      l03fe
  1265. ;
  1266. ; Parse file, wildcards not allowed
  1267. ;
  1268. l03f2:
  1269.         ld      c,FALSE
  1270.         ld      de,(l00d2)      ; Get top of memory for input
  1271. l03f8:
  1272.         inc     de
  1273.         ld      a,(de)
  1274.         cp      ' '             ; Skip blanks
  1275.         jr      z,l03f8
  1276. l03fe:
  1277.         ld      hl,l005c+Fdrv+Fname
  1278.         ld      b,Fext
  1279.         call    l047b           ; Blank extension
  1280. l0406:
  1281.         ld      a,(de)          ; Get character
  1282.         call    doupcase                ; Convert to upper case
  1283.         cp      'A'             ; Test posible drive
  1284.         jr      c,l0420
  1285.         cp      'P'+1
  1286.         jr      nc,l0420
  1287.         ld      b,a             ; Save drive
  1288.         inc     de
  1289.         ld      a,(de)
  1290.         cp      ':'             ; Verify drive
  1291.         jr      nz,l041f
  1292.         ld      a,b
  1293.         sub     'A'-1           ; Make binary
  1294.         inc     de
  1295.         jr      l0421
  1296. l041f:
  1297.         dec     de
  1298. l0420:
  1299.         xor     a               ; Set default drive
  1300. l0421:
  1301.         ld      hl,l005c
  1302.         ld      (hl),a          ; Save drive
  1303.         inc     hl
  1304.         inc     c               ; Test wildcards allowed
  1305.         dec     c
  1306.         jr      z,l0443         ; Nope
  1307.         ld      a,(de)          ; Get character
  1308.         call    l0482           ; Test delimiter
  1309.         jr      nz,l0443        ; Nope
  1310.         cp      '?'             ; Test single wildcard
  1311.         jr      z,l0443         ; Yeap
  1312.         cp      '*'             ; Test wildcard
  1313.         jr      z,l0443         ; Yeap
  1314.         cp      '.'             ; Test dot
  1315.         jr      z,l0443         ; Yeap
  1316.         ld      b,Fname+Fext
  1317.         call    l0477           ; Set wildcard
  1318.         jr      l0453           ; Go init remainder
  1319. l0443:
  1320.         ld      b,Fname
  1321.         call    l045e           ; Parse name
  1322.         ld      a,(de)
  1323.         cp      '.'             ; Test extension delimiter
  1324.         jr      nz,l0453        ; Nope
  1325.         inc     de
  1326.         ld      b,Fext
  1327.         call    l045e           ; Parse extension
  1328. l0453:
  1329.         ld      hl,l005c+_ex
  1330.         ld      b,FCBlen-_ex
  1331. l0458:
  1332.         ld      (hl),0          ; Clear remainder of FCB
  1333.         inc     hl
  1334.         djnz    l0458
  1335.         ret
  1336. ;
  1337. ; Parse B characters
  1338. ;
  1339. l045e:
  1340.         ld      a,(de)          ; Get character
  1341.         inc     c               ; Test wildcard allowed
  1342.         dec     c
  1343.         jr      z,l046b         ; Nope
  1344.         cp      '?'             ; Test single wildcard
  1345.         jr      z,l0470         ; Save it
  1346.         cp      '*'             ; Test multiple wildcards
  1347.         jr      z,l0476         ; Map them
  1348. l046b:
  1349.         call    l0482           ; Test delimiter
  1350.         jr      z,l047b         ; Yeap
  1351. l0470:
  1352.         ld      (hl),a          ; Store character
  1353.         inc     hl
  1354.         inc     de
  1355.         djnz    l045e
  1356.         ret
  1357. l0476:
  1358.         inc     de
  1359. ;
  1360. ; Set B wildcards
  1361. ;
  1362. l0477:
  1363.         ld      a,'?'           ; Set wildcard character
  1364.         jr      l047d
  1365. ;
  1366. ; Blank B positions in ^HL
  1367. ;
  1368. l047b:
  1369.         ld      a,' '
  1370. l047d:
  1371.         ld      (hl),a          ; Save character
  1372.         inc     hl
  1373.         djnz    l047d
  1374.         ret
  1375. ;
  1376. ; Test delimiter
  1377. ; Z set says yes
  1378. ;
  1379. l0482:
  1380.         call    doupcase                ; Convert to upper case
  1381.         cp      ' '             ; Test control
  1382.         jr      c,l0496         ; Yeap, it's a delimiter
  1383.         push    hl
  1384.         push    bc
  1385.         ld      hl,l0498
  1386.         ld      bc,ll0498
  1387.         cpir                    ; Find in table
  1388.         pop     bc
  1389.         pop     hl
  1390.         ret
  1391. l0496:
  1392.         cp      a
  1393.         ret
  1394. ;
  1395. l0498:
  1396.         db      ' .,;:=?*[]<>{}'
  1397. ll0498  equ     $-l0498
  1398. ;
  1399. ; Convert character to UPPER case
  1400. ;
  1401. doupcase:
  1402.         cp      'a'             ; Test range
  1403.         ret     c
  1404.         cp      'z'+1
  1405.         ret     nc
  1406.         sub     'a'-'A'         ; Convert to upper case
  1407.         ret
  1408. ;
  1409. ; Print hex word in reg HL
  1410. ;
  1411. l04af:
  1412.         ld      a,h             ; Get hi
  1413.         call    l04b4           ; Print it
  1414.         ld      a,l             ; Followed by lo
  1415. ;
  1416. ; Print hex byte in Accu
  1417. ;
  1418. l04b4:
  1419.         push    af
  1420.         rra                     ; Isolate hi bits
  1421.         rra
  1422.         rra
  1423.         rra
  1424.         call    l04bd           ; Convert them
  1425.         pop     af
  1426. l04bd:
  1427.         and     LoMask          ; Mak bits
  1428.         add     a,090h          ; Dirty trick
  1429.         daa
  1430.         adc     a,040h
  1431.         daa
  1432.         jp      puttoconsole_a          ; Put to console
  1433. ;
  1434. ; Get byte from 16 bit
  1435. ; ENTRY Reg HL holds 16 bit signed integer
  1436. ; EXIT  Accu holds 0 and carry set if HL<0
  1437. ;       Accu holds -1 and carry reset if HL>256
  1438. ;       Accu holds low part and carry reset else
  1439. ;
  1440. l04c8:
  1441.         xor     a
  1442.         scf
  1443.         bit     7,h             ; Test sign bit
  1444.         ret     nz              ; Return 0 and C set if HL<0
  1445.         ld      a,h
  1446.         or      a
  1447.         ld      a,l
  1448.         ret     z               ; Return LO if HI=0
  1449.         ld      a,-1            ; Else return -1
  1450.         ret
  1451. ;
  1452. ; Test enough space
  1453. ; ENTRY Reg HL holds 1st free address
  1454. ;       Reg DE holds last free address
  1455. ;       Reg BC holds top of ram
  1456. ;       Accu holds run mode
  1457. ;
  1458. l04d4:
  1459.         ld      (l00d8),a       ; Re/Set runmode (0 is TP menue)
  1460.         push    bc
  1461.         call    l1eaf           ; Init heap
  1462.         pop     bc
  1463.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  1464.         or      a
  1465.         sbc     hl,bc           ; Test memory available
  1466.         jp      c,l20a8         ; Nope, exit
  1467.         ex      de,hl
  1468.         pop     de              ; Get caller
  1469.         ld      sp,hl           ; Set new stack
  1470.         ld      bc,-StkSpc
  1471.         add     hl,bc           ; Allow some stack space
  1472.         ld      (l00c6),hl      ; Set recursion pointer
  1473.         xor     a
  1474.         ld      l,a
  1475.         ld      h,a
  1476.         ld      (l00ce),hl      ; Reset current PC
  1477.         ld      (l00dc),a       ; Reset overlay drive
  1478.         ld      a,_JP
  1479.         ld      (l00d9),a       ; Init restart
  1480.         ld      hl,l20de
  1481.         ld      (l00da),hl      ; Set error vector
  1482.         ex      de,hl
  1483.         ld      (l00cc),hl      ; Set base PC
  1484.         jp      (hl)            ; Jump back to caller
  1485. ;
  1486. ; Start of recursive procedure or function
  1487. ; ENTRY Reg BC holds bytes to be preserved
  1488. ;       Reg HL holds address of save area
  1489. ;
  1490. l0508:
  1491.         push    hl
  1492.         ld      hl,(l00c6)      ; Get recursion pointer
  1493.         or      a
  1494.         sbc     hl,bc           ; Calculate new pointer
  1495.         ld      (l00c6),hl
  1496.         ld      de,(l00c4)      ; Get heap pointer
  1497.         or      a
  1498.         sbc     hl,de           ; Test against it
  1499.         add     hl,de
  1500.         ex      de,hl
  1501.         pop     hl
  1502.         jp      c,l1d75         ; Error if overlapping
  1503.         ldir
  1504.         ret
  1505. ;
  1506. ; End of recursive procedure or function
  1507. ; ENTRY Reg BC holds bytes to be preserved
  1508. ;       Reg DE holds address of save area
  1509. ;
  1510. l0522:
  1511.         ld      hl,(l00c6)      ; Get recursion pointer
  1512.         ldir                    ; Reload code
  1513.         ld      (l00c6),hl      ; Update pointer
  1514.         exx
  1515.         ret
  1516. ;
  1517. ; Load real into registers
  1518. ; ENTRY Reg HL points to real variable
  1519. ; EXIT  Regs HL,DE,BC hold number
  1520. ;
  1521. l052c:
  1522.         ld      e,(hl)          ; Get exponent
  1523.         inc     hl
  1524.         ld      d,(hl)          ; Get LSB
  1525.         inc     hl
  1526.         push    de
  1527.         ld      e,(hl)          ; Get 4th mantissa byte
  1528.         inc     hl
  1529.         ld      d,(hl)          ; Get 3rd mantissa byte
  1530.         inc     hl
  1531.         ld      c,(hl)          ; Get 2nd mantissa byte
  1532.         inc     hl
  1533.         ld      b,(hl)          ; Get MSB
  1534.         pop     hl
  1535.         ret
  1536. ;
  1537. ; move string to stack
  1538. ; ENTRY Reg HL points to string
  1539. ;
  1540. l053a:
  1541.         pop     ix              ; Get caller
  1542.         ex      de,hl
  1543.         ld      a,(de)          ; Get length of string
  1544.         ld      c,a
  1545.         ld      b,0
  1546.         cpl                     ; Negate
  1547.         ld      l,a
  1548.         ld      h,-1
  1549.         add     hl,sp           ; Fix stack
  1550.         ld      sp,hl
  1551.         ex      de,hl
  1552.         inc     bc
  1553.         ldir                    ; move to stack
  1554.         jp      (ix)            ; Exit
  1555. ;
  1556. ; move immediate string to stack
  1557. ; ENTRY String started with length after caller
  1558. ;
  1559. l054d:
  1560.         pop     de              ; Get string pointer
  1561.         ld      a,(de)          ; Get length
  1562.         ld      c,a
  1563.         ld      b,0             ; Expand for 16 bit
  1564.         cpl                     ; Negate
  1565.         ld      l,a
  1566.         ld      h,-1
  1567.         add     hl,sp           ; Fix stack
  1568.         ld      sp,hl
  1569.         ex      de,hl
  1570.         inc     bc
  1571.         ldir                    ; move to stack
  1572.         jp      (hl)
  1573. ;
  1574. ; Push set onto stack
  1575. ; ENTRY Reg HL points to set variable
  1576. ;       Reg C holds set length in bits
  1577. ;       Reg B holds set to be cleared
  1578. ;
  1579. l055d:
  1580.         pop     ix              ; Get caller
  1581.         ex      de,hl
  1582.         ld      hl,-set.len
  1583.         add     hl,sp           ; Adjust stack for max set length
  1584.         ld      sp,hl
  1585.         ex      de,hl
  1586.         push    bc
  1587.         inc     b               ; Test bits to clear
  1588.         dec     b
  1589.         jr      z,l0570         ; Nope
  1590.         xor     a
  1591. l056c:
  1592.         ld      (de),a          ; Clear a part
  1593.         inc     de
  1594.         djnz    l056c
  1595. l0570:
  1596.         ldir                    ; Save set on stack
  1597.         pop     bc
  1598.         ld      a,set.len
  1599.         sub     b
  1600.         sub     c               ; Test remaining bits to clear
  1601.         jr      z,l057f         ; Nope
  1602.         ld      b,a
  1603.         xor     a
  1604. l057b:
  1605.         ld      (de),a          ; Clear bits
  1606.         inc     de
  1607.         djnz    l057b
  1608. l057f:
  1609.         jp      (ix)
  1610. ;
  1611. ; Initialize a set on stack
  1612. ;
  1613. l0581:
  1614.         pop     ix              ; Get caller
  1615.         ld      hl,-set.len
  1616.         add     hl,sp           ; Fix stack
  1617.         ld      sp,hl
  1618.         ld      b,set.len       ; Set count
  1619.         xor     a
  1620. l058b:
  1621.         ld      (hl),a          ; Init set
  1622.         inc     hl
  1623.         djnz    l058b
  1624.         jp      (ix)
  1625. ;
  1626. ; Init one set element
  1627. ; ENTRY Reg HL holds set value to be set
  1628. ;
  1629. l0591:
  1630.         pop     ix
  1631.         ld      b,l             ; Get value
  1632.         call    l05ba           ; Get bit
  1633. l0597:
  1634.         or      (hl)            ; Insert it
  1635.         ld      (hl),a
  1636. l0599:
  1637.         jp      (ix)
  1638. ;
  1639. ; Init a contiguous set value
  1640. ; ENTRY Reg HL holds upper limit
  1641. ;       On stack pushed lower limit
  1642. ;
  1643. l059b:
  1644.         pop     ix
  1645.         pop     de              ; Get lower limit
  1646.         ld      a,l
  1647.         sub     e
  1648.         jr      c,l0599         ; Out of range
  1649.         inc     a
  1650.         ld      c,a
  1651.         ld      b,e             ; Get low value
  1652.         call    l05ba           ; Get bit
  1653.         ld      e,a
  1654.         ld      b,c             ; Copy loop value
  1655.         xor     a
  1656. l05ab:
  1657.         or      e
  1658.         sla     e               ; Shift bit
  1659.         jr      nc,l05b6
  1660.         or      (hl)            ; Insert
  1661.         ld      (hl),a
  1662.         inc     hl              ; Point to next
  1663.         xor     a
  1664.         ld      e,1             ; Init low bit for next
  1665. l05b6:
  1666.         djnz    l05ab
  1667.         jr      l0597           ; Set final one
  1668. ;
  1669. ; Access one set bit
  1670. ; ENTRY Reg B holds numeric value of set element
  1671. ; EXIT  Accu holds bit
  1672. ;       Reg HL points to set loacation
  1673. ;
  1674. l05ba:
  1675.         ld      a,b             ; Get value
  1676.         and     11111000b       ; Mask it
  1677.         rrca                    ; Divide by eight
  1678.         rrca
  1679.         rrca
  1680.         add     a,2             ; Fix position for stack
  1681.         ld      l,a
  1682.         ld      h,0
  1683.         add     hl,sp           ; Get position
  1684.         ld      a,b
  1685.         and     00000111b       ; Mask bits
  1686.         inc     a
  1687.         ld      b,a
  1688.         xor     a
  1689.         scf                     ; Init 1
  1690. l05cd:
  1691.         rla                     ; Shift bit into correct position
  1692.         djnz    l05cd
  1693.         ret
  1694. ;
  1695. ; Save real number
  1696. ; ENTRY Reg HL points to real variable
  1697. ;       Alternative regs HL,DE,BC hold number
  1698. ;
  1699. l05d1:
  1700.         push    hl              ; Save pointer
  1701.         exx
  1702.         ex      de,hl
  1703.         ex      (sp),hl         ; Get back pointer
  1704.         ld      (hl),e          ; Save exponent
  1705.         inc     hl
  1706.         ld      (hl),d          ; Save LSB
  1707.         inc     hl
  1708.         pop     de
  1709.         ld      (hl),e          ; Save 4th mantissa byte
  1710.         inc     hl
  1711.         ld      (hl),d          ; Save 3rd byte
  1712.         inc     hl
  1713.         ld      (hl),c          ; Save 2nd byte
  1714.         inc     hl
  1715.         ld      (hl),b          ; Save MSB
  1716.         ret
  1717. ;
  1718. ; Assign string from stack
  1719. ; ENTRY Reg HL points to string to be assigned
  1720. ;       Reg B holds max length of this string
  1721. ;
  1722. l05e2:
  1723.         pop     ix              ; Get caller
  1724.         ld      a,b             ; Get max
  1725.         ex      de,hl           ; Swap pointer
  1726.         ld      hl,0
  1727.         ld      b,h
  1728.         add     hl,sp           ; Fix stack for start of string
  1729.         ld      c,(hl)          ; Get this length
  1730.         push    hl
  1731.         add     hl,bc           ; Calculate new stack
  1732. l05ee:
  1733.         inc     hl
  1734.         ex      (sp),hl
  1735.         cp      c               ; Test length
  1736.         jr      c,l05f4
  1737.         ld      a,c             ; Get smaller one
  1738. l05f4:
  1739.         ld      (de),a          ; Unpack length
  1740.         inc     de
  1741.         inc     hl
  1742.         or      a               ; Test any character
  1743.         jr      z,l05fd         ; Nope
  1744.         ld      c,a
  1745.         ldir                    ; Unpack if so
  1746. l05fd:
  1747.         pop     hl
  1748.         ld      sp,hl
  1749.         jp      (ix)
  1750. ;
  1751. ; Assign string from stack
  1752. ; ENTRY Reg B holds max length of string
  1753. ;
  1754. l0601:
  1755.         pop     ix              ; Get caller
  1756.         ld      a,b             ; Get max
  1757.         ld      hl,0
  1758.         ld      b,h
  1759.         add     hl,sp           ; Fix stack for start of string
  1760.         ld      c,(hl)          ; Get this length
  1761.         push    hl
  1762.         add     hl,bc           ; Calculate new stack
  1763.         inc     hl
  1764.         ld      e,(hl)          ; Fetch address of string
  1765.         inc     hl
  1766.         ld      d,(hl)
  1767.         jr      l05ee           ; Unpack it
  1768. ;
  1769. ; Assign set variable
  1770. ; ENTRY Reg HL points to variable
  1771. ;       Reg BC holds length of set
  1772. ;
  1773. l0612:
  1774.         pop     ix              ; Get caller
  1775.         ex      de,hl
  1776.         ld      l,b             ; Copy length
  1777.         ld      h,0
  1778.         ld      b,h
  1779.         add     hl,sp           ; Point to start location
  1780.         ldir                    ; Unpack set variable
  1781.         ld      hl,set.len
  1782. l061f:
  1783.         add     hl,sp           ; Fix stack
  1784.         ld      sp,hl
  1785.         jp      (ix)            ; Exit
  1786. ;
  1787. ; Assign set variable
  1788. ; ENTRY Reg BC holds length of set
  1789. ;
  1790. l0623:
  1791.         pop     ix              ; Get caller
  1792.         ld      hl,set.len
  1793.         add     hl,sp           ; Point to destination
  1794.         ld      e,(hl)          ; Get it
  1795.         inc     hl
  1796.         ld      d,(hl)
  1797.         ld      l,b             ; Copy length
  1798.         ld      h,0
  1799.         ld      b,h
  1800.         add     hl,sp           ; Point to start location
  1801.         ldir
  1802.         ld      hl,set.len+2    ; Remember address
  1803.         jr      l061f           ; Fix stack
  1804. ;
  1805. ; Set set to stack
  1806. ; ENTRY Reg HL holds address of set
  1807. ;       Reg B  holds length of set
  1808. ;
  1809. l0638:
  1810.         pop     ix              ; Get caller
  1811.         ex      de,hl           ; Swap source
  1812.         ld      a,b
  1813.         cpl
  1814.         ld      l,a
  1815.         ld      h,-1            ; Get -length
  1816.         add     hl,sp           ; Fix stack
  1817.         ld      sp,hl           ; Set new
  1818.         ld      (hl),b          ; Set length
  1819.         inc     hl
  1820.         ld      c,b             ; Expand length
  1821.         ld      b,0
  1822.         ex      de,hl           ; Get back source
  1823.         ldir                    ; move to stack
  1824.         jp      (ix)
  1825. ;
  1826. ; Index check on compiler directive {$R+}
  1827. ; ENTRY Reg HL holds current index
  1828. ;       Reg DE holds max index
  1829. ;
  1830. l064c:
  1831.         or      a
  1832.         sbc     hl,de           ; Verify limit ok
  1833.         add     hl,de
  1834.         ret     c               ; Yeap
  1835.         ld      a,_IndxErr
  1836.         jp      l2027           ; Else process error
  1837. ;
  1838. ; Range check on compiler directive {$R+}
  1839. ; ENTRY Reg HL holds actual value
  1840. ;       Reg DE holds low limit
  1841. ;       Reg BC holds range of value
  1842. ;
  1843. l0656:
  1844.         or      a
  1845.         sbc     hl,de
  1846.         or      a
  1847.         sbc     hl,bc           ; Test max
  1848.         jr      nc,l0661        ; Error
  1849.         add     hl,bc           ; Restore value
  1850.         add     hl,de
  1851.         ret
  1852. l0661:
  1853.         ld      a,_RngErr
  1854.         jp      l2027           ; Set error
  1855. ;
  1856. ; Set up FOR .. TO loop
  1857. ; ENTRY Reg DE holds start value
  1858. ;       Reg HL holds end value
  1859. ; EXIT  Reg DE holds loops
  1860. ;       Reg HL holds start value
  1861. ;
  1862. l0666:
  1863.         or      a
  1864.         sbc     hl,de           ; Get difference
  1865.         ex      de,hl           ; Into reg DE
  1866. l066a:
  1867.         inc     de              ; Fix loop count
  1868.         jp      pe,l0671        ; Check any loop
  1869.         ret     p
  1870.         jr      l0672
  1871. l0671:
  1872.         ret     m
  1873. l0672:
  1874.         ld      de,0            ; Set no loop
  1875.         ret
  1876. ;
  1877. ; Set up FOR .. DOWNTO loop
  1878. ; ENTRY Reg DE holds start value
  1879. ;       Reg HL holds end value
  1880. ; EXIT  Reg DE holds loops
  1881. ;       Reg HL holds start value
  1882. ;
  1883. l0676:
  1884.         push    de
  1885.         ex      de,hl
  1886.         or      a
  1887.         sbc     hl,de           ; Get difference
  1888.         ex      de,hl
  1889.         pop     hl
  1890.         jr      l066a           ; Build loop
  1891. ;
  1892. ; ################## The comparison package ###################
  1893. ; # TRUE set (=1 on TURBO) if relation matches                #
  1894. ; #                                                           #
  1895. ; # On all relational functions the assignment is as follows: #
  1896. ; #                                                           #
  1897. ; # INTEGER : DE:HL                                           #
  1898. ; # REAL    : (Regs):(Regs)'                                  #
  1899. ; # STRING  : (Stack):(next_stack)                            #
  1900. ; #                                                           #
  1901. ; #############################################################
  1902. ;
  1903. ; ********************************
  1904. ; ********** Relation = **********
  1905. ; ********************************
  1906. ;
  1907. ; %%%%%%%%%%%%%
  1908. ; %% INTEGER %%
  1909. ; %%%%%%%%%%%%%
  1910. ;
  1911. l067f:
  1912.         or      a
  1913.         sbc     hl,de           ; Get difference
  1914. l0682:
  1915.         ld      hl,_TRUE        ; Init TRUE
  1916.         ret     z               ; Ok, same
  1917.         dec     hl              ; Fix for FALSE
  1918.         ret
  1919. ;
  1920. ; %%%%%%%%%%
  1921. ; %% REAL %%
  1922. ; %%%%%%%%%%
  1923. ;
  1924. l0688:
  1925.         call    l0bdf           ; Compare
  1926.         jr      l0682           ; Set result
  1927. ;
  1928. ; %%%%%%%%%%%%
  1929. ; %% STRING %%
  1930. ; %%%%%%%%%%%%
  1931. ;
  1932. l068d:
  1933.         call    l09b0           ; Compare
  1934.         jr      l0682           ; Set result
  1935. ;
  1936. ; *********************************
  1937. ; ********** Relation <> **********
  1938. ; *********************************
  1939. ;
  1940. ; %%%%%%%%%%%%%
  1941. ; %% INTEGER %%
  1942. ; %%%%%%%%%%%%%
  1943. ;
  1944. l0692:
  1945.         or      a
  1946.         sbc     hl,de           ; Get difference
  1947. l0695:
  1948.         ld      hl,_TRUE        ; Init TRUE
  1949.         ret     nz              ; Ok, not same
  1950.         dec     hl              ; Fix for FALSE
  1951.         ret
  1952. ;
  1953. ; %%%%%%%%%%
  1954. ; %% REAL %%
  1955. ; %%%%%%%%%%
  1956. ;
  1957. l069b:
  1958.         call    l0bdf           ; Compare
  1959.         jr      l0695           ; Set result
  1960. ;
  1961. ; %%%%%%%%%%%%
  1962. ; %% STRING %%
  1963. ; %%%%%%%%%%%%
  1964. ;
  1965. l06a0:
  1966.         call    l09b0           ; Compare
  1967.         jr      l0695           ; Set result
  1968. ;
  1969. ; *********************************
  1970. ; ********** Relation >= **********
  1971. ; *********************************
  1972. ;
  1973. ; %%%%%%%%%%%%%
  1974. ; %% INTEGER %%
  1975. ; %%%%%%%%%%%%%
  1976. ;
  1977. l06a5:
  1978.         call    l0772           ; Check operands
  1979. l06a8:
  1980.         ld      hl,_TRUE        ; Init TRUE
  1981.         ret     nc              ; Ok if .GTE.
  1982.         dec     hl              ; Else fix for FALSE
  1983.         ret
  1984. ;
  1985. ; %%%%%%%%%%
  1986. ; %% REAL %%
  1987. ; %%%%%%%%%%
  1988. ;
  1989. l06ae:
  1990.         call    l0bdf           ; Compare
  1991.         jr      l06a8           ; Set result
  1992. ;
  1993. ; %%%%%%%%%%%%
  1994. ; %% STRING %%
  1995. ; %%%%%%%%%%%%
  1996. ;
  1997. l06b3:
  1998.         call    l09b0           ; Compare
  1999.         jr      l06a8           ; Set result
  2000. ;
  2001. ; *********************************
  2002. ; ********** Relation <= **********
  2003. ; *********************************
  2004. ;
  2005. ; %%%%%%%%%%%%%
  2006. ; %% INTEGER %%
  2007. ; %%%%%%%%%%%%%
  2008. ;
  2009. l06b8:
  2010.         call    l0772           ; Check operands
  2011. l06bb:
  2012.         ld      hl,_TRUE        ; Init TRUE
  2013.         ret     z               ; Ok if .EQ.
  2014.         ret     c               ; Ok if .LT.
  2015.         dec     hl              ; Else fix for FALSE
  2016.         ret
  2017. ;
  2018. ; %%%%%%%%%%
  2019. ; %% REAL %%
  2020. ; %%%%%%%%%%
  2021. ;
  2022. l06c2:
  2023.         call    l0bdf           ; Compare
  2024.         jr      l06bb           ; Set result
  2025. ;
  2026. ; %%%%%%%%%%%%
  2027. ; %% STRING %%
  2028. ; %%%%%%%%%%%%
  2029. ;
  2030. l06c7:
  2031.         call    l09b0           ; Compare
  2032.         jr      l06bb           ; Set result
  2033. ;
  2034. ; ********************************
  2035. ; ********** Relation > **********
  2036. ; ********************************
  2037. ;
  2038. ; %%%%%%%%%%%%%
  2039. ; %% INTEGER %%
  2040. ; %%%%%%%%%%%%%
  2041. ;
  2042. l06cc:
  2043.         call    l0772           ; Check operands
  2044. l06cf:
  2045.         ld      hl,FALSE        ; Init FALSE
  2046.         ret     z               ; Ok if .EQ.
  2047.         ret     c               ; Ok if .LT.
  2048.         inc     hl              ; Else fix for TRUE
  2049.         ret
  2050. ;
  2051. ; %%%%%%%%%%
  2052. ; %% REAL %%
  2053. ; %%%%%%%%%%
  2054. ;
  2055. l06d6:
  2056.         call    l0bdf           ; Compare
  2057.         jr      l06cf           ; Set result
  2058. ;
  2059. ; %%%%%%%%%%%%
  2060. ; %% STRING %%
  2061. ; %%%%%%%%%%%%
  2062. ;
  2063. l06db:
  2064.         call    l09b0           ; Compare
  2065.         jr      l06cf           ; Set result
  2066. ;
  2067. ; ********************************
  2068. ; ********** Relation < **********
  2069. ; ********************************
  2070. ;
  2071. ; %%%%%%%%%%%%%
  2072. ; %% INTEGER %%
  2073. ; %%%%%%%%%%%%%
  2074. ;
  2075. l06e0:
  2076.         call    l0772           ; Check operands
  2077. l06e3:
  2078.         ld      hl,_TRUE        ; Init TRUE
  2079.         ret     c               ; Ok if .LT.
  2080.         dec     hl              ; Else fix for FALSE
  2081.         ret
  2082. ;
  2083. ; %%%%%%%%%%
  2084. ; %% REAL %%
  2085. ; %%%%%%%%%%
  2086. ;
  2087. l06e9:
  2088.         call    l0bdf           ; Compare
  2089.         jr      l06e3           ; Set result
  2090. ;
  2091. ; %%%%%%%%%%%%
  2092. ; %% STRING %%
  2093. ; %%%%%%%%%%%%
  2094. ;
  2095. l06ee:
  2096.         call    l09b0           ; Compare
  2097.         jr      l06e3           ; Set result
  2098. ;
  2099. ; ################# End of comparison package #################
  2100. ;
  2101. ; Function SQR(integer):integer;
  2102. ; ENTRY Reg HL holds number
  2103. ; EXIT  Reg HL holds power
  2104. ;
  2105. l06f3:
  2106.         ld      d,h             ; Copy number
  2107.         ld      e,l
  2108. ;
  2109. ; Operator *
  2110. ; Multiply signed integers
  2111. ; ENTRY Reg DE holds multiplicand
  2112. ;       Reg HL holds multiplier
  2113. ; EXIT  Reg HL holds product
  2114. ;
  2115. l06f5:
  2116.         ld      c,e             ; Copy multiplicand
  2117.         ld      b,d
  2118.         ex      de,hl
  2119.         ld      hl,0            ; Init product
  2120.         ld      a,d
  2121.         or      a               ; Test word
  2122.         ld      a,16
  2123.         jr      nz,l0704        ; Yeap, set bit count
  2124.         ld      d,e
  2125.         ld      a,8             ; Change bit count
  2126. l0704:
  2127.         add     hl,hl           ; Do the multiplication
  2128.         ex      de,hl
  2129.         add     hl,hl
  2130.         ex      de,hl
  2131.         jr      nc,l070b
  2132.         add     hl,bc
  2133. l070b:
  2134.         dec     a
  2135.         jr      nz,l0704
  2136.         ret
  2137. ;
  2138. ; Operator DIV
  2139. ; Divide signed integers
  2140. ; ENTRY Reg DE holds dividend
  2141. ;       Reg HL holds divisor
  2142. ; EXIT  Reg HL holds quotient
  2143. ;       Reg DE holds remainder
  2144. ;
  2145. l070f:
  2146.         ld      a,h             ; Test zero divisor
  2147.         or      l
  2148.         jp      z,l0a03         ; Divide by zero
  2149.         ld      a,h
  2150.         xor     d               ; Calculate sign
  2151.         push    af
  2152.         call    l0780           ; Make both numbers positive
  2153.         ex      de,hl
  2154.         call    l0780
  2155.         ex      de,hl
  2156.         ld      b,h             ; Copy divisor
  2157.         ld      c,l
  2158.         xor     a
  2159.         ld      h,a             ; Clear result
  2160.         ld      l,a
  2161.         ld      a,17            ; Set bit count
  2162. l0726:
  2163.         adc     hl,hl           ; Perform division
  2164.         sbc     hl,bc
  2165.         jr      nc,l072e
  2166.         add     hl,bc
  2167.         scf
  2168. l072e:
  2169.         ccf
  2170.         rl      e
  2171.         rl      d
  2172.         dec     a               ; Test done
  2173.         jr      nz,l0726        ; Nope, loop on
  2174.         ex      de,hl
  2175.         pop     af              ; Get resulting sign
  2176.         ret     p
  2177.         jr      l0783           ; Negate result
  2178. ;
  2179. ; Function RANDOM(integer):integer
  2180. ; ENTRY Reg HL holds integer limit
  2181. ; EXIT  Reg HL holds random
  2182. ;
  2183. l073b:
  2184.         push    hl
  2185.         call    l0792           ; Get random value
  2186.         srl     h               ; Make positive, dividing by 2
  2187.         rr      l
  2188.         pop     de
  2189.         ex      de,hl
  2190. ;
  2191. ; Operator MOD
  2192. ; Get modulo of signed integers
  2193. ; ENTRY Reg DE holds dividend
  2194. ;       Reg HL holds divisor
  2195. ; EXIT  Reg HL holds remainder
  2196. ;
  2197. l0745:
  2198.         call    l070f           ; HL:=DE DIV HL;DE:=DE MOD HL
  2199.         ex      de,hl           ; Swap remainder
  2200.         bit     7,d             ; Test result
  2201.         ret     z
  2202.         jr      l0783           ; Negate
  2203. ;
  2204. ; Operator SHL
  2205. ; Shift left number
  2206. ; ENTRY Reg DE holds number to be shifted
  2207. ;       Reg HL holds shift count
  2208. ; EXIT  Reg HL holds result
  2209. ;
  2210. l074e:
  2211.         call    l0761           ; Get shift values
  2212.         ret     z               ; End on zero
  2213. l0752:
  2214.         add     hl,hl           ; Shift
  2215.         djnz    l0752
  2216.         ret
  2217. ;
  2218. ; Operator SHR
  2219. ; Shift right number
  2220. ; ENTRY Reg DE holds number to be shifted
  2221. ;       Reg HL holds shift count
  2222. ; EXIT  Reg HL holds result
  2223. ;
  2224. l0756:
  2225.         call    l0761           ; Get shift values
  2226.         ret     z               ; End on zero
  2227. l075a:
  2228.         srl     h               ; Shift
  2229.         rr      l
  2230.         djnz    l075a
  2231.         ret
  2232. ;
  2233. ; Set shift values
  2234. ; ENTRY Reg HL holds number to be shifted
  2235. ;       Reg DE holds shift count
  2236. ; EXIT  Reg B holds shift count
  2237. ;       Zero flag set on nothing to be shifted
  2238. ;       Reg HL may be preset to zero
  2239. ;
  2240. l0761:
  2241.         ex      de,hl           ; Swap factor
  2242.         ld      a,d             ; Test hi zero value
  2243.         or      a
  2244.         jr      nz,l076e        ; Nope, should be
  2245.         ld      a,e
  2246.         cp      16              ; Test max length
  2247.         jr      nc,l076e        ; Overflow
  2248.         ld      b,a
  2249.         or      a
  2250.         ret
  2251. l076e:
  2252.         xor     a
  2253.         ld      h,a             ; Clear result
  2254.         ld      l,a
  2255.         ret
  2256. ;
  2257. ; Compare signed integers
  2258. ; ENTRY Reg DE holds 1st number
  2259. ;       Reg HL holds 2nd number
  2260. ; EXIT  Zero  flag set if DE=HL
  2261. ;       Carry flag set if DE<HL
  2262. ;
  2263. l0772:
  2264.         ex      de,hl
  2265.         ld      a,h
  2266.         xor     d               ; Test same signs
  2267.         ld      a,h
  2268.         jp      m,l077e         ; Nope, fix carry
  2269.         cp      d               ; Compare hi
  2270.         ret     nz
  2271.         ld      a,l
  2272.         cp      e               ; Compare lo if hi is same
  2273.         ret
  2274. l077e:
  2275.         rla                     ; Get sign of first number
  2276.         ret
  2277. ;
  2278. ; Function ABS(integer):integer;
  2279. ; ENTRY Reg HL holds signed integer
  2280. ; EXIT  Reg HL holds positive integer
  2281. ;
  2282. l0780:
  2283.         bit     _MB,h           ; Test sign
  2284.         ret     z               ; Already positive
  2285. l0783:
  2286.         ld      a,h             ; Build one's complement
  2287.         cpl
  2288.         ld      h,a
  2289.         ld      a,l
  2290.         cpl
  2291.         ld      l,a
  2292.         inc     hl              ; Fix for two's complement
  2293.         ret
  2294. ;
  2295. ; Function ODD(integer):boolean
  2296. ;
  2297. l078b:
  2298.         ld      a,l             ; Get lo byte
  2299.         and     LSB             ; Extract bit
  2300.         ld      l,a             ; Expand to 16 bit
  2301.         ld      h,0
  2302.         ret
  2303. ;
  2304. ; Get random value
  2305. ; EXIT  Regs BC and HL hold byte 3 and 4 of resulting random
  2306. ;       Reg  DE holds middle part of real number
  2307. ;
  2308. l0792:
  2309.         ld      bc,(l00c8+2) ;ok ;FIXME         ; Load old values
  2310.         ld      de,(l00c8) ;ok ;FIXME
  2311.         push    bc              ; Save them
  2312.         push    de
  2313.         ld      a,b             ; Expand to 40 bits
  2314.         ld      b,c
  2315.         ld      c,d
  2316.         ld      d,e
  2317.         ld      e,0
  2318.         rra                     ; Shift them all
  2319.         rr      b
  2320.         rr      c
  2321.         rr      d
  2322.         rr      e
  2323.         pop     hl
  2324.         add     hl,de           ; Add to old
  2325.         ex      de,hl
  2326.         pop     hl
  2327.         adc     hl,bc
  2328.         ld      b,h
  2329.         ld      c,l
  2330.         ld      hl,0110001011101001b
  2331.         add     hl,de           ; Fix them - add 62E9H
  2332.         ld      (l00c8),hl ;ok ;FIXME   ; Save new values
  2333.         ex      de,hl
  2334.         ld      hl,0011011000011001b
  2335.         adc     hl,bc           ; Add 3619H
  2336.         ld      (l00c8+2),hl ;ok ;FIXME
  2337.         ld      b,h             ; Copy result
  2338.         ld      c,l
  2339.         ret
  2340. ;
  2341. ; Convert positive integer to ASCII number
  2342. ; ENTRY Reg IX points to ASCII buffer
  2343. ;       Reg HL holds integer
  2344. ; EXIT  Buffer filled
  2345. ;
  2346. l07c6:
  2347.         ld      b,0             ; Init flag
  2348.         ld      de,10000
  2349.         call    l07e2           ; Start with 10000s
  2350.         ld      de,1000
  2351.         call    l07e2           ; Then 1000s
  2352.         ld      de,100
  2353.         call    l07e2           ; Then 100s
  2354.         ld      e,10
  2355.         call    l07e2           ; Then 10s
  2356.         ld      a,l             ; Get remainder
  2357.         jr      l07ef
  2358. l07e2:
  2359.         xor     a               ; Clear quotient
  2360. l07e3:
  2361.         inc     a               ; Advance quotient
  2362.         sbc     hl,de           ; Divide
  2363.         jr      nc,l07e3        ; Still positive
  2364.         add     hl,de           ; Fix for last number
  2365.         inc     b               ; Access flag
  2366.         dec     a               ; Test zero digit
  2367.         jr      nz,l07ef        ; Nope, so store result
  2368.         dec     b               ; Test flag
  2369.         ret     z               ; No leading zeroes
  2370. l07ef:
  2371.         add     a,'0'           ; Make ASCII
  2372.         ld      (ix+0),a        ; Save it
  2373.         inc     ix              ; Advance buffer
  2374.         ret
  2375. ;
  2376. ; Convert ASCII number to integer
  2377. ; ENTRY Reg IX points to ASCII number
  2378. ; EXIT  Reg HL holds integer
  2379. ;       Carry set on overflow
  2380. ;
  2381. cnv_int:
  2382.         ld      a,(ix+0)
  2383.         sub     '$'             ; Test hex indicator
  2384.         ld      c,a             ; Save flag
  2385.         ld      hl,0            ; Init result
  2386.         jr      nz,l0804
  2387. l0802:
  2388.         inc     ix              ; Skip indicator
  2389. l0804:
  2390.         ld      a,(ix+0)
  2391.         call    doupcase                ; Convert to upper case
  2392.         sub     '0'             ; Strip off offset
  2393.         jr      c,l0837         ; Out of range
  2394.         cp      9+1             ; Test decimal
  2395.         jr      c,l0820         ; Yeap
  2396.         inc     c               ; Test hex allowed
  2397.         dec     c
  2398.         jr      nz,l0837        ; Nope
  2399.         sub     'A'-'0'-10      ; Fix hex offset
  2400.         cp      10              ; Verify correct range
  2401.         jr      c,l0837
  2402.         cp      15+1
  2403.         jr      nc,l0837
  2404. l0820:
  2405.         ld      d,h             ; Copy current number
  2406.         ld      e,l
  2407.         add     hl,hl           ; * 2
  2408.         ret     c               ; Overflow
  2409.         add     hl,hl           ; * 4
  2410.         ret     c
  2411.         inc     c               ; Test hex
  2412.         dec     c
  2413.         jr      nz,l082c
  2414.         ld      d,h             ; Copy * 4
  2415.         ld      e,l
  2416. l082c:
  2417.         add     hl,de           ; * 5 or * 8
  2418.         ret     c
  2419.         add     hl,hl           ; * 10 or * 16
  2420.         ret     c
  2421.         ld      e,a
  2422.         ld      d,0
  2423.         add     hl,de           ; Insert new digit
  2424.         ret     c
  2425.         jr      l0802
  2426. l0837:
  2427.         ld      a,c
  2428.         or      a               ; Test hex
  2429.         ret     z               ; Yeap
  2430.         ld      a,h
  2431.         add     a,a             ; Get MSB into carry if decimal
  2432.         ret
  2433. ;
  2434. ; Add two strings
  2435. ; ENTRY Stack holds strings
  2436. ; EXIT  Stack holds combined string
  2437. ;
  2438. l083d:
  2439.         pop     ix              ; Get caller
  2440.         pop     hl
  2441.         push    hl
  2442.         ld      a,l             ; Get length of 1st
  2443.         ld      h,0
  2444.         inc     hl
  2445.         add     hl,sp           ; Point to 2nd
  2446.         ld      c,(hl)
  2447.         add     a,c             ; Add lengthes
  2448.         jr      c,l0866         ; Too long
  2449.         ld      (hl),a          ; Set new length
  2450.         ex      de,hl
  2451.         ld      hl,0
  2452.         ld      b,h
  2453.         sbc     hl,bc           ; Prepare moving strings
  2454.         add     hl,sp
  2455.         ld      sp,hl
  2456.         ex      de,hl
  2457.         push    hl
  2458.         inc     bc
  2459.         ldir                    ; move into right place
  2460.         ex      de,hl
  2461.         pop     hl
  2462.         dec     hl
  2463.         dec     de
  2464.         ld      c,a
  2465.         inc     bc
  2466.         lddr
  2467.         ex      de,hl
  2468.         inc     hl
  2469.         ld      sp,hl
  2470.         jp      (ix)
  2471. l0866:
  2472.         ld      a,_StrLenErr    ; Set error
  2473.         jp      l2029
  2474. ;
  2475. ; Function COPY(string,start,length):string
  2476. ; ENTRY Start on stack, followed by string
  2477. ;       Reg HL holds length
  2478. ; EXIT  Substring on stack
  2479. ;
  2480. l086b:
  2481.         pop     ix              ; Get caller
  2482.         call    l04c8           ; Get length byte from integer
  2483.         ld      d,a
  2484.         pop     hl              ; Get start
  2485.         call    l09dd           ; Verify 1..255
  2486.         ld      e,a
  2487.         pop     hl              ; Get length ( - and 1st character)
  2488.         push    hl
  2489.         ld      a,l
  2490.         sub     e               ; Test against start
  2491.         jr      c,l0896         ; Out of bounds
  2492.         inc     d               ; Test zero length
  2493.         dec     d
  2494.         jr      z,l0896         ; Yeap, done
  2495.         cp      d               ; Compare against length
  2496.         jr      c,l0899         ; Nothing to move
  2497.         ld      c,d             ; Fix a bit
  2498.         ld      b,0
  2499.         ld      h,b
  2500.         add     hl,sp
  2501.         ld      a,e
  2502.         add     a,d
  2503.         ld      d,h
  2504.         ld      e,l
  2505.         dec     a
  2506.         ld      l,a
  2507.         ld      h,b
  2508.         add     hl,sp
  2509.         ld      a,c
  2510.         lddr                    ; Then move down
  2511.         ex      de,hl
  2512.         jr      l089f
  2513. l0896:
  2514.         xor     a               ; Set zero length
  2515.         jr      l089c
  2516. l0899:
  2517.         inc     a               ; Fix length
  2518.         ld      l,e
  2519.         dec     l               ; Fix position
  2520. l089c:
  2521.         ld      h,0
  2522.         add     hl,sp           ; Copy position
  2523. l089f:
  2524.         ld      (hl),a          ; Store length
  2525.         ld      sp,hl           ; Get stack
  2526.         jp      (ix)            ; Exit
  2527. ;
  2528. ; Function LENGTH(string):integer
  2529. ; ENTRY String on stack
  2530. ; EXIT  Reg HL holds length
  2531. ;
  2532. l08a3:
  2533.         pop     ix              ; Get caller
  2534.         pop     hl              ; Get length ( - and 1st character)
  2535.         push    hl
  2536.         ld      a,l             ; Save length
  2537.         ld      h,0
  2538.         inc     hl
  2539.         add     hl,sp
  2540.         ld      sp,hl           ; Fix stack
  2541.         ld      l,a             ; Get 16 bit length
  2542.         ld      h,0
  2543.         jp      (ix)            ; Exit
  2544. ;
  2545. ; Function POS(substring,string):integer
  2546. ; ENTRY String on stack, followed by substring
  2547. ; EXIT  Reg HL holds position, 0 is not found
  2548. ;
  2549. l08b2:
  2550.         pop     ix              ; Get caller
  2551.         ld      hl,0
  2552.         ld      d,h
  2553.         add     hl,sp           ; Copy stack
  2554.         ld      e,(hl)          ; Get length of main_string
  2555.         ld      c,e
  2556.         inc     hl
  2557.         push    hl
  2558.         add     hl,de           ; Point to sub_string
  2559.         ld      e,(hl)          ; Get length of sub_string
  2560.         ld      b,e
  2561.         inc     hl
  2562.         push    hl
  2563.         add     hl,de           ; Point to end of both
  2564.         push    hl
  2565.         pop     iy              ; Copy address
  2566.         pop     de              ; Get sub_string
  2567.         pop     hl              ; Get main_string
  2568.         ld      a,c
  2569.         sub     b               ; Test range
  2570.         jr      c,l08dc         ; Sub_string > main_string - no match
  2571.         inc     a               ; Fix count
  2572.         ld      c,a
  2573. l08ce:
  2574.         push    bc
  2575.         push    de
  2576.         push    hl
  2577. l08d1:
  2578.         ld      a,(de)
  2579.         cp      (hl)            ; Compare
  2580.         jr      z,l08e1         ; Maybe success
  2581.         pop     hl
  2582.         pop     de
  2583.         pop     bc
  2584.         inc     hl
  2585.         dec     c               ; Test more to search
  2586.         jr      nz,l08ce        ; Ok, then try next
  2587. l08dc:
  2588.         ld      hl,0            ; Set zero result
  2589.         jr      l08ef
  2590. l08e1:
  2591.         inc     hl
  2592.         inc     de
  2593.         djnz    l08d1           ; Loop thru sub_string
  2594.         pop     de
  2595.         pop     hl
  2596.         pop     bc
  2597.         ld      hl,0
  2598.         add     hl,sp           ; Get pointers
  2599.         ex      de,hl
  2600.         sbc     hl,de           ; Calculate resulting position
  2601. l08ef:
  2602.         ld      sp,iy           ; Set stack
  2603.         jp      (ix)            ; Exit
  2604. ;
  2605. ; Procedure DELETE(string,start,length)
  2606. ; ENTRY Start on stack, followed by string
  2607. ;       Reg HL holds length
  2608. ;
  2609. l08f3:
  2610.         pop     ix              ; Get caller
  2611.         call    l04c8           ; Get length byte from integer
  2612.         ld      c,a
  2613.         pop     hl
  2614.         call    l09dd           ; Verify length in range 1..255
  2615.         ld      e,a
  2616.         pop     hl              ; Get start_string
  2617.         ld      a,(hl)          ; Get length
  2618.         sub     e               ; Test start > length
  2619.         jr      c,l091e         ; Exit if so
  2620.         inc     c
  2621.         dec     c               ; Test any length
  2622.         jr      z,l091e         ; Nope, exit
  2623.         sub     c               ; Test remaining count
  2624.         jr      c,l091c         ; Nope, done
  2625.         push    af
  2626.         ld      a,(hl)
  2627.         sub     c
  2628.         ld      (hl),a
  2629.         ld      b,0
  2630.         ld      d,b
  2631.         add     hl,de           ; Point to destination
  2632.         ld      d,h
  2633.         ld      e,l
  2634.         add     hl,bc           ; Point to source
  2635.         pop     af
  2636.         inc     a
  2637.         ld      c,a
  2638.         ldir                    ; Unpack
  2639.         jr      l091e
  2640. l091c:
  2641.         dec     e               ; Adjust length
  2642.         ld      (hl),e          ; Store it
  2643. l091e:
  2644.         jp      (ix)            ; Exit
  2645. ;
  2646. ; Procedure INSERT(string,substring,start)
  2647. ; ENTRY Pointer of substring on stack, followed by string
  2648. ;       Reg HL holds start
  2649. ;       Reg B holds max length of string
  2650. ;
  2651. l0920:
  2652.         pop     ix              ; Get caller
  2653.         call    l09dd           ; Verify start in range 1..255
  2654.         ld      c,a
  2655.         pop     de              ; Get sub_string
  2656.         ld      (l00e8),de ;ok ;FIXME
  2657.         ld      hl,0
  2658.         add     hl,sp           ; Get string pointer
  2659.         ld      a,(de)
  2660.         push    af
  2661.         add     a,(hl)          ; Get combined length
  2662.         jr      c,l0937         ; Truncate on overflow
  2663.         cp      b               ; Compare against max
  2664.         jr      c,l0938         ; Ok
  2665. l0937:
  2666.         ld      a,b             ; Set max defualt
  2667. l0938:
  2668.         ld      (de),a          ; Save combined length
  2669.         pop     af              ; Get length of substring
  2670.         ld      d,a
  2671.         ld      e,(hl)
  2672.         sub     c               ; Get remainder
  2673.         jr      c,l096e         ; Skip
  2674.         inc     a
  2675.         ld      l,a
  2676.         ld      a,d
  2677.         add     a,e
  2678.         jr      c,l0949
  2679.         cp      b
  2680.         ld      a,l
  2681.         jr      c,l0951
  2682. l0949:
  2683.         ld      a,b
  2684.         sub     e
  2685.         jr      c,l0973
  2686.         sub     c
  2687.         jr      c,l0973
  2688.         inc     a
  2689. l0951:
  2690.         or      a
  2691.         jr      z,l0973
  2692.         push    bc
  2693.         push    de
  2694.         ld      hl,(l00e8)      ;ok ;FIXME ; Get back sub_string pointer
  2695.         ld      e,a
  2696.         dec     e
  2697.         ld      d,0
  2698.         ld      b,d
  2699.         add     hl,de
  2700.         add     hl,bc
  2701.         pop     de
  2702.         push    de
  2703.         push    hl
  2704.         ld      d,b
  2705.         add     hl,de
  2706.         ex      de,hl
  2707.         pop     hl
  2708.         ld      c,a
  2709.         lddr                    ; move down
  2710.         pop     de
  2711.         pop     bc
  2712.         jr      l0973
  2713. l096e:
  2714.         ld      a,d
  2715.         inc     a
  2716.         jr      z,l098b
  2717.         ld      c,a
  2718. l0973:
  2719.         ld      a,b
  2720.         sub     c
  2721.         inc     a
  2722.         cp      e
  2723.         jr      c,l097a
  2724.         ld      a,e
  2725. l097a:
  2726.         or      a
  2727.         jr      z,l098b
  2728.         ld      hl,(l00e8)      ;ok ;FIXME ; Get sub_string pointer
  2729.         ld      b,0
  2730.         add     hl,bc
  2731.         ex      de,hl
  2732.         ld      hl,1
  2733.         add     hl,sp
  2734.         ld      c,a
  2735.         ldir                    ; move
  2736. l098b:
  2737.         ld      hl,0
  2738.         ld      d,h
  2739.         add     hl,sp           ; Fix stack
  2740.         ld      e,(hl)
  2741.         inc     de
  2742.         add     hl,de
  2743.         ld      sp,hl           ; Set stack
  2744.         jp      (ix)            ; Exit
  2745. ;
  2746. ; Check assignment of string to character
  2747. ; EXIT  Reg L holds character
  2748. ;
  2749. l0996:
  2750.         pop     ix              ; Get caller
  2751.         pop     hl              ; Get length and character
  2752.         dec     l               ; Verify character only
  2753.         jp      nz,l0866        ; Error if not
  2754.         ld      l,h             ; Unpack character
  2755.         ld      h,0
  2756.         jp      (ix)            ; Exit
  2757. ;
  2758. ; Set character into string
  2759. ;
  2760. l09a2:
  2761.         ld      hl,2
  2762.         ld      d,h
  2763.         add     hl,sp           ; Point to string
  2764.         ld      e,(hl)          ; Get length
  2765.         inc     de
  2766.         add     hl,de           ; Point to top
  2767.         ld      a,(hl)          ; Get character
  2768.         ld      (hl),1          ; Set length
  2769.         inc     hl
  2770.         ld      (hl),a          ; Store character
  2771.         ret
  2772. ;
  2773. ; Compare two strings
  2774. ; ENTRY 1st stack 1st pushed, 2nd stack 2nd pushed
  2775. ; EXIT  Carry flag set if 1st<2nd
  2776. ;       Zero  flag set if 1st=2nd
  2777. ;
  2778. l09b0:
  2779.         ld      hl,2*2          ; Note 2nd level call
  2780.         ld      d,h
  2781.         add     hl,sp           ; Point to 2nd string
  2782.         ld      e,(hl)          ; Get length
  2783.         ld      c,e
  2784.         inc     hl
  2785.         push    hl
  2786.         add     hl,de           ; Point to first string
  2787.         ld      e,(hl)          ; Get length
  2788.         ld      b,e
  2789.         inc     hl
  2790.         push    hl
  2791.         add     hl,de           ; Set return stack
  2792.         push    hl
  2793.         pop     iy              ; Copy into reg IY
  2794.         pop     de              ; Get 1st string
  2795.         pop     hl              ; Get 2nd string
  2796. l09c4:
  2797.         xor     a               ; Try zero length
  2798.         cp      b
  2799.         jr      z,l09cc
  2800.         cp      c               ; Test on both
  2801.         jr      nz,l09d3
  2802.         ld      a,b
  2803. l09cc:
  2804.         cp      c
  2805. l09cd:
  2806.         pop     hl              ; Get back callers
  2807.         pop     de
  2808.         ld      sp,iy           ; Set new stack
  2809.         push    de              ; Set 2nd kevel caller
  2810.         jp      (hl)            ; Exit
  2811. l09d3:
  2812.         ld      a,(de)
  2813.         cp      (hl)            ; Compare
  2814.         jr      nz,l09cd        ; No match
  2815.         inc     hl
  2816.         inc     de
  2817.         dec     b
  2818.         dec     c
  2819.         jr      l09c4
  2820. ;
  2821. ; Verify value in reg HL in range 1..255
  2822. ;
  2823. l09dd:
  2824.         ld      a,h             ; Verify < 256
  2825.         or      a
  2826.         jr      nz,l09e4
  2827.         ld      a,l
  2828.         or      a               ; Verify <> 0
  2829.         ret     nz
  2830. l09e4:
  2831.         ld      a,_StrIdx
  2832.         jp      l2029
  2833. ;
  2834. ; Function ADD:real
  2835. ; ENTRY Regs (HL,DE,BC)  hold 1st number
  2836. ;       Regs (HL,DE,BC)' hold 2nd number
  2837. ; EXIT  Regs (HL,DE,BC)  hold sum
  2838. ;
  2839. l09e9:
  2840.         call    l0a0d           ; Add
  2841. l09ec:
  2842.         ret     nc              ; Check result
  2843.         ld      a,_FLPovfl
  2844.         jp      l2027           ; Set error and abort
  2845. ;
  2846. ; Function SUBTRACT:real
  2847. ; ENTRY Regs (HL,DE,BC)  hold 1st number
  2848. ;       Regs (HL,DE,BC)' hold 2nd number
  2849. ; EXIT  Regs (HL,DE,BC)  hold difference
  2850. ;
  2851. l09f2:
  2852.         call    l0a81           ; Subtract
  2853.         jr      l09ec           ; Check result
  2854. ;
  2855. ; Function SQR(real):real
  2856. ; ENTRY Regs (HL,DE,BC) hold number
  2857. ; EXIT  Regs (HL,DE,BC) hold square
  2858. ;
  2859. l09f7:
  2860.         call    l0fac           ; Copy number, then multiply
  2861. ;
  2862. ; Function MULTIPLY:real
  2863. ; ENTRY Regs (HL,DE,BC)  hold multiplicand
  2864. ;       Regs (HL,DE,BC)' hold multiplier
  2865. ; EXIT  Regs (HL,DE,BC)  hold product
  2866. ;
  2867. l09fa:
  2868.         call    l0a97           ; Multiply
  2869.         jr      l09ec           ; Check result
  2870. ;
  2871. ; Function DIVIDE:real
  2872. ; ENTRY Regs (HL,DE,BC)  hold 1st dividend
  2873. ;       Regs (HL,DE,BC)' hold 2nd divisor
  2874. ; EXIT  Regs (HL,DE,BC)  hold quotient
  2875. ;
  2876. l09ff:
  2877.         exx                     ; Get divisor
  2878.         ld      a,l
  2879.         or      a               ; Verify not zero
  2880.         exx
  2881. l0a03:
  2882.         ld      a,_DivZero
  2883.         jp      z,l2027         ; Error if division by zero
  2884.         call    l0af5           ; Divide
  2885.         jr      l09ec           ; Check result
  2886. ;
  2887. ; Add reals
  2888. ; ENTRY Regs (HL,DE,BC)  hold 1st number
  2889. ;       Regs (HL,DE,BC)' hold 2nd number
  2890. ; EXIT  Regs (HL,DE,BC)  hold sum
  2891. ;       Carry set on overflow
  2892. ;
  2893. l0a0d:
  2894.         exx
  2895.         bit     sgn.bit,b       ; Test sign of 2nd number
  2896.         exx
  2897.         jp      nz,l0a88        ; Subtract if less 0
  2898. l0a14:
  2899.         exx
  2900.         ld      a,l             ; Test 2nd number zero
  2901.         or      a
  2902.         exx
  2903.         ret     z               ; Ok, result is the 1st number
  2904.         exx
  2905.         push    bc              ; Save 1st number
  2906.         push    de
  2907.         push    hl
  2908.         exx
  2909.         ld      a,l
  2910.         or      a               ; Test 1st number zero
  2911.         jr      nz,l0a27        ; Nope
  2912.         exx
  2913.         res     sgn.bit,b       ; Clear sign
  2914.         jr      l0a7b           ; Get 2nd number as result
  2915. l0a27:
  2916.         push    bc
  2917.         set     sgn.bit,b       ; Force bit set
  2918.         xor     a
  2919.         ex      af,af' ;'
  2920.         exx
  2921.         set     sgn.bit,b
  2922.         ld      a,l
  2923.         exx
  2924.         sub     l               ; Test same exponents
  2925.         jr      z,l0a47         ; Yeap
  2926.         jr      nc,l0a3c
  2927.         neg
  2928.         ex      af,af' ;'
  2929.         dec     a
  2930.         ex      af,af' ;'
  2931.         exx
  2932. l0a3c:
  2933.         call    l0b7a           ; Shift mantissa right
  2934.         inc     l               ; Bump exponent
  2935.         dec     a
  2936.         jr      nz,l0a3c
  2937.         ex      af,af' ;'
  2938.         jr      z,l0a47
  2939.         exx
  2940. l0a47:
  2941.         pop     af              ; Get back mantissa MSB
  2942.         and     sign.bit        ; Test sign
  2943.         jr      nz,l0a5b        ; It's negative
  2944.         call    l0b92           ; Add mantissas
  2945.         jr      nc,l0a76        ; Test bit out
  2946.         call    l0b7b           ; Rotate mantissa right
  2947.         or      a
  2948.         inc     l               ; Fix exponent
  2949.         jr      nz,l0a76        ; Test underflow
  2950.         scf
  2951.         jr      l0a7b
  2952. l0a5b:
  2953.         call    l0bc6           ; Compare mantissas
  2954.         ccf
  2955.         push    af
  2956.         jr      z,l0a72         ; It's same
  2957.         jr      c,l0a65         ; It's less
  2958.         exx
  2959. l0a65:
  2960.         call    l0bac           ; Subtract mantissas
  2961. l0a68:
  2962.         bit     sgn.bit,b       ; Test normalized
  2963.         jr      nz,l0a75        ; Yeap
  2964.         call    l0b86           ; Shift left
  2965.         dec     l
  2966.         jr      nz,l0a68
  2967. l0a72:
  2968.         call    l0b72           ; Zero result
  2969. l0a75:
  2970.         pop     af
  2971. l0a76:
  2972.         jr      c,l0a7a         ; Test sign
  2973.         res     sgn.bit,b       ; Reset if positive
  2974. l0a7a:
  2975.         or      a
  2976. l0a7b:
  2977.         exx
  2978.         pop     hl
  2979.         pop     de
  2980.         pop     bc
  2981.         exx
  2982.         ret
  2983. ;
  2984. ; Subtract reals
  2985. ; ENTRY Regs (HL,DE,BC)  hold 1st number
  2986. ;       Regs (HL,DE,BC)' hold 2nd number
  2987. ; EXIT  Regs (HL,DE,BC)  hold difference
  2988. ;       Carry set on overflow
  2989. ;
  2990. l0a81:
  2991.         exx
  2992.         bit     sgn.bit,b       ; Test sign of 2nd number
  2993.         exx
  2994.         jp      nz,l0a14        ; Add if less 0
  2995. l0a88:
  2996.         call    l0a8f           ; Negate
  2997.         call    l0a14           ; Then add
  2998.         ret     c
  2999. ;
  3000. ; Negate real
  3001. ; ENTRY Regs HL,DE,BC hold real number
  3002. ; EXIT  Sign changed if real > 0
  3003. ;
  3004. l0a8f:
  3005.         inc     l               ; Test exponent zero
  3006.         dec     l
  3007.         ret     z               ; Exit if so
  3008.         ld      a,b
  3009.         xor     sign.bit        ; Change sign bit
  3010.         ld      b,a
  3011.         ret
  3012. ;
  3013. ; Multiply reals
  3014. ; ENTRY Regs (HL,DE,BC)  hold multiplicand
  3015. ;       Regs (HL,DE,BC)' hold multiplier
  3016. ; EXIT  Regs (HL,DE,BC)  hold product
  3017. ;       Carry set on overflow
  3018. ;
  3019. l0a97:
  3020.         exx
  3021.         ld      a,l
  3022.         or      a               ; Test zero multiplier
  3023.         exx
  3024.         jp      z,l0b72         ; Return 0.0 if so
  3025.         ld      a,l
  3026.         or      a
  3027.         ret     z               ; Return if multiplicand zero
  3028.         exx
  3029.         add     a,l             ; Add exponents
  3030.         exx
  3031.         call    l0b4d           ; Fix exponent
  3032.         push    bc              ; Save number
  3033.         push    de
  3034.         push    hl
  3035.         add     ix,sp
  3036.         call    l0b72           ; Prepare result
  3037.         exx
  3038.         ld      l,mant.len      ; Set mantissa count
  3039.         exx
  3040. l0ab3:
  3041.         ld      a,bit.len       ; Set bit count
  3042.         inc     ix
  3043.         ld      l,(ix+0)
  3044. l0aba:
  3045.         ex      af,af' ;'
  3046.         rr      l               ; Shift bit
  3047.         jr      nc,l0ac2
  3048.         call    l0b92           ; Add mantissa if bit out
  3049. l0ac2:
  3050.         call    l0b7b           ; Rotate mantissa right
  3051.         ex      af,af' ;'
  3052.         dec     a               ; Go thru all bits
  3053.         jr      nz,l0aba
  3054.         exx
  3055.         dec     l
  3056.         exx
  3057.         jr      nz,l0ab3
  3058.         ld      l,(ix-mant.len) ; Get byte back
  3059.         bit     sgn.bit,b       ; Test sign
  3060.         jr      nz,l0ade
  3061.         ex      af,af' ;'
  3062.         call    l0b87           ; Get bit
  3063.         inc     l
  3064.         dec     l
  3065.         jr      z,l0ade
  3066.         dec     l
  3067. l0ade:
  3068.         pop     af              ; Clean stack
  3069.         pop     af
  3070.         pop     af
  3071. l0ae1:
  3072.         or      a
  3073. l0ae2:
  3074.         ex      af,af' ;'
  3075.         pop     af
  3076.         exx
  3077.         pop     bc
  3078.         pop     hl
  3079.         exx
  3080.         pop     ix
  3081.         res     sgn.bit,b       ; Reset hi bit
  3082.         or      b
  3083.         ld      b,a             ; Insert sign
  3084.         inc     l
  3085.         dec     l
  3086.         call    z,l0b72         ; Clear if underflow
  3087.         ex      af,af' ;'
  3088.         ret
  3089. ;
  3090. ; Divide reals
  3091. ; ENTRY Regs (HL,DE,BC)  hold 1st dividend
  3092. ;       Regs (HL,DE,BC)' hold 2nd divisor
  3093. ; EXIT  Regs (HL,DE,BC)  hold quotient
  3094. ;       Carry set on overflow
  3095. ;
  3096. l0af5:
  3097.         ld      a,l
  3098.         or      a               ; Test zero divisor
  3099.         ret     z
  3100.         exx
  3101.         sub     l               ; Get resulting exponent
  3102.         exx
  3103.         ccf
  3104.         call    l0b4d           ; Fix it
  3105.         push    hl
  3106.         push    hl
  3107.         push    hl
  3108.         add     ix,sp
  3109.         exx
  3110.         ld      l,mant.len      ; Get complete count
  3111.         exx
  3112.         ld      a,bit.len       ; Set bit count
  3113. l0b0a:
  3114.         ex      af,af' ;'
  3115.         call    l0bc6           ; Compare mantissas
  3116.         jr      c,l0b13
  3117.         call    l0bac           ; Subtract mantissas
  3118. l0b13:
  3119.         ccf
  3120.         rl      l
  3121.         ex      af,af' ;'
  3122.         dec     a               ; Go thru the bits
  3123.         jr      nz,l0b26
  3124.         ld      (ix+mant.len),l ; Set result
  3125.         dec     ix
  3126.         exx
  3127.         dec     l               ; Go thru the mantissa
  3128.         exx
  3129.         jr      z,l0b32         ; Total end
  3130.         ld      a,bit.len       ; Reset bit count
  3131. l0b26:
  3132.         call    l0b86           ; Shift left
  3133.         jr      nc,l0b0a
  3134.         ex      af,af' ;'
  3135.         call    l0bac           ; Subtract mantissas
  3136.         or      a
  3137.         jr      l0b13
  3138. l0b32:
  3139.         call    l0b86           ; Shift left
  3140.         jr      c,l0b3b
  3141.         call    l0bc6           ; Compare mantissas
  3142.         ccf
  3143. l0b3b:
  3144.         pop     hl
  3145.         pop     de
  3146.         pop     bc
  3147.         bit     sgn.bit,b       ; Test bit
  3148.         jr      nz,l0b47
  3149.         call    l0b87           ; Shift in
  3150.         jr      l0ae1
  3151. l0b47:
  3152.         inc     l               ; Test ok
  3153.         jr      nz,l0ae1
  3154.         scf
  3155.         jr      l0ae2
  3156. ;
  3157. ; Fix exponent
  3158. ; ENTRY Accu and Carry reflect state of addition or
  3159. ;       subtraction of exponents
  3160. ;
  3161. l0b4d:
  3162.         jr      c,l0b55         ; Test bit out
  3163.         add     a,exp.offset    ; Add offset
  3164.         jr      c,l0b59         ; Test bit
  3165.         jr      l0b70
  3166. l0b55:
  3167.         add     a,exp.offset
  3168.         jr      c,l0b70
  3169. l0b59:
  3170.         ld      l,a             ; Set new exponent
  3171.         ex      (sp),ix         ; Get caller
  3172.         exx
  3173.         push    hl
  3174.         push    bc
  3175.         ld      a,b
  3176.         set     sgn.bit,b       ; Set bit
  3177.         exx
  3178.         xor     b
  3179.         and     sign.bit        ; Get result
  3180.         push    af
  3181.         set     sgn.bit,b       ; Second, too
  3182.         push    ix              ; Bring back caller
  3183.         ld      ix,0            ; Return IX=0
  3184.         ret
  3185. l0b70:
  3186.         pop     hl
  3187.         ret     c
  3188. ;
  3189. ; Clear real number
  3190. ; EXIT  Regs (HL,DE,BC) hold zero
  3191. ;
  3192. l0b72:
  3193.         xor     a
  3194.         ld      l,a             ; Clear all involved bytes
  3195.         ld      b,a
  3196.         ld      c,a
  3197.         ld      d,a
  3198.         ld      e,a
  3199.         ld      h,a
  3200.         ret
  3201. ;
  3202. ; Shift mantissa right
  3203. ;
  3204. l0b7a:
  3205.         or      a               ; Clear carry
  3206. ;
  3207. ; Rotate mantissa right
  3208. ;
  3209. l0b7b:
  3210.         rr      b               ; Shift 5 bytes right
  3211.         rr      c
  3212.         rr      d
  3213.         rr      e
  3214.         rr      h
  3215.         ret
  3216. ;
  3217. ; Shift mantissa left
  3218. ;
  3219. l0b86:
  3220.         or      a               ; Clear carry
  3221. ;
  3222. ; Rotate mantissa left
  3223. ;
  3224. l0b87:
  3225.         rl      h               ; Shift 5 bytes left
  3226.         rl      e
  3227.         rl      d
  3228.         rl      c
  3229.         rl      b
  3230.         ret
  3231. ;
  3232. ; Add mantissas
  3233. ;
  3234. l0b92:
  3235.         ld      a,h             ; Get 1st
  3236.         exx                     ; Then second
  3237.         add     a,h             ; Add
  3238.         exx
  3239.         ld      h,a             ; Into 1st
  3240.         ld      a,e
  3241.         exx
  3242.         adc     a,e
  3243.         exx
  3244.         ld      e,a
  3245.         ld      a,d
  3246.         exx
  3247.         adc     a,d
  3248.         exx
  3249.         ld      d,a
  3250.         ld      a,c
  3251.         exx
  3252.         adc     a,c
  3253.         exx
  3254.         ld      c,a
  3255.         ld      a,b
  3256.         exx
  3257.         adc     a,b
  3258.         exx
  3259.         ld      b,a
  3260.         ret
  3261. ;
  3262. ; Subtract mantissas
  3263. ;
  3264. l0bac:
  3265.         ld      a,h             ; Get 1st
  3266.         exx                     ; Then second
  3267.         sub     h               ; Subtract
  3268.         exx
  3269.         ld      h,a             ; Into 1st
  3270.         ld      a,e
  3271.         exx
  3272.         sbc     a,e
  3273.         exx
  3274.         ld      e,a
  3275.         ld      a,d
  3276.         exx
  3277.         sbc     a,d
  3278.         exx
  3279.         ld      d,a
  3280.         ld      a,c
  3281.         exx
  3282.         sbc     a,c
  3283.         exx
  3284.         ld      c,a
  3285.         ld      a,b
  3286.         exx
  3287.         sbc     a,b
  3288.         exx
  3289.         ld      b,a
  3290.         ret
  3291. ;
  3292. ; Compare mantissas
  3293. ;
  3294. l0bc6:
  3295.         ld      a,b             ; Get 1st
  3296.         exx                     ; Then second
  3297.         cp      b               ; Compare
  3298.         exx
  3299.         ret     nz              ; Exit if .NE. zero
  3300.         ld      a,c
  3301.         exx
  3302.         cp      c
  3303.         exx
  3304.         ret     nz
  3305.         ld      a,d
  3306.         exx
  3307.         cp      d
  3308.         exx
  3309.         ret     nz
  3310.         ld      a,e
  3311.         exx
  3312.         cp      e
  3313.         exx
  3314.         ret     nz
  3315.         ld      a,h
  3316.         exx
  3317.         cp      h
  3318.         exx
  3319.         ret
  3320. ;
  3321. ; Compare two reals
  3322. ; ENTRY 1st real in register set
  3323. ;       2nd real in alternative set
  3324. ; EXIT  Carry flag set if 1st<2nd
  3325. ;       Zero  flag set if 1st=2nd
  3326. ;
  3327. l0bdf:
  3328.         exx
  3329.         ld      a,b             ; Get sign
  3330.         exx
  3331.         xor     b               ; Test same signs
  3332.         jp      p,l0be9         ; Yeap
  3333.         ld      a,b             ; Get 1st sign
  3334.         rla                     ; Calculate result
  3335.         ret
  3336. l0be9:
  3337.         bit     sgn.bit,b       ; Test 1st > 0
  3338.         jr      z,l0bf3         ; Yeap
  3339.         call    l0bf3           ; Compare
  3340.         ret     z
  3341.         ccf
  3342.         ret
  3343. l0bf3:
  3344.         ld      a,l             ; Get exponent
  3345.         exx
  3346.         cp      l               ; Compare
  3347.         exx
  3348.         ret     nz              ; Not same
  3349.         or      a               ; Test zero
  3350.         ret     z
  3351.         jp      l0bc6           ; Compare mantissas
  3352. ;
  3353. ; Function INT(real):real
  3354. ;
  3355. l0bfd:
  3356.         ld      a,l
  3357.         sub     Exp.One         ; Test >= 1
  3358.         jp      c,l0b72         ; Nope, return 0.0
  3359.         inc     a               ; Fix count
  3360.         cp      mant.bits       ; Test fraction
  3361.         ret     nc              ; No, that's it
  3362.         exx
  3363.         push    bc              ; save 2nd
  3364.         push    de
  3365.         push    hl
  3366.         ex      af,af' ;'
  3367.         call    l0b72           ; Init result
  3368.         ex      af,af' ;'
  3369. l0c10:
  3370.         scf
  3371.         call    l0b7b           ; Rotate mantissa right
  3372.         dec     a
  3373.         jr      nz,l0c10
  3374.         exx
  3375.         ld      a,h             ; Mask result
  3376.         exx
  3377.         and     h
  3378.         exx
  3379.         ld      h,a
  3380.         ld      a,e
  3381.         exx
  3382.         and     e
  3383.         exx
  3384.         ld      e,a
  3385.         ld      a,d
  3386.         exx
  3387.         and     d
  3388.         exx
  3389.         ld      d,a
  3390.         ld      a,c
  3391.         exx
  3392.         and     c
  3393.         exx
  3394.         ld      c,a
  3395.         ld      a,b
  3396.         exx
  3397.         and     b
  3398.         exx
  3399.         ld      b,a
  3400. l0c31:
  3401.         jp      l0a7b
  3402. ;
  3403. ; Function FRAC(real):real
  3404. ;
  3405. l0c34:
  3406.         exx
  3407.         push    bc
  3408.         push    de
  3409.         push    hl
  3410.         exx
  3411.         call    l0fac           ; Copy number
  3412.         exx
  3413.         call    l0bfd           ; Get integer part
  3414.         exx
  3415.         call    l0a81           ; Subtract from original number
  3416.         jr      l0c31
  3417. ;
  3418. ; Function SQRT(real):real
  3419. ;
  3420. l0c46:
  3421.         ld      a,l             ; Test zero operand
  3422.         or      a
  3423.         ret     z               ; Ok, that's it
  3424.         bit     sgn.bit,b       ; Verify operand >= 0
  3425.         ld      a,_NegSqrt
  3426.         jp      nz,l2027        ; Should be
  3427.         call    l0fac           ; Copy number
  3428.         ld      a,l
  3429.         add     a,exp.offset
  3430.         sra     a               ; Fix resulting exponent
  3431.         add     a,exp.offset
  3432.         ld      l,a
  3433.         sub     sqr.exp         ; Fix exponent
  3434.         push    af
  3435.         exx
  3436. l0c5f:
  3437.         push    bc
  3438.         push    de
  3439.         push    hl
  3440.         call    l0af5           ; Divide reals
  3441.         call    l0a0d           ; Add reals
  3442.         dec     l               ; Exponent - 1
  3443.         push    bc
  3444.         push    de
  3445.         push    hl
  3446.         call    l0a81           ; Subtract reals
  3447.         ld      a,l
  3448.         pop     hl
  3449.         pop     de
  3450.         pop     bc
  3451.         exx
  3452.         pop     hl
  3453.         pop     de
  3454.         pop     bc
  3455.         ex      (sp),hl
  3456.         cp      h               ; Test ready
  3457.         ex      (sp),hl
  3458.         jr      nc,l0c5f        ; Loop on
  3459.         pop     af
  3460.         exx
  3461.         ret
  3462. ;
  3463. ; Function COS(real):real
  3464. ;
  3465. l0c7f:
  3466.         exx
  3467.         call    l0f8e           ; Load constant PI
  3468.         dec     l               ; Make 90 degrees
  3469.         call    l0a81           ; Subtract reals
  3470. ;
  3471. ; Function SIN(real):real
  3472. ;
  3473. l0c87:
  3474.         exx
  3475.         call    l0f8e           ; Load constant PI
  3476.         inc     l               ; Make 360 degrees
  3477.         exx
  3478.         ld      a,l
  3479.         cp      sin.min         ; Test underflow
  3480.         ret     c
  3481.         push    bc
  3482.         res     sgn.bit,b       ; Clear sign
  3483.         call    l0bdf           ; Compare against period
  3484.         pop     bc
  3485.         jr      c,l0ca3
  3486.         call    l0af5           ; Divide reals
  3487.         call    l0c34           ; Get fraction
  3488.         call    l0a97           ; Multiply reals
  3489. l0ca3:
  3490.         bit     sgn.bit,b       ; Test sign
  3491.         jr      z,l0caa
  3492.         call    l0a0d           ; Add reals
  3493. l0caa:
  3494.         exx
  3495.         dec     l               ; Make 180 degrees
  3496.         exx
  3497.         call    l0bdf           ; Test within 180 degrees
  3498.         push    af
  3499.         jr      c,l0cb6
  3500.         call    l0a81           ; Subtract reals
  3501. l0cb6:
  3502.         exx
  3503.         dec     l               ; Make 90 degrees
  3504.         exx
  3505.         call    l0bdf           ; Test within 90 degrees
  3506.         jr      c,l0cc3
  3507.         exx
  3508.         inc     l               ; Make 180 degrees
  3509.         call    l0a81           ; Subtract reals
  3510. l0cc3:
  3511.         ld      a,l
  3512.         cp      sin.min         ; Test underflow
  3513.         jr      c,l0d03
  3514.         exx
  3515.         ld      bc,02aaah       ; Set 1/3
  3516.         ld      de,0aaaah
  3517.         ld      hl,0aa7fh
  3518.         call    l0a97           ; Multiply reals (Divide by 3)
  3519.         push    ix
  3520.         ld      ix,l0d0d-Real.Len
  3521.         ld      a,Trg.Len
  3522.         call    l0f34           ; Do the TAYLOR loop
  3523.         pop     ix
  3524.         call    l0fac           ; Copy number
  3525.         call    l0a97           ; Multiply reals
  3526.         call    l0a97           ; Multiply reals
  3527.         push    bc
  3528.         push    de
  3529.         push    hl
  3530.         exx
  3531.         call    l0fac           ; Copy number
  3532.         dec     l               ; Divide by 4
  3533.         dec     l
  3534.         exx
  3535.         dec     l               ; Divide by 2
  3536.         call    l0a0d           ; Add reals
  3537.         exx
  3538.         pop     hl
  3539.         pop     de
  3540.         pop     bc
  3541.         exx
  3542.         call    l0a81           ; Subtract reals
  3543.         inc     l               ; Multiply by 4
  3544.         inc     l
  3545. l0d03:
  3546.         pop     af
  3547.         inc     l               ; Test zero
  3548.         dec     l
  3549.         ret     z
  3550.         ret     c               ; Check sign
  3551.         ld      a,b
  3552.         xor     sign.bit        ; Toggle it
  3553.         ld      b,a
  3554.         ret
  3555. ;
  3556. ; Taylor series for SINE and COSINE
  3557. ;
  3558. l0d0d:
  3559.         db      067h,0aah,03fh,02bh,032h,0d7h   ; -1/11!
  3560.         db      06eh,0b6h,02ah,01dh,0efh,038h   ;  1/9!
  3561.         db      074h,00dh,0d0h,000h,00dh,0d0h   ; -1/7!
  3562.         db      07ah,088h,088h,088h,088h,008h   ;  1/5!
  3563.         db      07eh,0abh,0aah,0aah,0aah,0aah   ; -1/3!
  3564. Trg.Len equ     ($-l0d0d)/Real.Len
  3565. ;
  3566. ; Function LN(real):real
  3567. ;
  3568. l0d2b:
  3569.         inc     l
  3570.         dec     l               ; Check zero
  3571.         ld      a,_LNerr
  3572.         jp      z,l2027         ; Error if so
  3573.         bit     sgn.bit,b
  3574.         jp      nz,l2027        ; If negative, too
  3575.         exx
  3576.         call    l0f98           ; Load constant SQRT(2)
  3577.         exx
  3578.         ld      a,l
  3579.         ld      l,Exp.One       ; Fix exponent
  3580.         sub     l
  3581.         push    af
  3582.         call    l0af5           ; Divide reals
  3583.         exx
  3584.         call    l0f86           ; Load constant 1.0
  3585.         exx
  3586.         call    l0a81           ; Subtract reals
  3587.         push    bc
  3588.         push    de
  3589.         push    hl
  3590.         exx
  3591.         inc     l               ; Number times 2
  3592.         call    l0a0d           ; Add reals
  3593.         exx
  3594.         pop     hl
  3595.         pop     de
  3596.         pop     bc
  3597.         call    l0af5           ; Divide reals
  3598.         push    ix
  3599.         ld      ix,l0d92-Real.Len
  3600.         ld      a,LN.len
  3601.         call    l0f34           ; Do the TAYLOR loop
  3602.         pop     ix
  3603.         inc     l               ; Number times 2
  3604.         exx
  3605.         call    l0fa2           ; Load constant LN(2)
  3606.         dec     l               ; Halve it
  3607.         exx
  3608.         call    l0a0d           ; Add reals
  3609.         pop     af
  3610.         push    bc
  3611.         push    de
  3612.         push    hl
  3613.         ld      l,a
  3614.         ld      h,0
  3615.         jr      nc,l0d7c
  3616.         dec     h               ; Set -1
  3617. l0d7c:
  3618.         call    l1008           ; Convert to real
  3619.         exx
  3620.         inc     l               ; Number times 2
  3621.         call    l0a97           ; Multiply reals
  3622.         exx
  3623.         pop     hl
  3624.         pop     de
  3625.         pop     bc
  3626.         call    l0a0d           ; Add reals
  3627.         ld      a,l
  3628.         cp      ln.min          ; Test underflow
  3629.         jp      c,l0b72         ; Return 0.0 if so
  3630.         ret
  3631. ;
  3632. ; Taylor series for Natural Logarithm
  3633. ;
  3634. l0d92:
  3635.         db      07dh,08ah,09dh,0d8h,089h,01dh   ; 1/13
  3636.         db      07dh,0e9h,0a2h,08bh,02eh,03ah   ; 1/11
  3637.         db      07dh,08eh,0e3h,038h,08eh,063h   ; 1/9
  3638.         db      07eh,049h,092h,024h,049h,012h   ; 1/7
  3639.         db      07eh,0cdh,0cch,0cch,0cch,04ch   ; 1/5
  3640.         db      07fh,0abh,0aah,0aah,0aah,02ah   ; 1/3
  3641. LN.len  equ     ($-l0d92)/Real.Len
  3642. ;
  3643. ; Function EXP(real):real
  3644. ;
  3645. l0db6:
  3646.         exx
  3647.         call    l0fa2           ; Load constant LN(2)
  3648.         exx
  3649.         or      a
  3650.         bit     sgn.bit,b
  3651.         push    af              ; Save sign
  3652.         res     sgn.bit,b       ; Clear it
  3653.         call    l0af5           ; Divide reals
  3654.         ld      a,l
  3655.         cp      exp.max         ; Test overflow
  3656.         jr      nc,l0e10
  3657.         push    bc
  3658.         push    de
  3659.         push    hl
  3660.         inc     l               ; Times 2
  3661.         call    l0fd0           ; Get integer
  3662.         push    hl
  3663.         srl     h               ; Divide by 2
  3664.         rr      l
  3665.         ld      a,l
  3666.         pop     hl
  3667.         push    af
  3668.         call    l1008           ; Back to real
  3669.         inc     l               ; Test zero
  3670.         dec     l
  3671.         jr      z,l0de0
  3672.         dec     l               ; Fix if not
  3673. l0de0:
  3674.         exx
  3675.         pop     af
  3676.         pop     hl
  3677.         pop     de
  3678.         pop     bc
  3679.         push    af
  3680.         call    l0a81           ; Subtract reals
  3681.         push    ix
  3682.         ld      ix,l0e16-Real.Len
  3683.         ld      a,EXP.Len
  3684.         call    l0f49           ; Do the TAYLOR loop
  3685.         pop     ix
  3686.         pop     af
  3687.         jr      nc,l0e03
  3688.         push    af
  3689.         exx
  3690.         call    l0f98           ; Load constant SQRT(2)
  3691.         exx
  3692.         call    l0a97           ; Multiply reals
  3693.         pop     af
  3694. l0e03:
  3695.         add     a,l             ; Build resulting exponent
  3696.         ld      l,a
  3697.         jr      c,l0e10         ; Overflow
  3698.         pop     af              ; Test sign
  3699.         ret     z
  3700.         exx
  3701.         call    l0f86           ; Load constant 1.0
  3702.         jp      l0af5           ; Divide reals (1/number)
  3703. l0e10:
  3704.         pop     hl
  3705.         ld      a,_FLPovfl      ; Error
  3706.         jp      l2027
  3707. ;
  3708. ; Taylor series for natural EXPonetiation
  3709. ;
  3710. l0e16:
  3711.         db      06dh,02eh,01dh,011h,060h,031h   ; 1.3215 E-6
  3712.         db      070h,046h,02ch,0feh,0e5h,07fh   ; 1.5252 E-5
  3713.         db      074h,036h,07ch,089h,084h,021h   ; 1.5403 E-4
  3714.         db      077h,053h,03ch,0ffh,0c3h,02eh   ; 1.3333 E-3
  3715.         db      07ah,0d2h,07dh,05bh,095h,01dh   ; 9.6181 E-3
  3716.         db      07ch,025h,0b8h,046h,058h,063h   ; 5.5504 E-2
  3717.         db      07eh,016h,0fch,0efh,0fdh,075h   ; 2.4022 E-1
  3718.         db      080h,0d2h,0f7h,017h,072h,031h   ; 6.9314 E-1
  3719. EXP.Len equ     ($-l0e16)/Real.Len
  3720. ;
  3721. ; Function ARCTAN(real):real
  3722. ;
  3723. l0e46:
  3724.         ld      a,l
  3725.         or      a               ; Test zero
  3726.         ret     z
  3727.         push    ix
  3728.         exx
  3729.         call    l0f86           ; Load constant 1.0
  3730.         exx
  3731.         xor     a
  3732.         bit     sgn.bit,b       ; Test sign
  3733.         jr      z,l0e58
  3734.         inc     a
  3735.         res     sgn.bit,b       ; Make absolute
  3736. l0e58:
  3737.         push    af
  3738.         call    l0bdf           ; Compare against 1.0
  3739.         jr      c,l0e66
  3740.         exx
  3741.         call    l0af5           ; Divide reals (1/number)
  3742.         pop     af
  3743.         set     sgn.bit,a       ; Indicate reverse
  3744.         push    af
  3745. l0e66:
  3746.         exx
  3747.         ld      bc,006cfh       ; Load 0.13165
  3748.         ld      de,0e98eh
  3749.         ld      hl,04a7eh
  3750.         exx
  3751.         call    l0bdf           ; Compare reals
  3752.         jr      nc,l0e7b
  3753.         call    l0f2e           ; Build TAYLOR series
  3754.         jr      l0eca
  3755. l0e7b:
  3756.         ld      ix,l0ee0-3*Real.Len
  3757.         ld      a,2             ; Set loop
  3758. l0e81:
  3759.         ex      af,af' ;'
  3760.         exx
  3761.         ld      de,3*Real.Len
  3762.         add     ix,de
  3763.         call    l0f73           ; Get value from table
  3764.         exx
  3765.         call    l0bdf           ; Compare reals
  3766.         jr      c,l0e9c
  3767.         ex      af,af' ;'
  3768.         dec     a               ; Go thru the loop
  3769.         jr      nz,l0e81
  3770.         exx
  3771.         ld      de,2*Real.Len
  3772.         add     ix,de           ; Fix table
  3773.         exx
  3774. l0e9c:
  3775.         exx
  3776.         call    l0f6e           ; Get next from table
  3777.         set     sgn.bit,b       ; Make negative
  3778.         call    l0a0d           ; Add reals
  3779.         push    bc
  3780.         push    de
  3781.         push    hl
  3782.         call    l0f73           ; Get value back
  3783.         call    l0a97           ; Multiply reals
  3784.         exx
  3785.         call    l0f86           ; Load constant 1.0
  3786.         call    l0a0d           ; Add reals
  3787.         exx
  3788.         pop     hl
  3789.         pop     de
  3790.         pop     bc
  3791.         call    l0af5           ; Divide reals
  3792.         push    ix
  3793.         call    l0f2e           ; Do TAYLOR
  3794.         pop     ix
  3795.         exx
  3796.         call    l0f6e           ; Get from table
  3797.         call    l0a0d           ; Add reals
  3798. l0eca:
  3799.         pop     af
  3800.         rla                     ; Get sign bit
  3801.         jr      nc,l0ed8
  3802.         push    af
  3803.         exx
  3804.         call    l0f8e           ; Load constant PI
  3805.         dec     l               ; Make 90 degrees
  3806.         call    l0a81           ; Subtract reals
  3807.         pop     af
  3808. l0ed8:
  3809.         pop     ix
  3810.         bit     1,a             ; Test operand sign
  3811.         ret     z
  3812.         set     sgn.bit,b       ; Set negative
  3813.         ret
  3814. ;
  3815. ; 2nd Taylor series for ARCTangent
  3816. ;
  3817. l0ee0:
  3818.         db      07fh,0e7h,0cfh,0cch,013h,054h   ; 4.1421 E-1
  3819.         db      07fh,0f6h,0f4h,0a2h,030h,009h   ; 2.6794 E-1
  3820.         db      07fh,06ah,0c1h,091h,00ah,006h   ; 2.6179 E-1
  3821.         db      080h,0b5h,09eh,08ah,06fh,044h   ; 7.6732 E-1
  3822.         db      080h,082h,02ch,03ah,0cdh,013h   ; 5.7735 E-1
  3823.         db      080h,06ah,0c1h,091h,00ah,006h   ; 5.2359 E-1
  3824.         db      081h,000h,000h,000h,000h,000h   ; 1.0000
  3825.         db      080h,021h,0a2h,0dah,00fh,049h   ; 7.8539 E-1
  3826. ;
  3827. ; Taylor series for ARCTangent
  3828. ;
  3829. l0f10:
  3830.         db      07dh,0e8h,0a2h,08bh,02eh,0bah   ; -1/11
  3831.         db      07dh,08eh,0e3h,038h,08eh,063h   ;  1/9
  3832.         db      07eh,049h,092h,024h,049h,092h   ; -1/7
  3833.         db      07eh,0cdh,0cch,0cch,0cch,04ch   ;  1/5
  3834.         db      07fh,0abh,0aah,0aah,0aah,0aah   ; -1/3
  3835. AT.Len  equ     ($-l0f10)/Real.Len
  3836. ;
  3837. ; Perform TAYLOR series
  3838. ; Calculate SERIES(x^2)*x
  3839. ;
  3840. l0f2e:
  3841.         ld      ix,l0f10-Real.Len
  3842.         ld      a,AT.Len
  3843. l0f34:
  3844.         push    bc
  3845.         push    de
  3846.         push    hl
  3847.         push    af
  3848.         call    l0fac           ; Copy number
  3849.         call    l0a97           ; Multiply reals [^2]
  3850.         pop     af
  3851.         call    l0f49           ; Do the TAYLOR loop
  3852.         exx
  3853.         pop     hl
  3854.         pop     de
  3855.         pop     bc
  3856.         jp      l0a97           ; Multiply reals
  3857. ;
  3858. ; The TAYLOR series loop
  3859. ; ENTRY Reg IX points to table
  3860. ;       Accu holds loop count
  3861. ; Calculate : 1-(1/3!)x+..+/-..-(1/11!)x^8
  3862. ;
  3863. l0f49:
  3864.         push    af
  3865.         exx
  3866.         call    l0f6e           ; Load from table
  3867.         jr      l0f60           ; Skip addition this time
  3868. l0f50:
  3869.         push    af
  3870.         exx
  3871.         push    bc
  3872.         push    de
  3873.         push    hl
  3874.         call    l0f6e           ; Get next value from table
  3875.         call    l0a0d           ; Add reals
  3876.         exx
  3877.         pop     hl
  3878.         pop     de
  3879.         pop     bc
  3880.         exx
  3881. l0f60:
  3882.         call    l0a97           ; Multiply reals
  3883.         pop     af
  3884.         dec     a               ; Test done
  3885.         jr      nz,l0f50        ; Nope
  3886.         exx
  3887.         call    l0f86           ; Load constant 1.0
  3888.         jp      l0a0d           ; Add reals
  3889. ;
  3890. ; Load next real from table
  3891. ; ENTRY Reg IX points to table
  3892. ; EXIT  Regs (HL,DE,BC) hold real
  3893. ;
  3894. l0f6e:
  3895.         ld      de,Real.Len
  3896.         add     ix,de           ; Point to nexr
  3897. ;
  3898. ; Load real from table
  3899. ; ENTRY Reg IX points to table
  3900. ; EXIT  Regs (HL,DE,BC) hold real
  3901. ;
  3902. l0f73:
  3903.         ld      l,(ix+0)        ; Get exponent
  3904.         ld      h,(ix+1)        ; Mantissa LSB
  3905.         ld      e,(ix+2)
  3906.         ld      d,(ix+3)
  3907.         ld      c,(ix+4)
  3908.         ld      b,(ix+5)        ; Mantissa MSB
  3909.         ret
  3910. ;
  3911. ; Load constant 1.0
  3912. ;
  3913. l0f86:
  3914.         ld      hl,Exp.One      ; Load 6 bytes 2^0
  3915.         ld      b,h
  3916.         ld      c,h
  3917.         ld      d,h
  3918.         ld      e,h
  3919.         ret
  3920. ;
  3921. ; Load constant PI=3.141592654
  3922. ;
  3923. l0f8e:
  3924.         ld      bc,0490fh       ; Load 6 bytes
  3925.         ld      de,0daa2h
  3926.         ld      hl,02182h
  3927.         ret
  3928. ;
  3929. ; Load constant SQRT (2)=1.414213562
  3930. ;
  3931. l0f98:
  3932.         ld      bc,03504h       ; Load 6 bytes
  3933.         ld      de,0f333h
  3934.         ld      hl,0fa81h
  3935.         ret
  3936. ;
  3937. ; Load constant LN (2)=0.693147181
  3938. ;
  3939. l0fa2:
  3940.         ld      bc,03172h       ; Load 6 bytes
  3941.         ld      de,017f7h
  3942.         ld      hl,0d280h
  3943.         ret
  3944. ;
  3945. ; Copy real number
  3946. ; ENTRY Regs (HL,DE,BC) hold number
  3947. ; EXIT  Number copied to alternating regs (HL,DE,BC)'
  3948. ;
  3949. l0fac:
  3950.         push    bc              ; Push onto stack
  3951.         push    de
  3952.         push    hl
  3953.         exx                     ; Copy into alternate registers
  3954.         pop     hl              ; Pop back
  3955.         pop     de
  3956.         pop     bc
  3957.         ret
  3958. ;
  3959. ; Function RANDOM:real;
  3960. ; EXIT  Regs (HL,DE,BC) hold number
  3961. ;
  3962. l0fb4:
  3963.         call    l0792           ; Get random value
  3964.         ld      hl,exp.offset   ; Init exponent and count
  3965.         ld      a,mant.bits-bit.len
  3966. l0fbc:
  3967.         bit     sgn.bit,b       ; Test MSB set
  3968.         jr      nz,l0fcd
  3969.         sla     e               ; Shift left if not
  3970.         rl      d
  3971.         rl      c
  3972.         rl      b
  3973.         dec     l               ; Count down exponent
  3974.         dec     a
  3975.         jr      nz,l0fbc
  3976.         ld      l,a
  3977. l0fcd:
  3978.         res     sgn.bit,b       ; .. make 1.0> x >=0.0
  3979.         ret
  3980. ;
  3981. ; Function ROUND(real):integer
  3982. ;
  3983. l0fd0:
  3984.         bit     sgn.bit,b       ; Attache sign
  3985.         exx
  3986.         call    l0f86           ; Load constant 1.0
  3987.         jr      z,l0fda         ; Test < 0
  3988.         set     sgn.bit,b       ; make constant -1.0
  3989. l0fda:
  3990.         dec     l               ; Set +-0.5
  3991.         call    l0a0d           ; Add reals
  3992. ;
  3993. ; Function TRUNC(real):integer
  3994. ;
  3995. l0fde:
  3996.         or      a
  3997.         bit     sgn.bit,l       ; Test exponent < 0
  3998.         jr      z,l0fff         ; Return zero if so
  3999.         bit     sgn.bit,b       ; Mark sign
  4000.         ex      af,af' ;'
  4001.         set     sgn.bit,b       ; Set bit
  4002. l0fe8:
  4003.         ld      a,int.max
  4004.         cp      l
  4005.         jr      c,l1003         ; Test overflow
  4006.         jr      z,l0ff5         ; Or end of conversion
  4007.         call    l0b7a           ; Shift mantissa right
  4008.         inc     l               ; Bump exponent
  4009.         jr      l0fe8
  4010. l0ff5:
  4011.         call    l0b7a           ; Shift mantissa right
  4012.         ex      af,af' ;'
  4013.         ld      h,b             ; Get result
  4014.         ld      l,c
  4015.         ret     z               ; End if > 0
  4016.         jp      l0783           ; Negate
  4017. l0fff:
  4018.         ld      hl,0            ; Return 0
  4019.         ret
  4020. l1003:
  4021.         ld      a,_TruncOvl
  4022.         jp      l2027           ; Set error
  4023. ;
  4024. ; Convert integer to floating point
  4025. ; ENTRY Reg HL holds signed integer
  4026. ; EXIT  Regs (HL,DE,BC) hold real
  4027. ;
  4028. ; NOTE: ON INTEGER 8000H AND ONLY ON THIS NUMBER
  4029. ;       THIS ROUTINE WILL LOOP FOREVER !!!!!!!!
  4030. ;
  4031. l1008:
  4032.         ld      a,h             ; Test Zero
  4033.         or      l
  4034.         jp      z,l0b72         ; Set 0.0 if so
  4035.         bit     sgn.bit,h       ; Test sign
  4036.         ex      af,af' ;'
  4037.         call    l0780           ; Make number positive
  4038.         ld      a,int.max+1     ; Init exponent
  4039. l1015:
  4040.         add     hl,hl           ; Shift mantissa
  4041.         dec     a               ; Fix exponent
  4042.         bit     sgn.bit,h       ; Test ready
  4043.         jr      z,l1015         ; Nope, wait for bit
  4044.         ld      b,h             ; Get into hi part of mantissa
  4045.         ld      c,l
  4046.         ld      de,0            ; Clear lo part
  4047.         ld      h,d
  4048.         ld      l,a
  4049.         ex      af,af' ;'       ; Test sign
  4050.         ret     nz
  4051.         res     sgn.bit,b       ; Set > 0
  4052.         ret
  4053. ;
  4054. ; Convert real to formatted ASCII string
  4055. ; ENTRY Reg HL holds fix comma places (-1 on none)
  4056. ;       Reg DE holds decimal places
  4057. ;       Regs (HL,BC,DE)' hold real number
  4058. ;       Reg IX points to ASCII buffer
  4059. ;
  4060. l1027:
  4061.         call    l04c8           ; Get fix comma places
  4062.         ex      de,hl
  4063.         ld      e,0
  4064.         jr      c,l1033         ; Integer was < 0, no places
  4065.         cp      real.dig+1      ; Test max digits
  4066.         jr      c,l104b
  4067. l1033:
  4068.         dec     e
  4069.         call    l04c8           ; Get decimal places
  4070.         exx
  4071.         bit     sgn.bit,b       ; Test sign
  4072.         exx
  4073.         ld      d,real.field    ; Init field size
  4074.         jr      z,l1040
  4075.         inc     d               ; Fix for sign < 0.0
  4076. l1040:
  4077.         sub     d               ; Test against field length
  4078.         jr      nc,l1044
  4079.         xor     a
  4080. l1044:
  4081.         cp      real.field+2    ; Test max
  4082.         jr      c,l104a
  4083.         ld      a,real.field+2
  4084. l104a:
  4085.         inc     a
  4086. l104b:
  4087.         ld      d,a
  4088.         push    de
  4089.         exx
  4090.         ld      iy,Number ;number ;???
  4091.         push    ix
  4092.         call    l10eb           ; Prepare conversion
  4093.         pop     ix
  4094.         pop     de
  4095.         ld      c,a             ; Save result exponent
  4096.         ld      a,d
  4097.         inc     a
  4098.         bit     sgn.bit,e       ; Test sign
  4099.         jr      nz,l1071        ; < 0
  4100.         add     a,c             ; Fix exponent
  4101.         jp      p,l106b
  4102.         ld      (iy),0          ; Clear entry
  4103.         jr      l1076
  4104. l106b:
  4105.         cp      real.ASCII      ; Test decimal places
  4106.         jr      c,l1071
  4107.         ld      a,real.ASCII-1  ; Truncate it
  4108. l1071:
  4109.         push    de
  4110.         call    l1180           ; Normalize ASCII
  4111.         pop     de
  4112. l1076:
  4113.         bit     sgn.bit,b       ; Test sign
  4114.         jr      z,l107f
  4115.         ld      a,'-'
  4116.         call    l10e5           ; Set sign
  4117. l107f:
  4118.         bit     sgn.bit,e       ; Test sign
  4119.         jr      z,l1086
  4120.         ld      h,c             ; Unpack
  4121.         ld      c,0
  4122. l1086:
  4123.         bit     sgn.bit,c       ; Test sign
  4124.         jr      z,l108f
  4125.         call    l10e3           ; Set 0
  4126.         jr      l1096
  4127. l108f:
  4128.         call    l10d9           ; Copy ASCII
  4129.         dec     c               ; Bump down
  4130.         jp      p,l108f
  4131. l1096:
  4132.         ld      a,d             ; Test mantissa
  4133.         or      a
  4134.         jr      z,l10b1         ; None
  4135.         ld      a,'.'
  4136.         call    l10e5           ; Set decimal dot
  4137. l109f:
  4138.         inc     c               ; Fix exponent
  4139.         jr      z,l10a8
  4140.         call    l10e3           ; Set 0
  4141.         dec     d
  4142.         jr      nz,l109f
  4143. l10a8:
  4144.         dec     d
  4145.         jp      m,l10b1
  4146.         call    l10d9           ; Copy ASCII
  4147.         jr      l10a8
  4148. l10b1:
  4149.         bit     sgn.bit,e       ; Test exponent
  4150.         ret     z               ; Nope
  4151.         ld      a,'E'
  4152.         call    l10e5           ; Set 'E'xponent
  4153.         ld      a,'+'
  4154.         bit     sgn.bit,h       ; Test bit
  4155.         jr      z,l10c5
  4156.         ld      a,h
  4157.         neg                     ; Make exponent > 0
  4158.         ld      h,a
  4159.         ld      a,'-'
  4160. l10c5:
  4161.         call    l10e5           ; Store sign of exponent
  4162.         ld      a,h             ; Get exponent
  4163.         ld      b,'0'-1         ; Init HI
  4164. l10cb:
  4165.         inc     b               ; Fix result
  4166.         sub     10              ; Divide by 10
  4167.         jr      nc,l10cb
  4168.         add     a,'9'+1         ; Make remainder ASCII
  4169.         ld      (ix),b          ; save HI
  4170.         inc     ix
  4171.         jr      l10e5           ; Store LO
  4172. ;
  4173. ; Copy from buffer, set 0 if end
  4174. ;
  4175. l10d9:
  4176.         ld      a,(iy)          ; Get number
  4177.         inc     iy
  4178.         or      a               ; Test end
  4179.         jr      nz,l10e5        ; Nope
  4180.         dec     iy              ; Fix for zero storage
  4181. ;
  4182. ; Store ASCII zero into number
  4183. ;
  4184. l10e3:
  4185.         ld      a,'0'           ; Set zero
  4186. ;
  4187. ; Store ASCII into number
  4188. ;
  4189. l10e5:
  4190.         ld      (ix),a          ; Store number
  4191.         inc     ix              ; Update pointer
  4192.         ret
  4193. ;
  4194. ; Prepare ASCII for real to formatted ASCII conversion
  4195. ; ENTRY Reg IY points to ASXII buffer
  4196. ;       Regs (HL,BC,DE) hold real number
  4197. ; EXIT  Buffer pre-filled
  4198. ;       Accu holds exponent equivalent
  4199. ;
  4200. l10eb:
  4201.         push    iy              ; save buffer
  4202.         inc     l               ; Test zero number
  4203.         dec     l
  4204.         jr      nz,l10ff
  4205.         ld      b,real.ASCII    ; Set length
  4206. l10f3:
  4207.         ld      (iy),'0'        ; Clear ASCII number
  4208.         inc     iy
  4209.         djnz    l10f3
  4210.         xor     a
  4211.         jp      l117d
  4212. l10ff:
  4213.         push    bc              ; Save sign
  4214.         res     sgn.bit,b       ; Reset sign
  4215.         ld      a,l
  4216.         exx
  4217.         sub     exp.offset      ; Strip off offset
  4218.         ld      l,a
  4219.         sbc     a,a             ; Expand to signed 16 bit
  4220.         ld      h,a
  4221.         ld      de,ExpFix
  4222.         call    l06f5           ; HL:=HL*DE
  4223.         ld      de,10 / 2
  4224.         add     hl,de           ; Gix exponent
  4225.         ld      a,h
  4226.         cp      ExpRange        ; Test range
  4227.         jr      nz,l1119
  4228.         inc     a               ; Fix result
  4229. l1119:
  4230.         ld      (iy),a          ; Store into buffer
  4231.         neg
  4232.         call    l1240
  4233.         ld      a,l
  4234.         cp      Exp.One         ; Test exponent
  4235.         jr      nc,l112c
  4236.         call    l12b3           ; Fix mantissa
  4237.         dec     (iy)            ; Fix exponent
  4238. l112c:
  4239.         set     sgn.bit,b       ; Set bit
  4240.         ld      a,exp.offset+4
  4241.         sub     l               ; Test exponent
  4242.         ld      l,0
  4243.         jr      z,l113d
  4244. l1135:
  4245.         call    l0b7a           ; Shift mantissa right
  4246.         rr      l
  4247.         dec     a
  4248.         jr      nz,l1135
  4249. l113d:
  4250.         ld      a,(iy)          ; Get exponent
  4251.         push    af
  4252.         ld      a,real.ASCII    ; Set count
  4253. l1143:
  4254.         ex      af,af'
  4255.         ld      a,b             ; Get MSB
  4256.         rra                     ; Isolate hi
  4257.         rra
  4258.         rra
  4259.         rra
  4260.         and     LoMask          ; Mask bits
  4261.         add     a,'0'           ; Make ASCII
  4262.         ld      (iy),a
  4263.         inc     iy
  4264.         ld      a,b
  4265.         and     LoMask
  4266.         ld      b,a
  4267.         push    bc
  4268.         push    de
  4269.         push    hl
  4270.         sla     l
  4271.         call    l0b87           ; Rotate mantissa left *2
  4272.         sla     l
  4273.         call    l0b87           ; * 4
  4274.         ex      de,hl
  4275.         ex      (sp),hl
  4276.         add     hl,de           ; * 5
  4277.         pop     de
  4278.         ex      (sp),hl
  4279.         adc     hl,de
  4280.         ex      de,hl
  4281.         pop     hl
  4282.         ex      (sp),hl
  4283.         adc     hl,bc
  4284.         ld      b,h
  4285.         ld      c,l
  4286.         pop     hl
  4287.         sla     l
  4288.         call    l0b87           ; *10
  4289.         ex      af,af'
  4290.         dec     a
  4291.         jr      nz,l1143
  4292.         pop     af
  4293.         pop     bc
  4294. l117d:
  4295.         pop     iy
  4296.         ret
  4297. ;
  4298. ; Normalize ASCII number
  4299. ; ENTRY Accu holds length of number
  4300. ;
  4301. l1180:
  4302.         push    iy
  4303.         pop     hl              ; Copy buffer
  4304.         ld      e,a
  4305.         ld      d,0
  4306.         add     hl,de
  4307.         ld      a,(hl)          ; Get last digit
  4308.         ld      (hl),0
  4309.         cp      '5'             ; Test to be normalized
  4310.         ret     c               ; Nope
  4311. l118d:
  4312.         dec     e               ; Count down
  4313.         jp      m,l119c
  4314.         dec     hl              ; Get previous
  4315.         ld      a,(hl)
  4316.         inc     a               ; Advance digit
  4317.         ld      (hl),a
  4318.         cp      '9'+1           ; Test in range
  4319.         ret     c               ; Yeap
  4320.         ld      (hl),0          ; Clear this one
  4321.         jr      l118d
  4322. l119c:
  4323.         ld      (hl),'1'        ; Set carry
  4324.         inc     hl
  4325.         ld      (hl),0          ; Clear next
  4326.         inc     c
  4327.         ret
  4328. ;
  4329. ; Convert ASCII string to Floating Point number
  4330. ; ENTRY Reg IX points to ASCII number
  4331. ; EXIT  Regs HL,DE,BC hold real
  4332. ;       Carry set indicates conversion error
  4333. ;
  4334. cnv_flp:
  4335.         exx
  4336.         ld      bc,0            ; Reset flags
  4337.         exx
  4338.         call    l0b72           ; Init 0.0
  4339. l11ab:
  4340.         ld      a,(ix)          ; Get character
  4341.         call    doupcase                ; Convert to upper case
  4342.         cp      '.'             ; Test decimal point
  4343.         jr      nz,l11c1
  4344.         exx
  4345.         bit     dot.bit,b       ; Test already selected
  4346.         scf
  4347.         ret     nz              ; Error if so
  4348.         set     dot.bit,b       ; Indicate dot
  4349.         exx
  4350. l11bd:
  4351.         inc     ix              ; Skip character
  4352.         jr      l11ab           ; Get next
  4353. l11c1:
  4354.         cp      'E'             ; Test exponent
  4355.         jr      z,l11e6         ; Yeap, process it
  4356.         call    l1239           ; Test digit
  4357.         jr      nc,l121e        ; Nope
  4358.         ex      af,af'
  4359.         call    l12b3           ; Convert mantissa
  4360.         ret     c               ; Error
  4361.         ex      af,af'
  4362.         exx
  4363.         push    bc
  4364.         ld      l,a             ; Build integer
  4365.         ld      h,0
  4366.         call    l1008           ; Convert to floating point
  4367.         call    l09e9           ; Add reals
  4368.         exx
  4369.         pop     bc
  4370.         ret     c               ; End if overflow
  4371.         bit     dot.bit,b       ; Test decimal point
  4372.         jr      z,l11e3
  4373.         dec     c               ; Fix length if so
  4374. l11e3:
  4375.         exx
  4376.         jr      l11bd
  4377. ;
  4378. ; Found 'E'xponent
  4379. ;
  4380. l11e6:
  4381.         call    l121e           ; Fix mantissa
  4382.         ret     c               ; Overflow
  4383.         exx
  4384.         set     exp.bit,b       ; Set bit
  4385.         inc     ix
  4386.         ld      a,(ix)
  4387.         cp      '+'             ; Test any sign
  4388.         jr      z,l11fc         ; Skip plus
  4389.         cp      '-'
  4390.         jr      nz,l11fe
  4391.         set     exps.bit,b      ; Indicate negative exponent
  4392. l11fc:
  4393.         inc     ix
  4394. l11fe:
  4395.         call    l1236           ; Get 1st digit
  4396.         ccf
  4397.         ret     c               ; Invalid
  4398.         ld      c,a
  4399.         inc     ix
  4400.         call    l1236           ; Get 2nd digit
  4401.         jr      nc,l1215        ; Only one
  4402.         inc     ix
  4403.         ld      d,a
  4404.         ld      a,c             ; Get first one - it's tens
  4405.         add     a,a             ; * 2
  4406.         add     a,a             ; * 4
  4407.         add     a,c             ; * 5
  4408.         add     a,a             ; *10
  4409.         add     a,d             ; Insert 2nd
  4410.         ld      c,a
  4411. l1215:
  4412.         bit     exps.bit,b      ; Test exponent < 0
  4413.         jr      z,l121d         ; Nope
  4414.         ld      a,c
  4415.         neg                     ; Change it if so
  4416.         ld      c,a
  4417. l121d:
  4418.         exx
  4419. l121e:
  4420.         exx
  4421.         ld      a,c             ; Get exponent
  4422.         add     a,exp.offset    ; Set offset
  4423.         cp      05ah            ; Check range
  4424.         ret     c               ; Underflow
  4425.         cp      0a6h
  4426.         ccf
  4427.         ret     c               ; Overflow
  4428.         push    bc
  4429.         push    ix
  4430.         ld      a,c
  4431.         call    l1240           ; Fix exponent
  4432.         pop     ix
  4433.         exx
  4434.         pop     bc              ; Fix stack
  4435.         exx
  4436.         ret
  4437. ;
  4438. ; Get character and test if digit
  4439. ; ENTRY Reg IX points to character
  4440. ; EXIT  Accu holds character
  4441. ;       Carry reset if in range
  4442. ;
  4443. l1236:
  4444.         ld      a,(ix)          ; Get character
  4445. ;
  4446. ; Test character a digit - C set if so
  4447. ; ENTRY Accu holds character
  4448. ; EXIT  Carry reset if in range
  4449. ;
  4450. l1239:
  4451.         sub     '0'             ; Strip off offset
  4452.         ccf
  4453.         ret     nc              ; Out of range
  4454.         cp      9+1
  4455.         ret
  4456. ;
  4457. ; Fix exponent for real to ASCII conversion
  4458. ; ENTRY Accu holds exponent equivalent
  4459. ; EXIT  Real fixed
  4460. ;
  4461. l1240:
  4462.         push    af              ; Save exponent
  4463.         or      a               ; Test sign
  4464.         jp      p,l1247
  4465.         neg                     ; Make >0
  4466. l1247:
  4467.         push    af
  4468.         srl     a               ; Shift
  4469.         srl     a
  4470.         inc     a               ; Then fix
  4471.         ld      hl,-Real.Len    ; Init index
  4472.         ld      de,Real.Len
  4473. l1253:
  4474.         add     hl,de           ; Fix index
  4475.         dec     a
  4476.         jr      nz,l1253
  4477.         ex      de,hl
  4478.         ld      ix,l1277        ; Point to table
  4479.         add     ix,de
  4480.         call    l0f73           ; Get number from table
  4481.         pop     af
  4482.         and     11b             ; Get MOD 4
  4483.         jr      z,l126e
  4484. l1266:
  4485.         push    af
  4486.         call    l12b3           ; Fix mantissa
  4487.         pop     af
  4488.         dec     a
  4489.         jr      nz,l1266
  4490. l126e:
  4491.         pop     af              ; Get back exponent
  4492.         or      a
  4493.         jp      p,l0a97         ; Multiply reals if > 0
  4494.         exx
  4495.         jp      l0af5           ; Divide reals if < 0
  4496. ;
  4497. ; Fix up table
  4498. ;
  4499. l1277:
  4500.         db      081h,000h,000h,000h,000h,000h   ; 1 E 0
  4501.         db      08eh,000h,000h,000h,040h,01ch   ; 1 E 4
  4502.         db      09bh,000h,000h,020h,0bch,03eh   ; 1 E 8
  4503.         db      0a8h,000h,010h,0a5h,0d4h,068h   ; 1 E12
  4504.         db      0b6h,004h,0bfh,0c9h,01bh,00eh   ; 1 E16
  4505.         db      0c3h,0ach,0c5h,0ebh,078h,02dh   ; 1 E20
  4506.         db      0d0h,0cdh,0ceh,01bh,0c2h,053h   ; 1 E24
  4507.         db      0deh,0f9h,078h,039h,03fh,001h   ; 1 E28
  4508.         db      0ebh,02bh,0a8h,0adh,0c5h,01dh   ; 1 E32
  4509.         db      0f8h,0c9h,07bh,0ceh,097h,040h   ; 1 E36
  4510. ;
  4511. ; Fix mantissa for real to ASCII conversion
  4512. ; ENTRY Regs (BC,DE,HL) hold real
  4513. ; EXIT  Real fixed
  4514. ;
  4515. l12b3:
  4516.         ld      a,l             ; Test exponent
  4517.         or      a
  4518.         ret     z               ; Zero
  4519.         set     _MB,b           ; Set bit
  4520.         push    bc
  4521.         push    de
  4522.         ld      a,h
  4523.         call    l0b7a           ; Shift mantissa right
  4524.         call    l0b7a           ; Two places
  4525.         add     a,h             ; Add LSB
  4526.         ld      h,a
  4527.         ex      (sp),hl         ; Get middle part
  4528.         adc     hl,de           ; Add it
  4529.         ex      de,hl
  4530.         pop     hl
  4531.         ex      (sp),hl
  4532.         adc     hl,bc           ; Same for hi part
  4533.         ld      b,h             ; Copy to high
  4534.         ld      c,l
  4535.         pop     hl              ; Get back old hi
  4536.         jr      nc,l12d6
  4537.         call    l0b7b           ; Rotate mantissa right
  4538.         inc     l               ; Fix exponent
  4539.         scf
  4540.         ret     z
  4541. l12d6:
  4542.         ld      a,l
  4543.         add     a,3             ; Fix exponent
  4544.         ld      l,a
  4545.         res     _MB,b           ; Clear bit
  4546.         ret
  4547. ;
  4548. ; Test sets not equal (<>)
  4549. ; ENTRY Both sets on stack
  4550. ; EXIT  Reg HL holds boolean result
  4551. ;
  4552. l12dd:
  4553.         ld      c,_TRUE         ; Set flag
  4554.         jr      l12e3           ; Compare
  4555. ;
  4556. ; Test sets equal (=)
  4557. ; ENTRY Both sets on stack
  4558. ; EXIT  Reg HL holds boolean result
  4559. ;
  4560. l12e1:
  4561.         ld      c,FALSE
  4562. l12e3:
  4563.         call    l133f           ; Get sets
  4564. l12e6:
  4565.         ld      a,(de)
  4566.         cp      (hl)            ; Compare
  4567.         jr      nz,l12f2        ; Not equal
  4568.         inc     hl
  4569.         inc     de
  4570.         djnz    l12e6
  4571.         ld      a,c
  4572.         xor     _TRUE           ; Zoggle flag if equal
  4573.         ld      c,a
  4574. l12f2:
  4575.         ld      hl,2*set.len
  4576.         add     hl,sp           ; Fix stack
  4577.         ld      sp,hl
  4578.         ld      l,c             ; Get state
  4579.         ld      h,0
  4580.         jp      (ix)            ; Exit
  4581. ;
  4582. ; Test two sets included (1st in 2nd, <=)
  4583. ; ENTRY Both sets on stack
  4584. ; EXIT  Reg HL holds boolean result
  4585. ;
  4586. l12fc:
  4587.         ld      c,_TRUE         ; Set flag
  4588.         jr      l1302
  4589. ;
  4590. ; Test two sets included (2nd in 1st, >=)
  4591. ; ENTRY Both sets on stack
  4592. ; EXIT  Reg HL holds boolean result
  4593. ;
  4594. l1300:
  4595.         ld      c,FALSE
  4596. l1302:
  4597.         call    l133f           ; Get sets
  4598.         dec     c               ; Test comparision mode
  4599.         jr      nz,l1309
  4600.         ex      de,hl
  4601. l1309:
  4602.         ld      c,FALSE
  4603. l130b:
  4604.         ld      a,(de)
  4605.         or      (hl)            ; Combine
  4606.         cp      (hl)            ; Compare
  4607.         jr      nz,l12f2
  4608.         inc     hl
  4609.         inc     de
  4610.         djnz    l130b
  4611.         ld      c,_TRUE         ; Return TRUE
  4612.         jr      l12f2
  4613. ;
  4614. ; Combine two sets (add, +)
  4615. ; ENTRY Both sets on stack
  4616. ; EXIT  Combined set on stack
  4617. ;
  4618. l1318:
  4619.         call    l133f           ; Get sets
  4620. l131b:
  4621.         ld      a,(de)
  4622.         or      (hl)            ; Combine sets
  4623.         ld      (hl),a
  4624.         inc     hl
  4625.         inc     de
  4626.         djnz    l131b
  4627. l1322:
  4628.         ex      de,hl
  4629.         ld      sp,hl
  4630.         jp      (ix)
  4631. ;
  4632. ; Combine two sets (subtract, -)
  4633. ; ENTRY Both sets on stack
  4634. ; EXIT  Combined set on stack
  4635. ;
  4636. l1326:
  4637.         call    l133f           ; Get sets
  4638. l1329:
  4639.         ld      a,(de)
  4640.         cpl                     ; Complement
  4641.         and     (hl)            ; Mask bits
  4642.         ld      (hl),a
  4643.         inc     hl
  4644.         inc     de
  4645.         djnz    l1329
  4646.         jr      l1322
  4647. ;
  4648. ; Combine two sets (intersection, *)
  4649. ; ENTRY Both sets on stack
  4650. ; EXIT  Combined set on stack
  4651. ;
  4652. l1333:
  4653.         call    l133f           ; Get sets
  4654. l1336:
  4655.         ld      a,(de)
  4656.         and     (hl)            ; Mask
  4657.         ld      (hl),a
  4658.         inc     hl
  4659.         inc     de
  4660.         djnz    l1336
  4661.         jr      l1322
  4662. ;
  4663. ; Get addresses of sets
  4664. ; ENTRY Both sets on stack
  4665. ; EXIT  Regs HL and DE point to sets
  4666. ;       Reg  IX holds caller address
  4667. ;       Reg  B  holds set length
  4668. ;
  4669. l133f:
  4670.         pop     iy              ; Get last caller
  4671.         pop     ix              ; Get caller before last one
  4672.         ld      hl,0
  4673.         add     hl,sp
  4674.         ex      de,hl           ; Get 1st set
  4675.         ld      hl,set.len
  4676.         ld      b,l             ; Get length
  4677.         add     hl,sp           ; Get 2nd set
  4678.         jp      (iy)            ; Return
  4679. ;
  4680. ; Test element in set (IN)
  4681. ; ENTRY Both sets on stack
  4682. ; EXIT  Reg HL holds boolean result
  4683. ;
  4684. l134f:
  4685.         pop     ix              ; Get caller
  4686.         ld      hl,set.len+1
  4687.         add     hl,sp           ; Get pointer to set
  4688.         ld      a,(hl)
  4689.         or      a               ; Test any set
  4690.         jr      z,l135c
  4691.         xor     a
  4692.         jr      l1362           ; Force FALSE
  4693. l135c:
  4694.         dec     hl
  4695.         ld      b,(hl)
  4696.         call    l05ba           ; Get bit state
  4697.         and     (hl)
  4698. l1362:
  4699.         ld      hl,set.len+2
  4700.         add     hl,sp
  4701.         ld      sp,hl           ; Set return stack
  4702.         ld      hl,FALSE        ; Init FALSE
  4703.         jr      z,l136d         ; Test result
  4704.         inc     hl              ; Set TRUE
  4705. l136d:
  4706.         jp      (ix)
  4707. ;
  4708. ; Procedure ASSIGN(file,filename)
  4709. ; ENTRY Filenname as string on stack
  4710. ;       FIB followed string
  4711. ;
  4712. ; Assign text file
  4713. ;
  4714. l136f:
  4715.         db      skip            ; Set non zero
  4716. ;
  4717. ; Assign (un)typed file
  4718. ;
  4719. l1370:
  4720.         xor     a               ; Set zero
  4721.         ld      (l00e8),a       ;ok ;FIXME ; Put into mode
  4722.         pop     iy              ; Get back caller
  4723.         ld      hl,(l00d2)      ;ok ;FIXME ; Get top of memory
  4724.         ld      b,16            ; And max length
  4725.         call    l05e2           ; Assign string from stack
  4726.         xor     a
  4727.         ld      (de),a          ; Close it
  4728.         pop     hl              ; Fetch FIB
  4729.         ld      (l00e2),hl      ;ok ;FIXME ; Put into device
  4730.         push    iy              ; Bring back caller
  4731.         ld      a,h             ; Verify not standard but file
  4732.         or      a
  4733.         jr      nz,l1390
  4734.         ld      a,_StdAssErr    ; Set illegal FIB
  4735.         ld      (l00d0),a ;ok ;FIXME
  4736.         ret
  4737. l1390:
  4738.         ld      a,(l00e8)       ;ok ;FIXME ; Get back mode
  4739.         or      a               ; Test text file
  4740.         jr      z,l13a0         ; Nope
  4741.         call    l13b6           ; Find standard device
  4742.         jr      nz,l13a0        ; Nope
  4743.         ld      hl,(l00e2)      ;ok ;FIXME ; Get back FIB
  4744.         ld      (hl),a          ; Set flag
  4745.         ret
  4746. l13a0:
  4747.         call    l03f2           ; Parse file
  4748.         ld      hl,(l00e2) ;ok ;FIXME
  4749.         ld      (hl),0
  4750.         ld      de,FIB.FCB
  4751.         add     hl,de           ; Point to FCB part
  4752.         ex      de,hl
  4753.         ld      hl,l005c
  4754.         ld      bc,FCBlen
  4755.         ldir                    ; move FCB to FIB
  4756.         ret
  4757. ;
  4758. ; Find standard IO device
  4759. ; ENTRY TOPRAM filled with device string
  4760. ; EXIT  Zero flag set if device found
  4761. ;       Accu holds FIB flag if so
  4762. ;
  4763. l13b6:
  4764.         ld      b,Std.Len       ; Init length
  4765.         ld      hl,l13e6        ; Get table address
  4766. l13bb:
  4767.         push    bc
  4768.         push    hl
  4769.         ld      b,Std.Itm-1     ; Set length of one item
  4770.         ld      de,(l00d2)      ;ok ;FIXME ; Get top of memory
  4771. l13c3:
  4772.         inc     de
  4773.         ld      a,(de)
  4774.         cp      ' '             ; Skip leading blanks
  4775.         jr      z,l13c3
  4776. l13c9:
  4777.         ld      a,(de)          ; Get character
  4778.         call    doupcase                ; Convert to upper case
  4779.         sub     (hl)            ; Compare
  4780.         jr      z,l13da         ; Maybe a hit
  4781.         pop     hl
  4782.         pop     bc
  4783.         ld      de,Std.Itm
  4784.         add     hl,de           ; Point to next entry
  4785.         djnz    l13bb           ; Try more
  4786.         or      a
  4787.         ret
  4788. l13da:
  4789.         inc     hl
  4790.         inc     de
  4791.         djnz    l13c9           ; Loop until all found
  4792.         pop     bc
  4793.         pop     bc
  4794.         ld      a,(de)
  4795.         cp      ':'             ; Verify standard device
  4796.         ret     nz
  4797.         ld      a,(hl)          ; Get flag if so
  4798.         ret
  4799. ;
  4800. ; Standard character I/O devices
  4801. ;
  4802. l13e6:
  4803.         db      'CON'
  4804.         db      11000001b       ; Input output for CON 
  4805. Std.Itm equ     $-l13e6
  4806.         db      'TRM'
  4807.         db      11000001b       ; Input output for TRM
  4808.         db      'KBD'
  4809.         db      10000010b       ; Input for KBD
  4810.         db      'LST'
  4811.         db      01000011b       ; Output for LST
  4812.         db      'AUX'
  4813.         db      11000100b       ; Input output for AUX
  4814.         db      'USR'
  4815.         db      11000101b       ; Input output for USR
  4816. Std.Len equ     ($-l13e6) / Std.Itm
  4817. ;
  4818. ; Prepare files
  4819. ; ENTRY Reg HL points to FIB
  4820. ;
  4821. ; Procedure REWRITE(text_file)
  4822. ;
  4823. l13fe:
  4824.         db      skip
  4825. ;
  4826. ; Procedure RESET(text_file)
  4827. ;
  4828. l13ff:
  4829.         xor     a
  4830.         ld      (l00e8),a       ;ok ;FIXME ; Set mode (0=RESET)
  4831.         call    l1469           ; Close open file
  4832.         ld      a,(l00d0) ;ok ;FIXME
  4833.         or      a               ; Test error
  4834.         ret     nz              ; End if so
  4835.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  4836.         res     wr.bit,(hl)     ; Reset write flag
  4837.         ld      a,(hl)
  4838.         and     FIBtype         ; Get type
  4839.         ret     nz              ; Exit on standard device
  4840.         call    l1430           ; Prepare file operation
  4841.         ld      a,(l00d0) ;ok ;FIXME
  4842.         or      a               ; Test error
  4843.         ret     nz              ; Exit if so
  4844.         ld      hl,(l00e2)      ;ok ;FIXME ; Get back FIB
  4845.         ld      a,(l00e8)       ;ok ;FIXME ; Get file mode
  4846.         or      a               ; Test RESET
  4847.         ld      bc,RecLng*256+_.in
  4848.         jr      z,l142b         ; Yeap
  4849.         ld      bc,0*256+_.out
  4850. l142b:
  4851.         ld      (hl),c          ; Set flag
  4852.         inc     hl
  4853.         inc     hl
  4854.         ld      (hl),b          ; Set buffer pointer
  4855.         ret
  4856. ;
  4857. ; Prepare file operation for current FIB
  4858. ;
  4859. l1430:
  4860.         call    l145a           ; Clear FCB of this FIB
  4861.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  4862.         ld      de,FIB.FCB
  4863.         add     hl,de           ; Point to FCB
  4864.         ex      de,hl
  4865.         ld      a,(l00e8)       ;ok ;FIXME ; Get file mode
  4866.         or      a               ; Test RESET
  4867.         ld      bc,_NoFile*256+_open
  4868.         jr      z,l144e         ; Yeap, go open file
  4869.         push    de
  4870.         ld      c,_delete
  4871.         call    BDOS            ; Delete file before rewrite
  4872.         pop     de
  4873.         ld      bc,_DirFull*256+_make
  4874. l144e:
  4875.         push    bc
  4876.         call    BDOS            ; Now open or make file
  4877.         pop     bc
  4878.         ;inc    a               ; Test success
  4879.         ;ret    nz              ; Yeap
  4880.          or a
  4881.          ret z
  4882.         ld      a,b
  4883.         ld      (l00d0),a       ;ok ;FIXME ; Set error if not
  4884.         ret
  4885. ;
  4886. ; Clear FCB of current FIB
  4887. ;
  4888. l145a:
  4889.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  4890.         ld      de,FIB.FCB+_ex
  4891.         add     hl,de           ; Point to EX filed
  4892.         ld      b,FCBlen-_ex    ; Set length
  4893. l1463:
  4894.         ld      (hl),0          ; Clear it
  4895.         inc     hl
  4896.         djnz    l1463
  4897.         ret
  4898. ;
  4899. ; Close text file
  4900. ;
  4901. ; Procedure CLOSE(text_file)
  4902. ;
  4903. ; ENTRY Reg HL holds FIB
  4904. ;
  4905. l1469:
  4906.         ld      (l00e2),hl      ;ok ;FIXME ; Save FIB for current device
  4907.         ld      a,(hl)
  4908.         and     FIBtype         ; Get type
  4909.         ret     nz              ; Exit if not a file
  4910.         bit     out.bit,(hl)    ; Test output
  4911.         jr      z,l147e         ; Skip if not
  4912.         ld      a,eof
  4913.         call    l16c6           ; Close file by EOF
  4914.         call    l170c           ; Then flash buffer
  4915.         jr      l1481
  4916. l147e:
  4917.         bit     in.bit,(hl)     ; Test input
  4918.         ret     z               ; Nope, end
  4919. l1481:
  4920.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  4921.         push    hl
  4922.         ld      de,FIB.FCB
  4923.         add     hl,de           ; Point to FCB
  4924.         ex      de,hl
  4925.         ld      c,_close
  4926.         call    BDOS            ; Close file
  4927.         pop     hl
  4928.         inc     a               ; Test success
  4929.         jr      nz,l1498        ; Yeap
  4930.         ld      a,_NoClose
  4931.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  4932. l1498:
  4933.         ld      (hl),0          ; Reset FIB flag
  4934.         ret
  4935. ;
  4936. ; Set standard device
  4937. ;
  4938. l149b:
  4939.         ex      (sp),hl
  4940.         ld      (l00e4),hl      ;ok ;FIXME ; Save caller
  4941.         ex      (sp),hl
  4942.         push    hl
  4943.         ld      hl,l00c2
  4944.         ld      (l00e2),hl      ;ok ;FIXME ; Set standard as FIB
  4945.         pop     hl
  4946.         ret
  4947. ;
  4948. ; Check file before read
  4949. ; ENTRY Reg HL points to FIB
  4950. ;
  4951. l14a9:
  4952.         ex      (sp),hl
  4953.         ld      (l00e4),hl      ;ok ;FIXME ; Save caller for error
  4954.         ex      (sp),hl
  4955.         ld      (l00e2),hl      ;ok ;FIXME ; Save FIB
  4956.         bit     in.bit,(hl)     ; Test read allowed
  4957.         ret     nz              ; Yeap
  4958.         ld      a,_NoRead
  4959.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  4960.         ret
  4961. ;
  4962. ; Check file before write
  4963. ; ENTRY Reg HL points to FIB
  4964. ;
  4965. l14ba:
  4966.         ex      (sp),hl
  4967.         ld      (l00e4),hl      ;ok ;FIXME ; Save caller for error
  4968.         ex      (sp),hl
  4969.         ld      (l00e2),hl      ;ok ;FIXME ; Save FIB
  4970.         bit     out.bit,(hl)    ; Test write allowed
  4971.         ret     nz              ; Yeap
  4972.         ld      a,_NoWrite
  4973.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  4974.         ret
  4975. ;
  4976. ; Function READLN(var)
  4977. ; ENTRY Reg HL points to variable
  4978. ;
  4979. l14cb:
  4980.         db      skip
  4981. ;
  4982. ; Function READ(var)
  4983. ; ENTRY Reg HL points to variable
  4984. ; EXIT  Reg HL points to variable
  4985. ;
  4986. l14cc:
  4987.         xor     a
  4988.         ex      (sp),hl         ; Get caller
  4989.         ld      (l00e4),hl      ;ok ;FIXME ; Save it
  4990.         ex      (sp),hl
  4991.         push    hl
  4992.         ld      hl,l00c2
  4993.         ld      (l00e2),hl      ;ok ;FIXME ; Set standard device
  4994.         res     wr.bit,(hl)     ; Reset write bit
  4995.         push    af              ; Save mode
  4996.         call    l14e8           ; Read a line
  4997.         pop     af
  4998.         or      a               ; Test READLN
  4999.         jr      z,l14e6
  5000.         call    l01e1           ; Give new line if so
  5001. l14e6:
  5002.         pop     hl
  5003.         ret
  5004. ;
  5005. ; Read a line from keyboard
  5006. ;
  5007. l14e8:
  5008.         ld      b,0             ; Reset flag
  5009. l14ea:
  5010.         ld      hl,l00d1        ; Point to buffer length
  5011.         ld      a,(hl)          ; Get buffer length
  5012.         cp      _MaxBuf+1       ; Verify in range
  5013.         jr      c,l14f4
  5014.         ld      a,_MaxBuf       ; Truncate if not
  5015. l14f4:
  5016.         ld      c,a
  5017.         ld      (hl),_MaxBuf    ; Set default length
  5018.         ld      hl,(l00d2)      ;ok ;FIXME ; Get top of memory
  5019.         ld      (l00d4),hl      ;ok ;FIXME ; Unpack it
  5020. l14fd:
  5021.         ld      d,0             ; Reset character count
  5022. l14ff:
  5023.         call    readfromkbd             ; Read character
  5024.         ld      (hl),a          ; Unpack it
  5025.         ld      e,1             ; Init flag
  5026.         cp      bs              ; Test backspace
  5027.         jr      z,l153f
  5028.         ;cp     DEL             ; Test delete
  5029.         ;jr     z,l153f
  5030.         dec     e
  5031.         cp      CtrlX           ; Test ^X
  5032.         jr      z,l153f
  5033.         cp      esc             ; Test escape
  5034.         jr      z,l153f
  5035.         cp      eof             ; Test end of file
  5036.         jr      z,l1550
  5037.         cp      cr              ; Test end of line
  5038.         jr      z,l1556
  5039.         cp      ' '             ; Test printable
  5040.         jr      nc,l1533
  5041.         cp      CtrlC           ; Test ^C
  5042.         jr      nz,l14ff
  5043.         ld      a,(l00dd)       ;ok ;FIXME ; Get $C mode
  5044.         or      a               ; Test abort
  5045.         jr      z,l14ff         ; $C- - so ignore
  5046.         ld      ix,(l00e4) ;ok ;FIXME
  5047.         jp      l2016           ; Abort
  5048. ;
  5049. ; Found printable character
  5050. ;
  5051. l1533:
  5052.         ld      a,c             ; Get max
  5053.         cp      d               ; Test against count
  5054.         jr      z,l14ff         ; Yeap, ignore
  5055.         ld      a,(hl)          ; Get character
  5056.         inc     d               ; Advance counter
  5057.         inc     hl              ; Point to next storage location
  5058.         call    puttoconsole_a          ; Put to console
  5059.         jr      l14ff
  5060. ;
  5061. ; Special control detected: Backspace, DELete, ^X, ESCape
  5062. ;
  5063. l153f:
  5064.         dec     d               ; Fix count
  5065.         jp      m,l14fd         ; Ignore if at 1st position
  5066.         dec     hl
  5067.         call    l0200           ; Position cursor left
  5068.         db      bs,' ',bs
  5069.         db      null
  5070.         dec     e               ; Test backspace or delete
  5071.         jr      z,l14ff         ; Yeap
  5072.         jr      l153f           ; Else delete two characters on screen
  5073. ;
  5074. ; Found EOF
  5075. ;
  5076. l1550:
  5077.         inc     b               ; Test flag
  5078.         dec     b
  5079.         jr      z,l14ff         ; Ignore input
  5080.         jr      l155a           ; Close input line
  5081. ;
  5082. ; Found CR
  5083. ;
  5084. l1556:
  5085.         inc     b               ; Test flag
  5086.         dec     b
  5087.         jr      nz,l155e        ; Ignore EOF
  5088. l155a:
  5089.         ld      (hl),eof        ; Close line
  5090.         jr      l1566
  5091. l155e:
  5092.         call    l01e1           ; Give new line
  5093.         ld      (hl),cr         ; Close line
  5094.         inc     hl
  5095.         ld      (hl),lf
  5096. l1566:
  5097.         inc     hl
  5098.         ld      (l00d6),hl      ;ok ;FIXME ; Set top pointer
  5099.         ret
  5100. ;
  5101. ; Get character from file or console buffer
  5102. ;
  5103. l156b:
  5104.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  5105.         ld      a,(l00d0) ;ok ;FIXME
  5106.         or      a               ; Test error
  5107.         jp      nz,l15ed        ; Force EOF if so
  5108.         ld      a,(hl)
  5109.         bit     wr.bit,a        ; Test preread char
  5110.         jp      nz,l15e9        ; Fetch if so
  5111.         and     FIBtype         ; Test device
  5112.         jr      nz,l15ab        ; Yeap, standard I/O
  5113.         inc     hl              ; Point to sector buffer
  5114.         inc     hl
  5115.         ld      a,(hl)
  5116.         or      a               ; Test filled
  5117.         jp      p,l1597         ; Not yet
  5118.          push   hl
  5119.          ex de,hl
  5120.          ld     c,_setdma
  5121.          call   l19ba           ; set DTA
  5122.          pop    hl        
  5123.         ld      c,_rdseq
  5124.         push    hl
  5125.         call    l19ba           ; Read sector
  5126.         pop     hl
  5127.         ;jr     z,l1595         ; Read was successfull
  5128.          cp 128 ;EOF in NedoOS
  5129.          jr nz,l1595            ; Read was successfull
  5130.          ;jr $ ;lister.pas
  5131. ;CP/M has eofs in the end of last sector?
  5132. ;do this by hand:
  5133.         or a
  5134.         jr z,read_load_noaddeofs ;full sector
  5135. ;a=128+bytes loaded
  5136.         neg
  5137. ;a=128-bytes loaded
  5138.         ld b,a
  5139.         ld a,l
  5140.         add a,127
  5141.         ld e,a
  5142.         adc a,h
  5143.         sub e
  5144.         ld d,a
  5145.         ;ld de,TmpBuff+127      ;de= Point to buffer end
  5146.         ld a,eof;-1
  5147.         ld (de),a
  5148.         dec de
  5149.         djnz $-2
  5150. read_load_noaddeofs
  5151.  
  5152.         push    hl
  5153.         ld      de,FIB.buff-2
  5154.         add     hl,de           ; Point to buffer
  5155.         ld      (hl),eof        ; Set EOF
  5156.         pop     hl
  5157. l1595:
  5158.         xor     a
  5159.         ld      (hl),a          ; Reset buffer pointer
  5160. l1597:
  5161.         inc     (hl)            ; Bump pointer
  5162.         add     a,FIB.buff-2
  5163.         ld      e,a
  5164.         ld      d,0
  5165.         add     hl,de           ; Calculate current buffer
  5166.         ld      a,(hl)
  5167.         cp      eof             ; Test EOF
  5168.         jr      nz,l15e0        ; Nope
  5169.         ld      hl,(l00e2) ;ok ;FIXME
  5170.         inc     hl
  5171.         inc     hl
  5172.         dec     (hl)            ; Fix pointer if eof found
  5173.        ;push hl
  5174.        ; ld c,_close
  5175.        ; call BDOS_with_FCB1 ;с этим виснет lister в конце!!!
  5176.        ;pop hl
  5177.         jr      l15e0
  5178. l15ab:
  5179.         dec     a               ; Test CON:
  5180.         jr      nz,l15c9
  5181.         ld      hl,(l00d4)      ;ok ;FIXME ; Get current pointer
  5182.         ld      de,(l00d6)      ;ok ;FIXME ; Get top pointer
  5183.         or      a
  5184.         sbc     hl,de           ; Test more in buffer
  5185.         jr      c,l15bf         ; Ok
  5186.         ld      b,-1
  5187.         call    l14ea           ; Else get more
  5188. l15bf:
  5189.         ld      hl,(l00d4)      ;ok ;FIXME ; Get current pointer
  5190.         ld      a,(hl)
  5191.         inc     hl              ; Bump
  5192.         ld      (l00d4),hl ;ok ;FIXME
  5193.         jr      l15e0
  5194. l15c9:
  5195.         dec     a               ; Test KBD:
  5196.         jr      nz,l15d2
  5197.         call    l00a3           ; Read KBD
  5198.         ld      a,l
  5199.         jr      l15e0
  5200. l15d2:
  5201.         dec     a               ; Test AUX:
  5202.         dec     a
  5203.         jr      nz,l15dc
  5204.         call    l00af           ; Get from auxiliary
  5205.         ld      a,l
  5206.         jr      l15e0
  5207. l15dc:
  5208.         call    l00b5           ; Read USR
  5209.         ld      a,l
  5210. l15e0:
  5211.         ld      hl,(l00e2)      ;ok ;FIXME ; Get back FIB
  5212.         set     wr.bit,(hl)     ; Set preread flag
  5213.         inc     hl
  5214.         ld      (hl),a          ; Save character
  5215.         dec     hl
  5216.         ret
  5217. l15e9:
  5218.         inc     hl              ; Point to character buffer
  5219.         ld      a,(hl)          ; Get character
  5220.         dec     hl
  5221.         ret
  5222. l15ed:
  5223.         ld      a,eof           ; Return EOF
  5224.         ret
  5225. ;
  5226. ; Get character from current device
  5227. ; Fix up controls
  5228. ;
  5229. l15f0:
  5230.         push    hl
  5231.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  5232.         ld      a,(hl)
  5233.         and     FIBtype         ; Get device
  5234.         cp      RAMdevice       ; Test RAM
  5235.         jr      z,l1622
  5236. l15fb:
  5237.         call    l156b           ; Get character from device
  5238.         cp      ' '+1           ; Test control
  5239.         jr      nc,l160a        ; Nope
  5240.         cp      eof             ; Test EOF
  5241.         jr      z,l160a         ; Yeap
  5242.         res     wr.bit,(hl)     ; Reset preread
  5243.         jr      l15fb           ; Then synchronize
  5244. l160a:
  5245.         ld      de,Number       ; Set buffer
  5246.         ld      b,_MaxSamp      ; Set max
  5247. l160f:
  5248.         push    bc
  5249.         push    de
  5250.         call    l156b           ; Get character from device
  5251.         pop     de
  5252.         pop     bc
  5253.         cp      ' '+1           ; Test control
  5254.         jr      c,l1620         ; Yeap, end if so
  5255.         res     wr.bit,(hl)     ; No preread
  5256.         ld      (de),a          ; save character
  5257.         inc     de
  5258.         djnz    l160f
  5259. l1620:
  5260.         xor     a
  5261.         ld      (de),a          ; Close buffer
  5262. l1622:
  5263.         pop     hl
  5264.         ret
  5265. ;
  5266. ; Check negative sign of ASCII number
  5267. ; ENTRY Location NUMBER filled
  5268. ; EXIT  Reg IX points to number buffer
  5269. ;       Reg B holds 0 on no negative sign
  5270. ;               and 1 on negative sign found
  5271. ;       Zero flag indicates empty buffer
  5272. ;
  5273. l1624:
  5274.         ld      ix,Number       ; Init pointer
  5275.         ld      a,(ix)          ; Get character
  5276.         or      a
  5277.         ret     z               ; Exit if zero
  5278.         ld      b,0
  5279.         cp      '-'             ; Test negative sign
  5280.         ret     nz              ; Nope
  5281.         inc     b               ; Fix result
  5282.         inc     ix              ; Skip pointer
  5283.         ret
  5284. ;
  5285. ; Fix number conversion for error
  5286. ; ENTRY Reg IX points behind number
  5287. ;       Carry set reflects overflow
  5288. ; EXIT  Carry set indicates error
  5289. ;       IORESULT set to error 010H
  5290. ;
  5291. l1636:
  5292.         jr      c,l163d         ; Fall into error
  5293.         ld      a,(ix)          ; Test correct end
  5294.         or      a
  5295.         ret     z               ; Yeap
  5296. l163d:
  5297.         ld      a,_IllNum
  5298.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  5299.         scf
  5300.         ret
  5301. ;
  5302. ; Get character from input READ(char)
  5303. ; ENTRY Reg HL points to character variable
  5304. ;
  5305. l1644:
  5306.         push    hl              ; Save pointer
  5307.         call    l156b           ; Get character
  5308.         res     wr.bit,(hl)     ; Reset preread
  5309.         pop     hl              ; Get back pointer
  5310.         ld      (hl),a          ; Save character
  5311.         ret
  5312. ;
  5313. ; Get byte from input READ(byte)
  5314. ; ENTRY Reg HL points to byte variable
  5315. ;
  5316. l164d:
  5317.         db      skip            ; Set byte flag
  5318. ;
  5319. ; Get integer from input READ(integer)
  5320. ; ENTRY Reg HL points to integer variable
  5321. ;
  5322. l164e:
  5323.         xor     a               ; Reset byte flag
  5324.         ld      c,a
  5325.         push    bc
  5326.         call    l15f0           ; Get number input
  5327.         pop     bc
  5328.         call    l1624           ; Test sign
  5329.         ret     z               ; Empty number, exit
  5330.         push    bc
  5331.         push    hl
  5332.         call    cnv_int         ; Convert ASCII to integer
  5333.         pop     de
  5334.         pop     bc
  5335.         call    l1636           ; Test error
  5336.         ret     c               ; Yeap, exit
  5337.         dec     b               ; Test negative sign
  5338.         call    z,l0783         ; Negate if so
  5339.         ex      de,hl
  5340.         ld      (hl),e          ; Save low or byte
  5341.         inc     c
  5342.         dec     c               ; Test byte
  5343.         jr      nz,l1670        ; Skip if so
  5344.         inc     hl
  5345.         ld      (hl),d          ; Save high on integer
  5346. l1670:
  5347.         ex      de,hl
  5348.         ret
  5349. ;
  5350. ; Get real from input READ(real)
  5351. ; ENTRY Reg HL points to real variable
  5352. ;
  5353. l1672:
  5354.         call    l15f0           ; Get ASCII number
  5355.         call    l1624           ; Test sign
  5356.         ret     z               ; Empty number, exit
  5357.         push    bc
  5358.         push    hl
  5359.         call    cnv_flp         ; Convert to real
  5360.         exx
  5361.         pop     hl
  5362.         pop     bc
  5363.         call    l1636           ; Test error
  5364.         ret     c               ; Yeap, exit
  5365.         dec     b               ; Test negative sign
  5366.         exx
  5367.         call    z,l0a8f         ; Negate if so
  5368.         exx
  5369.         jp      l05d1           ; Save real number
  5370. ;
  5371. ; Get string from input READ(string[max])
  5372. ; ENTRY Reg HL points to string variable
  5373. ;       Reg B holds max characters in string
  5374. ;
  5375. l168e:
  5376.         push    hl              ; Save pointer
  5377.         ex      de,hl
  5378.         ld      c,0             ; Clear character count
  5379. l1692:
  5380.         push    bc
  5381.         push    de
  5382.         call    l156b           ; Get character
  5383.         pop     de
  5384.         pop     bc
  5385.         cp      cr              ; Test end of line
  5386.         jr      z,l16a8
  5387.         cp      eof             ; Test end of file
  5388.         jr      z,l16a8
  5389.         res     wr.bit,(hl)     ; Reset preread
  5390.         inc     c               ; Advance count
  5391.         inc     de              ; Advance pointer
  5392.         ld      (de),a
  5393.         djnz    l1692
  5394. l16a8:
  5395.         pop     hl              ; Get back pointer
  5396.         ld      (hl),c          ; Set length
  5397.         ret
  5398. ;
  5399. ; Handle end of line after READLN from file
  5400. ;
  5401. l16ab:
  5402.         call    l156b           ; Get character
  5403.         cp      eof             ; Test end of file
  5404.         jr      z,l16c5
  5405.         res     wr.bit,(hl)     ; Reset preread
  5406.         cp      lf              ; Test new line
  5407.         jr      z,l16c5
  5408.         cp      cr              ; Wait for end of line
  5409.         jr      nz,l16ab
  5410.         call    l156b
  5411.         cp      lf              ; Maybe new line
  5412.         jr      nz,l16c5
  5413.         res     wr.bit,(hl)     ; Reset preread if so
  5414. l16c5:
  5415.         ret
  5416. ;
  5417. ; Output character to device
  5418. ; ENTRY Accu holds character
  5419. ;
  5420. l16c6:
  5421.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  5422.         ld      c,a             ; Save character
  5423.         ld      a,(l00d0) ;ok ;FIXME
  5424.         or      a               ; Test I/O error
  5425.         ret     nz              ; Exit if so
  5426.         ld      a,(hl)          ; Get type
  5427.         and     FIBtype         ; Test device
  5428.         jr      nz,l16e4        ; Yeap
  5429.         inc     hl              ; Point to sector buffer
  5430.         inc     hl
  5431.         push    hl
  5432.         ld      a,(hl)          ; Get pointer
  5433.         add     a,FIB.buff-2
  5434.         ld      e,a
  5435.         ld      d,0
  5436.         add     hl,de           ; Make pointer absolute
  5437.         ld      (hl),c          ; Save character
  5438.         pop     hl
  5439.         inc     (hl)            ; Advance count
  5440.         ret     p               ; Still in range
  5441.         jr      l170c           ; Write record
  5442. l16e4:
  5443.         cp      RAMdevice       ; Test store to RAM
  5444.         jr      z,l16fd         ; Yeap
  5445.         pop     hl
  5446.         ld      b,0
  5447.         push    bc
  5448.         push    hl
  5449.         dec     a               ; 1=CON:
  5450.         jp      z,l00a6         ; Put to console
  5451.         dec     a               ; 3=LST:
  5452.         dec     a
  5453.         jp      z,l00a9         ; Put to printer
  5454.         dec     a               ; 4=AUX:
  5455.         jp      z,l00ac         ; Put to auxiliary
  5456.                                 ; 5=USR:
  5457.         jp      l00b2           ; Put to console
  5458. l16fd:
  5459.         ld      hl,(l00e8)      ;ok ;FIXME ; Get string pointer
  5460.         ld      a,(l00ea)       ;ok ;FIXME ; Get max length
  5461.         cp      (hl)            ; Test in range
  5462.         ret     z               ; Nope, exit
  5463.         inc     (hl)            ; Bump count
  5464.         ld      e,(hl)
  5465.         ld      d,0
  5466.         add     hl,de           ; Build address
  5467.         ld      (hl),c          ; Store character
  5468.         ret
  5469. ;
  5470. ; Write sector to file if any item in buffer
  5471. ;
  5472. l170c:
  5473.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  5474.         inc     hl
  5475.         inc     hl
  5476.         ld      a,(hl)          ; Get record pointer
  5477.         or      a               ; Test any in buffer
  5478.         ret     z               ; Nope, exit
  5479.         ld      (hl),0          ; Clear pointer
  5480.         ld      c,_wrseq
  5481.         call    l19ba           ; Write record
  5482.         ret     z               ; Ok, no errr
  5483.         ld      a,_WrErr
  5484.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  5485.         ret
  5486. ;
  5487. ; Write character to device
  5488. ; WRITE(char)
  5489. ; ENTRY Reg L holds character
  5490. ;
  5491. l1722:
  5492.         ld      a,l             ; Get character
  5493.         jp      l16c6           ; Put it
  5494. ;
  5495. ; Write integer to device
  5496. ; WRITE(int)
  5497. ; WRITE(int:m)
  5498. ; ENTRY Integer on stack
  5499. ;       Reg HL holds digit count (zero without count)
  5500. ;
  5501. l1726:
  5502.         pop     bc
  5503.         pop     de
  5504.         push    bc
  5505.         ld      ix,(l00d2)      ;ok ;FIXME ; Get top of memory for buffer
  5506.         bit     sgn.bit,h       ; Test sign of count
  5507.         jr      z,l1737         ; >= 0
  5508.         call    l0783           ; Negate
  5509.         ex      de,hl           ; Swap values
  5510.         jr      l1745
  5511. l1737:
  5512.         ex      de,hl
  5513.         bit     sgn.bit,h       ; Test sign of number
  5514.         jr      z,l1745         ; >= 0
  5515.         call    l0783           ; Negate
  5516.         ld      (ix),'-'        ; Init sign
  5517.         inc     ix
  5518. l1745:
  5519.         push    de
  5520.         call    l07c6           ; Convert integer to ASCII
  5521. l1749:
  5522.         pop     hl
  5523.         call    l04c8           ; Get byte from integer
  5524.         ld      de,(l00d2)      ;ok ;FIXME ; Get back top of memory
  5525.         push    ix
  5526.         pop     hl
  5527.         or      a
  5528.         sbc     hl,de           ; Calculate length of string
  5529.         ld      c,l
  5530.         ex      de,hl
  5531. l1759:
  5532.         sub     c               ; Test against count
  5533.         jr      c,l176a         ; Ignore if out of range
  5534.         jr      z,l176a
  5535.         ld      b,a             ; Save count
  5536.         push    hl
  5537. l1760:
  5538.         ld      a,' '
  5539.         push    bc
  5540.         call    l16c6           ; Blank leading places
  5541.         pop     bc
  5542.         djnz    l1760
  5543.         pop     hl
  5544. l176a:
  5545.         ld      b,c             ; Get back length
  5546.         inc     b
  5547. l176c:
  5548.         dec     b
  5549.         ret     z
  5550.         ld      a,(hl)
  5551.         push    bc
  5552.         push    hl
  5553.         call    l16c6           ; Type digits
  5554.         pop     hl
  5555.         pop     bc
  5556.         inc     hl
  5557.         jr      l176c
  5558. ;
  5559. ; Formatted write
  5560. ; WRITE(real)
  5561. ; WRITE(real:n)
  5562. ; WRITE(real:n:m)
  5563. ; ENTRY Reg HL holds fix comma places (-1 on none)
  5564. ;       Stack holds decimal places and real
  5565. ;       (Without decimal places defaults to 24)
  5566. ;
  5567. l1779:
  5568.         pop     bc
  5569.         pop     de              ; Get places
  5570.         exx
  5571.         pop     hl              ; Get number
  5572.         pop     de
  5573.         pop     bc
  5574.         exx
  5575.         push    bc
  5576.         ld      ix,(l00d2)      ;ok ;FIXME ; Get top of memory for buffer
  5577.         push    de
  5578.         call    l1027           ; Convert real to ASCII
  5579.         jr      l1749
  5580. ;
  5581. ; Boolean write
  5582. ; WRITE(bool)
  5583. ; WRITE(bool:m)
  5584. ; ENTRY Reg HL holds places (0 on none)
  5585. ;       Stack holds boolean
  5586. ;
  5587. l178b:
  5588.         pop     bc
  5589.         pop     de              ; Get boolean
  5590.         push    bc
  5591.         call    l04c8           ; Get byte from integer
  5592.         bit     _LB,e           ; Test bit
  5593.         ld      hl,l17a1
  5594.         ld      c,l17a1.l
  5595.         jr      nz,l1759        ; It is TRUE
  5596.         ld      hl,l17a5
  5597.         ld      c,l17a5.l
  5598.         jr      l1759           ; Tell FALSE
  5599. ;
  5600. l17a1:
  5601.         db      'TRUE'
  5602. l17a1.l equ     $-l17a1
  5603. l17a5:
  5604.         db      'FALSE'
  5605. l17a5.l equ     $-l17a5
  5606. ;
  5607. ; String and formatted character write
  5608. ; WRITE(string)
  5609. ; WRITE(string:m)
  5610. ; WRITE(char:m)
  5611. ; ENTRY Reg HL holds places (0 on none)
  5612. ;       Stack holds string (chracter=string with length=1)
  5613. ;
  5614. l17aa:
  5615.         call    l04c8           ; Get byte from integer for places
  5616.         ld      hl,2
  5617.         add     hl,sp           ; Fix stack
  5618.         ld      c,(hl)          ; Get length
  5619.         inc     hl
  5620.         call    l1759           ; Print right justified
  5621.         pop     de              ; Get back caller
  5622.         ld      sp,hl           ; Reset stack
  5623.         push    de
  5624.         ret
  5625. ;
  5626. ; Immediate string write
  5627. ; WRITE('string')
  5628. ; ENTRY Stack holds string starting with length
  5629. ;
  5630. l17ba:
  5631.         pop     hl              ; Get pointer to string
  5632.         ld      a,(hl)          ; Get length
  5633.         inc     hl
  5634.         or      a               ; Test any
  5635.         jr      z,l17cc
  5636.         ld      b,a             ; save length if so
  5637. l17c1:
  5638.         ld      a,(hl)          ; Get character
  5639.         push    bc
  5640.         push    hl
  5641.         call    l16c6           ; Write it
  5642.         pop     hl
  5643.         pop     bc
  5644.         inc     hl
  5645.         djnz    l17c1
  5646. l17cc:
  5647.         jp      (hl)
  5648. ;
  5649. ; Give new line
  5650. ; WRITELN{...}
  5651. ;
  5652. l17cd:
  5653.         ld      a,cr
  5654.         call    l16c6           ; Give return
  5655.         ld      a,lf
  5656.         jp      l16c6           ; Followed by line feed
  5657. ;
  5658. ; The logical delimiter functions
  5659. ; Function SEEKEOLN(device):boolean
  5660. ; ENTRY Reg HL points to FIB
  5661. ; EXIT  Reg HL holds TRUE or FALSE
  5662. ;
  5663. l17d7:
  5664.         ld      de,1*256+cr     ; Set CR
  5665.         jr      l17e9
  5666. ;
  5667. ; Function EOLN(device):boolean
  5668. ;
  5669. l17dc:
  5670.         ld      de,cr
  5671.         jr      l17e9
  5672. ;
  5673. ; Function SEEKEOF(device):boolean
  5674. ;
  5675. l17e1:
  5676.         ld      de,1*256+eof    ; Set EOF
  5677.         jr      l17e9
  5678. ;
  5679. ; Function EOF(device):boolean
  5680. ;
  5681. l17e6: ;???
  5682.         ld      de,eof
  5683. l17e9:
  5684.         ld      (l00e2),hl      ;ok ;FIXME ; Set device
  5685.         bit     in.bit,(hl)     ; Test input possible
  5686.         jr      z,l180c         ; Nope
  5687. l17f0:
  5688.         push    de
  5689.         call    l156b           ; Get character
  5690.         pop     de
  5691.         cp      e               ; Test end found
  5692.         jr      z,l1808         ; Yeap
  5693.         cp      eof             ; Test end of file
  5694.         jr      z,l1808         ; Force TRUE if so
  5695.         cp      ' '+1           ; Test control
  5696.         jr      nc,l180c        ; Nope
  5697.         inc     d               ; Test control to be checked
  5698.         dec     d
  5699.         jr      z,l180c         ; Yeap
  5700.         res     wr.bit,(hl)     ; Reset preread
  5701.         jr      l17f0
  5702. l1808:
  5703.         ld      hl,_TRUE        ; Return TRUE
  5704.         ret
  5705. l180c:
  5706.         ld      hl,FALSE        ; Return FALSE
  5707.         ret
  5708. ;
  5709. ; Prepare typed files
  5710. ; Procedure REWRITE(typed_file)
  5711. ; ENTRY Reg HL points to FIB
  5712. ;       Reg DE holds length of record
  5713. ;
  5714. l1810:
  5715.         db      skip
  5716. ;
  5717. ; Procedure RESET(typed_file)
  5718. ;
  5719. l1811:
  5720.         xor     a
  5721.         ld      (l00e8),a       ;ok ;FIXME ; Set mode (0=RESET)
  5722.         ld      (l00e6),de      ;ok ;FIXME ; Save record length
  5723.         call    l187a           ; Close file
  5724.         ld      a,(l00d0)       ;ok ;FIXME ; Test error
  5725.         or      a
  5726.         ret     nz              ; End if so
  5727.         call    l1430           ; Set up FIB ;opens/creates file!!!
  5728.         ld      a,(l00d0)       ;ok ;FIXME ; Test error
  5729.         or      a
  5730.         ret     nz              ; End if so
  5731.         ld      hl,(l00e2)      ;ok ;FIXME ; Init FIB flag
  5732.         ld      (hl),_.in+_.out+_.read
  5733.         inc     hl
  5734.         inc     hl
  5735.         ld      (hl),a          ; Init record pointer
  5736.         ld      de,FIB.cur-2
  5737.         add     hl,de           ; Point to current record
  5738.         ld      (hl),a          ; Clear it
  5739.         inc     hl
  5740.         ld      (hl),a
  5741.         ld      de,FIB.FCB+_rrn-FIB.cur-1
  5742.         add     hl,de           ; Point to random record
  5743.         ld      (hl),a          ; Clear it
  5744.         inc     hl
  5745.         ld      (hl),a
  5746.         ld      de,FIB.rec-FIB.FCB-_rrn-1
  5747.         add     hl,de           ; Point to FIB record
  5748.         ld      a,(l00e8) ;ok ;FIXME
  5749.         or      a               ; Test mode
  5750.         jr      nz,l1864        ; Skip RESET
  5751. ;
  5752. ; Perform RESET
  5753. ;
  5754.         push    hl
  5755.         ld      bc,FixRecLen    ; Set four bytes
  5756.         xor     a
  5757.         call    l1909           ; Prepare read
  5758.         pop     hl
  5759.         inc     hl
  5760.         inc     hl
  5761.         ld      c,(hl)          ; Point to max records
  5762.         inc     hl
  5763.         ld      b,(hl)
  5764.         ld      hl,(l00e6) ;ok ;FIXME
  5765.         or      a
  5766.         sbc     hl,bc           ; Test agianst tem in file
  5767.         ret     z               ; Correct value
  5768.         ld      a,_InvRec
  5769.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  5770.         ret
  5771. ;
  5772. ; Perform REWRITE
  5773. ;
  5774. l1864:
  5775.         push    hl
  5776.         xor     a
  5777.         ld      (hl),a          ; Clear record
  5778.         inc     hl
  5779.         ld      (hl),a
  5780.         inc     hl
  5781.         ld      de,(l00e6)      ;ok ;FIXME ; Fetch length
  5782.         ld      (hl),e          ; Store into FIB
  5783.         inc     hl
  5784.         ld      (hl),d
  5785.         pop     hl
  5786.         ld      bc,FixRecLen
  5787.         ld      a,Rec.New+Rec.Wr
  5788.         jp      l1909           ; Prepare write
  5789. ;
  5790. ; Procedure CLOSE(typed_file)
  5791. ; ENTRY Reg HL points to FIB
  5792. ;
  5793. l187a:
  5794.         ld      (l00e2),hl      ;ok ;FIXME ; Save FIB
  5795.         ld      a,(hl)          ; Get state
  5796.         and     _.in+_.out      ; Test any action
  5797.         ret     z               ; Nope
  5798.         call    l19ae           ; Write record if requested
  5799.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  5800.         ld      de,FIB.FCB+_rrn
  5801.         add     hl,de           ; Point to random recird
  5802.         xor     a
  5803.         ld      (hl),a          ; Clear it
  5804.         inc     hl
  5805.         ld      (hl),a
  5806.         ld      de,-FIB.FCB-_rrn+1
  5807.         add     hl,de           ; Point to record
  5808.         ld      (hl),a          ; Clear it
  5809.         inc     hl
  5810.         inc     hl
  5811.         ld      bc,FixRecLen
  5812.         ld      a,Rec.Wr
  5813.         call    l1909           ; Prepare write
  5814.         call    l19ae           ; Write if requested
  5815.         jp      l1481           ; Close file
  5816. ;
  5817. ; Prepare write to record file
  5818. ; ENTRY Reg HL points to FIB
  5819. ;
  5820. l18a4:
  5821.         ex      (sp),hl
  5822.         ld      (l00e4),hl      ;ok ;FIXME ; Save caller
  5823.         ex      (sp),hl
  5824.         ld      (l00e2),hl      ;ok ;FIXME ; Save FIB
  5825.         ld      a,(hl)
  5826.         and     _.in+_.out      ; Test I/O allowed
  5827.         ret     nz              ; Yeap
  5828. l18b0:
  5829.         ld      a,_BlkErr
  5830.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  5831.         ret
  5832. ;
  5833. ; Get structure from input READ(type)
  5834. ; ENTRY Reg HL points to FIB
  5835. ;
  5836. l18b6:
  5837.         ld      a,(l00d0)       ;ok ;FIXME ; Get error
  5838.         or      a               ; Test previous
  5839.         ret     nz              ; Yeap
  5840.         push    hl
  5841.         call    l1a5a           ; Get record data
  5842.         ex      de,hl
  5843.         or      a
  5844.         sbc     hl,de           ; Test against last record
  5845.         pop     hl
  5846.         jr      nc,l18d6        ; Error
  5847.         xor     a
  5848.         call    l1909           ; Read
  5849. l18ca:
  5850.         ld      hl,(l00e2)      ;ok ;FIXME ; Get back FIB
  5851.         ld      de,FIB.cur
  5852.         add     hl,de
  5853.         inc     (hl)            ; Bump record
  5854.         ret     nz
  5855.         inc     hl
  5856.         inc     (hl)
  5857.         ret
  5858. l18d6:
  5859.         ld      a,_IllEOF
  5860.         ld      (l00d0),a       ; Set error
  5861.         ret
  5862. ;
  5863. ; Put structure to output WRITE(type)
  5864. ; ENTRY Reg HL points to FIB
  5865. ;
  5866. l18dc:
  5867.         ld      a,(l00d0)       ;ok ;FIXME ; Get error
  5868.         or      a               ; Test previous
  5869.         ret     nz              ; Yeap
  5870.         push    hl
  5871.         call    l1a5a           ; Get record data
  5872.         or      a
  5873.         sbc     hl,de           ; Test same size
  5874.         ld      a,Rec.Wr
  5875.         jr      nz,l18fc
  5876.         ld      hl,(l00e2) ;ok ;FIXME
  5877.         ld      de,FIB.rec
  5878.         add     hl,de           ; Point to record
  5879.         inc     (hl)            ; Bump it
  5880.         jr      nz,l18fa
  5881.         inc     hl
  5882.         inc     (hl)
  5883.         jr      z,l1902         ; Overflow error
  5884. l18fa:
  5885.         ld      a,Rec.New+Rec.Wr
  5886. l18fc:
  5887.         pop     hl
  5888.         call    l1909           ; Execute write
  5889.         jr      l18ca
  5890. l1902:
  5891.         pop     hl
  5892.         ld      a,_OvflErr
  5893.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  5894.         ret
  5895. ;
  5896. ; Perform record IO
  5897. ; ENTRY Reg HL points to FIB record field
  5898. ;       Reg BC holds record length
  5899. ;       (Four on CLOSE, RESET and REWRITE)
  5900. ;       Accu holds code :
  5901. ;               0 : On RESET and READ
  5902. ;               1 : On CLOSE and WRITE
  5903. ;               3 : On WRITE and REWRITE
  5904. ;
  5905. l1909:
  5906.         ld      (l00e9),a       ;ok ;FIXME ; Save code
  5907.         ex      de,hl
  5908. l190d:
  5909.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  5910.         bit     rd.bit,(hl)     ; Test known buffer
  5911.         jr      z,l1943         ; Nope
  5912.         res     rd.bit,(hl)     ; Reset bit
  5913.         ld      a,(l00e9)       ;ok ;FIXME ; Get mode
  5914.         bit     Rec.Wr.bit,a    ; Test write
  5915.         jr      z,l1935         ; Nope, so read
  5916.         inc     hl
  5917.         inc     hl
  5918.         ld      a,(hl)          ; Get record pointer
  5919.         dec     hl
  5920.         dec     hl
  5921.         or      a
  5922.         jr      nz,l1935        ; Not empty, so read
  5923.         ld      a,(l00e9)       ;ok ;FIXME ; Get code
  5924.         bit     Rec.New.bit,a   ; Test new
  5925.         jr      nz,l1943        ; Yeap
  5926.         ld      a,b             ; Get counter
  5927.         or      a
  5928.         jr      nz,l1943
  5929.         ld      a,c             ; Test new
  5930.         or      a
  5931.         jp      m,l1943
  5932. l1935:
  5933.         push    bc
  5934.         push    de
  5935.         ld      c,_rndrd
  5936.         call    l19ba           ; Read record
  5937.         pop     de
  5938.         pop     bc
  5939.         ;jr nz,$
  5940.         jr      nz,l1991        ; Error return
  5941.         ld      hl,(l00e2)      ;ok ;FIXME ; Get back FIB
  5942. l1943:
  5943.         ld      a,(l00e9)       ;ok ;FIXME ; Get mode
  5944.         bit     Rec.Wr.bit,a    ; Test write allowed
  5945.         jr      z,l194c         ; Nope
  5946.         set     wr.bit,(hl)     ; Set bit
  5947. l194c:
  5948.         inc     hl
  5949.         inc     hl
  5950.         ld      a,(hl)          ; Get pointer to buffer
  5951.         add     a,FIB.buff-2
  5952.         push    de
  5953.         ld      e,a
  5954.         ld      d,0
  5955.         add     hl,de           ; Get address of buffer
  5956.         pop     de
  5957.         sub     FIB.buff-2      ; Reset pointer
  5958.         call    l199a           ; Swap pointer
  5959. l195c:
  5960.         ldi                     ; move bytes
  5961.         jp      po,l1966        ; Test done
  5962.         inc     a               ; Bump pointer
  5963.         jp      p,l195c         ; Test done
  5964.         dec     a
  5965. l1966:
  5966.         inc     a
  5967.         call    l199a           ; Swap back
  5968.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  5969.         inc     hl
  5970.         inc     hl
  5971.         and     NOMSB           ; Test remainder in buffer
  5972.         ld      (hl),a
  5973.         jr      nz,l198a        ; Yeap
  5974.         push    bc
  5975.         push    de
  5976.         push    hl
  5977.         call    l19ae           ; Write record
  5978.         pop     hl
  5979.         pop     de
  5980.         pop     bc
  5981.         jr      nz,l1994        ; Error return
  5982.         push    de
  5983.         ld      de,FIB.FCB+_rrn-2
  5984.         add     hl,de           ; Point to record
  5985.         pop     de
  5986.         inc     (hl)            ; Advance it
  5987.         jr      nz,l198a
  5988.         inc     hl
  5989.         inc     (hl)
  5990. l198a:
  5991.         ld      a,b             ; Test all done
  5992.         or      c
  5993.         jp      nz,l190d        ; Nope
  5994.         ex      de,hl
  5995.         ret
  5996. l1991:
  5997.         ld      a,_IllEOF
  5998.         db      skip.2
  5999. l1994:
  6000.         ld      a,_WrErr
  6001.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  6002.         ret
  6003. ;
  6004. ; Swap record pointers on request
  6005. ; ENTRY Reg HL and DE hold pointer
  6006. ; EXIT  Register swapped on write selected
  6007. ;
  6008. l199a:
  6009.         push    af
  6010.         ld      a,(l00e9)       ;ok ;FIXME ; Get mode
  6011.         bit     Rec.Wr.bit,a    ; Test selection
  6012.         jr      z,l19a3
  6013.         ex      de,hl           ; Swap
  6014. l19a3:
  6015.         pop     af
  6016.         ret
  6017. ;
  6018. ; Force record write
  6019. ; Procedure FLUSH(type)
  6020. ; ENTRY Reg HL holds FIB
  6021. ;
  6022. l19a5:
  6023.         ld      (l00e2),hl      ;ok ;FIXME ; Save FIB
  6024.         call    l19ae           ; Write if possible
  6025.         ret     z
  6026.         jr      l1994           ; Set error
  6027. ;
  6028. ; Write random record if select, set read
  6029. ;
  6030. l19ae:
  6031.         ld      c,_rndwr        ; Set OS function
  6032.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  6033.         set     rd.bit,(hl)     ; Set read bit
  6034.         bit     wr.bit,(hl)     ; Test write
  6035.         ret     z               ; Nope
  6036.         res     wr.bit,(hl)     ; Reset and write
  6037. ;
  6038. ; Execute file function
  6039. ; ENTRY Reg C holds file function
  6040. ; EXIT  Zero flag reflects state of function
  6041. ;       Accu holds BDOS code
  6042. ;
  6043. l19ba:
  6044.         ld      hl,(l00e2)      ;ok ;FIXME ; Load FIB
  6045.         push    hl
  6046.         push    bc
  6047.         ld      de,FIB.buff
  6048.         add     hl,de           ; Point to buffer
  6049.         ex      de,hl
  6050.         ld      c,_setdma
  6051.         call    BDOS            ; Set disk buffer
  6052.         pop     bc
  6053.         pop     hl
  6054.         ld      de,FIB.FCB
  6055.         add     hl,de           ; Point to FCB
  6056.         ex      de,hl
  6057.         call    BDOS            ; Execute OS function
  6058.         or      a               ; Build result
  6059.         ret
  6060. ;
  6061. ; Procedure SEEK(file,record)
  6062. ; ENTRY Reg HL holds record seeked for
  6063. ;       FIB pushed onto stack
  6064. ;
  6065. l19d5:
  6066.         pop     bc
  6067.         pop     de
  6068.         ld      (l00e2),de      ;ok ;FIXME ; Save FIB
  6069.         push    bc
  6070.         push    hl
  6071.         call    l1a5a           ; Get FIB data
  6072.         pop     de
  6073.         or      a
  6074.         sbc     hl,de           ; Test record less size
  6075.         jr      c,l1a26         ; Error if so
  6076.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  6077.         ld      bc,FIB.reclen   ; Point to length of record
  6078.         add     hl,bc
  6079.         ld      c,(hl)          ; Get record
  6080.         inc     hl
  6081.         ld      b,(hl)
  6082.         inc     hl
  6083.         ld      (hl),e          ; Save record number
  6084.         inc     hl
  6085.         ld      (hl),d
  6086.         call    l1a2c           ; Multiply it
  6087.         ld      bc,FixRecLen
  6088.         add     hl,bc           ; Adjust for header
  6089.         jr      nc,l19fe
  6090.         inc     de
  6091. l19fe:
  6092.         ld      a,l
  6093.         and     NOMSB           ; Get record pointer
  6094.         add     hl,hl           ; * 2
  6095.         ex      de,hl
  6096.         adc     hl,hl
  6097.         ex      de,hl
  6098.         ld      d,e             ; / 256
  6099.         ld      e,h
  6100.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  6101.         inc     hl
  6102.         inc     hl
  6103.         ld      (hl),a          ; Store record pointer
  6104.         ld      bc,FIB.FCB+_rrn-2
  6105.         add     hl,bc           ; Point to random record
  6106.         ld      c,(hl)          ; Get it
  6107.         inc     hl
  6108.         ld      b,(hl)
  6109.         ex      de,hl
  6110.         or      a
  6111.         sbc     hl,bc           ; Test record already set
  6112.         add     hl,bc
  6113.         ret     z               ; Yeap
  6114.         push    de
  6115.         push    hl
  6116.         call    l19ae           ; Write record
  6117.         pop     de
  6118.         pop     hl
  6119.         ld      (hl),d          ; Set current record
  6120.         dec     hl
  6121.         ld      (hl),e
  6122.         ret
  6123. l1a26:
  6124.         ld      a,_SeekEOF
  6125.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  6126.         ret
  6127. ;
  6128. ; Multiply record number by record length
  6129. ; ENTRY Reg BC holds length of record
  6130. ;       Reg DE holds number of record
  6131. ; EXIT  Reg HL holds the product of both
  6132. ;
  6133. l1a2c:
  6134.         push    de              ; Copy number
  6135.         exx
  6136.         pop     hl              ; Get copy
  6137.         exx
  6138.         ld      hl,0            ; Init result
  6139.         ld      d,h
  6140.         ld      e,l
  6141.         ld      a,16            ; Set bit length
  6142. l1a37:
  6143.         add     hl,hl           ; Shift result
  6144.         ex      de,hl
  6145.         adc     hl,hl           ; Treat as 32 bit number
  6146.         ex      de,hl
  6147.         exx
  6148.         add     hl,hl           ; Shift number
  6149.         exx
  6150.         jr      nc,l1a45
  6151.         add     hl,bc           ; Fix for carry
  6152.         jr      nc,l1a45
  6153.         inc     de
  6154. l1a45:
  6155.         dec     a
  6156.         jr      nz,l1a37        ; Loop on
  6157.         ret
  6158. ;
  6159. ; Function EOF(device):boolean (untyped)
  6160. ;
  6161. l1a49::
  6162.         call    l1a5d           ; Get size of file
  6163.         or      a
  6164.         sbc     hl,de           ; Test end
  6165.         ld      hl,FALSE
  6166.         ret     nz              ; Return FALSE if not
  6167.         inc     hl              ; Fix for TRUE
  6168.         ret
  6169. ;
  6170. ; Get record position of file
  6171. ; Function FILEPOS(file):integer
  6172. ; ENTRY Reg HL holds FIB
  6173. ; EXIT  Reg HL holds current record
  6174. ;
  6175. l1a55:
  6176.         call    l1a5d           ; Get size of file
  6177.         ex      de,hl           ; Into integer result
  6178.         ret
  6179. ;
  6180. ; Get record data of file
  6181. ; EXIT  Reg HL holds size of file
  6182. ;       Reg DE holds current record
  6183. ;       Reg BC holds record length
  6184. ;
  6185. l1a5a:
  6186.         ld      hl,(l00e2)      ;ok ;FIXME ; Load FIB
  6187. ;
  6188. ; Get size of file
  6189. ; Function FILESIZE(file):integer
  6190. ; ENTRY Reg HL holds FIB
  6191. ; EXIT  Reg HL holds size of file in terms of records
  6192. ;       Reg DE holds current record
  6193. ;       Reg BC holds length of record
  6194. ;
  6195. l1a5d:
  6196.         ld      de,FIB.rec
  6197.         add     hl,de           ; Point to records
  6198.         ld      e,(hl)          ; Get number of records
  6199.         inc     hl
  6200.         ld      d,(hl)
  6201.         inc     hl
  6202.         push    de
  6203.         ld      c,(hl)          ; Get record length
  6204.         inc     hl
  6205.         ld      b,(hl)
  6206.         inc     hl
  6207.         ld      e,(hl)          ; Get current record
  6208.         inc     hl
  6209.         ld      d,(hl)
  6210.         pop     hl
  6211.         ret
  6212. ;
  6213. ; Prepare untyped files
  6214. ; Procedure REWRITE(un_typed_file)
  6215. ; ENTRY Reg HL points to FIB
  6216. ;
  6217. l1a6f:
  6218.         db      skip
  6219. ;
  6220. ; Procedure RESET(un_typed_file)
  6221. ;
  6222. l1a70:
  6223. ;TODO полностью переписать!!!
  6224.         xor     a
  6225.         ld      (l00e8),a       ;ok ;FIXME ; Save mode (0=RESET)
  6226.         call    l1ab0           ; Close open file
  6227.         ld      a,(l00d0) ;ok ;FIXME
  6228.         or      a               ; Test error
  6229.         ret     nz              ; Exit if so
  6230.         call    l1430           ; Fix FIB
  6231.         ld      a,(l00d0) ;ok ;FIXME
  6232.         or      a               ; Test error
  6233.         ret     nz              ; Exit if so
  6234.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  6235.         ld      (hl),_.in+_.out ; Set flag
  6236.         push    hl
  6237.         ld      de,FIB.FCB
  6238.         add     hl,de           ; Point to FCB
  6239.         ex      de,hl
  6240.         ld      c,_filsiz
  6241.         call    BDOS            ; Get size of file
  6242.         pop     hl
  6243.         ld      de,FIB.FCB+_rrn
  6244.         add     hl,de           ; Point to size
  6245.         xor     a
  6246.         ld      c,(hl)          ; Get size
  6247.         ld      (hl),a          ; Reset size
  6248.         inc     hl
  6249.         ld      b,(hl)
  6250.         ld      (hl),a
  6251.         ld      de,FIB.rec-FIB.FCB-_rrn-1
  6252.         add     hl,de           ; Point to record number
  6253.         ld      (hl),c          ; Set it
  6254.         inc     hl
  6255.         ld      (hl),b
  6256.         inc     hl
  6257.         ld      (hl),RecLng     ; Set standard record
  6258.         inc     hl
  6259.         ld      (hl),a
  6260.         inc     hl
  6261.         ld      (hl),a          ; Init current record
  6262.         inc     hl
  6263.         ld      (hl),a
  6264.         ret
  6265. ;
  6266. ; Close untyped file
  6267. ; ENTRY Reg HL holds FIB
  6268. ;
  6269. ; Procedure CLOSE(un_typed_file)
  6270. ;
  6271. l1ab0:
  6272.         ld      (l00e2),hl      ;ok ;FIXME ; Save FIB
  6273.         ld      a,(hl)          ; Get mode
  6274.         and     _.in+_.out      ; Test access
  6275.         ret     z               ; Nope
  6276.         jp      l1481           ; Close it
  6277. ;
  6278. ; Write block to untyped file
  6279. ; Procedure BLOCKWRITE(file,buffer,count)
  6280. ; ENTRY Reg HL holds number of records to be written
  6281. ;       On stack FIB and buffer
  6282. ;
  6283. l1aba:
  6284.         ld      a,_rndwr        ; Set function code
  6285.         jr      l1ac0
  6286. ;
  6287. ; Read block from untyped file
  6288. ; Procedure BLOCKREAD(file,buffer,count)
  6289. ; ENTRY Reg HL holds number of records to be read
  6290. ;       On stack FIB and buffer
  6291. ;
  6292. l1abe:
  6293.         ld      a,_rndrd        ; Set function code
  6294. l1ac0:
  6295.         ld      b,h             ; Copy count
  6296.         ld      c,l
  6297.         ld      hl,l00f0        ; Point to scratch
  6298.         ld      (l00e6),hl      ;ok ;FIXME ; Set for record
  6299.         pop     ix
  6300.         pop     de              ; Get buffer
  6301.         pop     hl              ; Get FIB
  6302.         push    ix
  6303.         push    bc
  6304.         call    l1afd           ; Execute block I/O
  6305.         pop     bc
  6306.         ld      a,(l00d0) ;ok ;FIXME
  6307.         or      a               ; Test error
  6308.         ret     nz              ; Exit if so
  6309.         ld      hl,(l00f0) ;ok ;FIXME
  6310.         sbc     hl,bc           ; Test all records processed
  6311.         ret     z               ; Yeap
  6312.         ld      a,(l00e9)       ;ok ;FIXME ; Get file function
  6313.         cp      _rndrd          ; Test read
  6314.         ld      a,_IllEOF
  6315.         jr      z,l1ae9
  6316.         ld      a,_WrErr
  6317. l1ae9:
  6318.         ld      (l00d0),a       ;ok ;FIXME ; Set error code accordingly
  6319.         ret
  6320. ;
  6321. ; Write block to untyped file
  6322. ; Procedure BLOCKWRITE(file,buffer,count,result)
  6323. ; ENTRY Reg HL points to result
  6324. ;       On stack FIB, buffer and number of records
  6325. ;
  6326. l1aed:
  6327.         ld      a,_rndwr        ; Set function
  6328.         jr      l1af3
  6329. ;
  6330. ; Read block from untyped file
  6331. ; Procedure BLOCKREAD(file,buffer,count,result)
  6332. ; ENTRY Reg HL points to result
  6333. ;       On stack FIB, buffer and number of records
  6334. ;
  6335. l1af1:
  6336.         ld      a,_rndrd        ; Set function
  6337. l1af3:
  6338.         ld      (l00e6),hl      ;ok ;FIXME ; Save result pointer
  6339.         pop     ix
  6340.         pop     bc              ; Get count
  6341.         pop     de              ; Get buffer
  6342.         pop     hl              ; Get FIB
  6343.         push    ix
  6344. ;
  6345. ; Perform block IO
  6346. ; ENTRY Accu holds file function
  6347. ;       Reg HL holds FIB
  6348. ;       Reg DE holds buffer
  6349. ;
  6350. l1afd:
  6351.         ld      (l00e9),a       ;ok ;FIXME ; Save function
  6352.         ld      (l00e2),hl      ;ok ;FIXME ; Save FIB
  6353.         ld      a,(hl)          ; Get mode
  6354.         and     _.in+_.out      ; Test IO allowed
  6355.         jp      z,l18b0         ; Nope
  6356.         ld      hl,(l00e6)      ;ok ;FIXME ; Get record address
  6357.         xor     a
  6358.         ld      (hl),a          ; Clear record
  6359.         inc     hl
  6360.         ld      (hl),a
  6361. l1b10:
  6362.         ld      a,b
  6363.         or      c               ; Test all done
  6364.         jr      z,l1b4d         ; Yeap
  6365.         push    bc
  6366.         push    de
  6367.         ld      c,_setdma
  6368.         call    BDOS            ; Set disk buffer
  6369.         ld      hl,(l00e2)      ;ok ;FIXME ; Get back FIB
  6370.         ld      de,FIB.FCB
  6371.         add     hl,de           ; Point to FCB
  6372.         ex      de,hl
  6373.         ld      a,(l00e9)       ;ok ;FIXME ; Get file function
  6374.         ld      c,a
  6375.         call    BDOS            ; Execute I/O
  6376.         pop     de
  6377.         pop     bc
  6378.         or      a               ; Test result
  6379.         jr      nz,l1b4d        ; Not good
  6380.         push    de
  6381.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB again
  6382.         ld      de,FIB.FCB+_rrn
  6383.         add     hl,de           ; Point to record
  6384.         inc     (hl)            ; Advance record
  6385.         jr      nz,l1b3c
  6386.         inc     hl
  6387.         inc     (hl)
  6388. l1b3c:
  6389.         pop     de
  6390.         ld      hl,RecLng
  6391.         add     hl,de           ; Advance buffer
  6392.         ex      de,hl
  6393.         ld      hl,(l00e6) ;ok ;FIXME
  6394.         inc     (hl)            ; Advance record count
  6395.         jr      nz,l1b4a
  6396.         inc     hl
  6397.         inc     (hl)
  6398. l1b4a:
  6399.         dec     bc              ; Count down requested length
  6400.         jr      l1b10
  6401. l1b4d:
  6402.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  6403.         ld      de,FIB.FCB+_rrn
  6404.         add     hl,de           ; Point to last record
  6405.         ld      c,(hl)
  6406.         inc     hl
  6407.         ld      b,(hl)
  6408.         ld      de,FIB.cur-FIB.FCB-_rrn-1
  6409.         add     hl,de           ; Point to FIB record
  6410.         ld      (hl),c          ; Save record number
  6411.         inc     hl
  6412.         ld      (hl),b
  6413.         ld      de,-FIB.rec
  6414.         add     hl,de           ; Point to record
  6415.         ld      d,(hl)
  6416.         dec     hl
  6417.         ld      e,(hl)
  6418.         ex      de,hl
  6419.         or      a
  6420.         sbc     hl,bc           ; Test against last record
  6421.         ret     nc
  6422.         ex      de,hl
  6423.         ld      (hl),c          ; Save new max record
  6424.         inc     hl
  6425.         ld      (hl),b
  6426.         ret
  6427. ;
  6428. ; Procedure SEEK(file,record)
  6429. ; ENTRY Reg HL holds record seeked for
  6430. ;       FIB pushed onto stack
  6431. ;
  6432. l1b6f:
  6433.         pop     bc
  6434.         pop     de
  6435.         ld      (l00e2),de      ;ok ;FIXME ; Save FIB
  6436.         push    bc
  6437.         push    hl
  6438.         call    l1a5a           ; Get record data
  6439.         pop     de
  6440.         or      a
  6441.         sbc     hl,de           ; Test position
  6442.         jp      c,l1a26         ; Error if overflow
  6443.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  6444.         ld      bc,FIB.cur
  6445.         add     hl,bc
  6446.         ld      (hl),e          ; Save new position
  6447.         inc     hl
  6448.         ld      (hl),d
  6449.         ld      bc,FIB.FCB+_rrn-FIB.cur-1
  6450.         add     hl,bc
  6451.         ld      (hl),e          ; Save in FCB, too
  6452.         inc     hl
  6453.         ld      (hl),d
  6454.         ret
  6455. ;
  6456. ; Delete file
  6457. ; Procedure ERASE(file)
  6458. ; ENTRY Reg HL holds FIB
  6459. ;
  6460. l1b93:
  6461.         call    l1c4c           ; Check legal FIB
  6462.         ret     nz              ; Nope
  6463.         ld      de,FIB.FCB
  6464.         add     hl,de           ; Point to FCB
  6465.         ex      de,hl
  6466.         ld      c,_delete
  6467.         call    BDOS            ; Delete file
  6468.         inc     a
  6469.         ret     nz
  6470.         jr      l1be4           ; Set error if unknown
  6471. ;
  6472. ; Rename file
  6473. ; Procedure RENAME(file,newname)
  6474. ; ENTRY FIB and name on stack
  6475. ;
  6476. l1ba5:
  6477.         pop     iy
  6478.         ld      hl,(l00d2)      ; Get top of memory for buffer
  6479.         ld      b,16            ; Set max
  6480.         call    l05e2           ; Assign string from stack
  6481.         xor     a
  6482.         ld      (de),a
  6483.         pop     hl              ; Load FIB
  6484.         push    iy
  6485.         call    l1c4c           ; Check legal FIB
  6486.         ret     nz              ; Nope
  6487.         push    hl
  6488.         call    l03f2           ; Parse file
  6489.         pop     hl
  6490.         push    hl
  6491.         ld      de,FIB.FCB+DIRlen
  6492.         add     hl,de           ; Point to 2nd FCB
  6493.         ex      de,hl
  6494.         ld      hl,l005c
  6495.         ld      bc,Fdrv+Fname+Fext
  6496.         ldir                    ; move new name
  6497.         pop     hl
  6498.         ld      de,FIB.FCB
  6499.         add     hl,de           ; Point to FCB
  6500.         push    hl
  6501.         ex      de,hl
  6502.         ld      c,_rename
  6503.         call    BDOS            ; Rename
  6504.         pop     de
  6505.         inc     a               ; Test success
  6506.         jr      z,l1be4         ; Nope
  6507.         ld      hl,l005c
  6508.         ld      bc,FCBlen
  6509.         ldir                    ; Unpack new file
  6510.         ret
  6511. l1be4:
  6512.         ld      a,_NoFile       ; Set error
  6513. l1be6:
  6514.         ld      (l00d0),a ;ok ;FIXME
  6515.         ret
  6516. ;
  6517. ; Perform executing new programs
  6518. ; Procedure EXECUTE(File)
  6519. ; ENTRY Reg HL points to FIB
  6520. ;
  6521. l1bea:
  6522.         db      skip
  6523. ;
  6524. ; Procedure CHAIN(File)
  6525. ;
  6526. l1beb:
  6527.         xor     a
  6528.         ld      (l00e8),a       ;ok ;FIXME ; Set mode (0=CHAIN)
  6529.         call    l1c4c           ; Test device ok
  6530.         ret     nz              ; Nope
  6531.         ld      a,(l00d8)       ;ok ;FIXME ; Test run mode
  6532.         or      a
  6533.         ld      a,_DirErr
  6534.         jr      z,l1be6         ; Must *NOT* be direct mode
  6535.         ld      hl,(l00e2)      ;ok ;FIXME ; Get FIB
  6536.         ld      de,FIB.FCB
  6537.         add     hl,de           ; Point to FCB
  6538.         ld      de,l005c
  6539.         ld      bc,FCBlen
  6540.         ldir                    ; move to standard FCB
  6541.         ld      de,l005c
  6542.         ld      c,_open
  6543.         call    BDOS            ; Open file ;WHERE IS CLOSE???
  6544.         inc     a
  6545.         jr      z,l1be4         ; File not found
  6546.         ld      hl,l1c33        ; Point to loader
  6547.         ld      de,l00b0
  6548.         ld      bc,l0019
  6549.         ldir                    ; move loader to temporry location
  6550.         ld      de,0x0100;TPA           ; Init loader address
  6551.         ld      a,(l00e8)       ;ok ;FIXME ; Test mode
  6552.         or      a
  6553.         jr      nz,l1c2d
  6554.         ld      de,(progstartaddr);(TPA+1)      ; Change address for CHAIN
  6555. l1c2d:
  6556.         ld      sp,0x0100;TPA           ; Get local stack
  6557.         jp      l00b0           ; Go load
  6558. ;
  6559. ; ############### Start of loader ###############
  6560. ;
  6561. ; Loader will be moved into 00B0H temporary location
  6562. ;
  6563. l1c33:
  6564.         disp    l00b0
  6565. _l1c33:
  6566.         push    de
  6567.         ld      c,_setdma
  6568.         call    BDOS            ; Set disk buffer
  6569.         ld      de,l005c
  6570.         ld      c,_rdseq
  6571.         call    BDOS            ; Read a code record
  6572.         pop     de
  6573.         ld      hl,RecLng
  6574.         add     hl,de           ; Bump address
  6575.         ex      de,hl
  6576.         ;or     a               ; Test more
  6577.         ;jr     z,_l1c33
  6578.          cp 128 ;EOF in NedoOS
  6579.          jr nz,_l1c33           ; Read was successfull
  6580.          ;jr $
  6581.         jr      0x0100;TPA              ; Start after loading
  6582. l0019   equ     $-_l1c33
  6583.         ent
  6584. ;
  6585. ; ################ End of loader ################
  6586. ;
  6587. ; Check legal device for file operation
  6588. ; ENTRY Reg HL points to FIB
  6589. ; EXIT  Zero flag set if legal device
  6590. ;       If illegal, IOerror 20H will be set
  6591. ;
  6592. l1c4c:
  6593.         ld      (l00e2),hl      ;ok ;FIXME ; Save FIB
  6594.         ld      a,(hl)          ; Get flag
  6595.         and     FIBtype         ; Mask it
  6596.         ret     z               ; 0000 menas file
  6597.         ld      a,_IllIO
  6598.         ld      (l00d0),a       ;ok ;FIXME ; Set error
  6599.         ret
  6600. ;
  6601. ; Load overlay file
  6602. ; ENTRY Reg HL holds record procedure starts with
  6603. ;       Reg DE holds number of records to be read
  6604. ;
  6605. ; Overlay call follows:
  6606. ;           2 Bytes hold last sector read
  6607. ;          11 Bytes NAME.EXT of file
  6608. ;       n*128 Bytes record(s)
  6609. ;
  6610. l1c59:
  6611.         ld      (l00e6),hl      ;ok ;FIXME ; Save record
  6612.         ld      (l00e8),de      ;ok ;FIXME ; Save record count
  6613.         ex      de,hl
  6614.         pop     hl
  6615.         ld      (l00e2),hl      ;ok ;FIXME ; Save caller
  6616.         ld      c,(hl)          ; Fetch last sector
  6617.         ld      (hl),e          ; Set new one
  6618.         inc     hl
  6619.         ld      b,(hl)
  6620.         ld      (hl),d
  6621.         ex      de,hl           ; Compare bew:old
  6622.         or      a
  6623.         sbc     hl,bc
  6624.         jr      z,l1cca         ; Overlay already in memory
  6625.         ex      de,hl
  6626.         inc     hl
  6627.         ld      de,l005c
  6628.         ld      a,(l00dc) ;ok ;FIXME    ; Get overlay drive
  6629.         ld      (de),a          ; Store into standard FCB
  6630.         inc     de
  6631.         ld      bc,Fname+Fext
  6632.         ldir                    ; move name to standard FCB
  6633.         ld      b,FCBlen-_ex
  6634.         xor     a
  6635. l1c82:
  6636.         ld      (de),a          ; Clear remainder of FCB
  6637.         inc     de
  6638.         djnz    l1c82
  6639.         push    hl              ; Save address of buffer
  6640.         ld      de,l005c
  6641.         ld      c,_open
  6642.         call    BDOS            ; Open file
  6643.         pop     de              ; Get back buffer address
  6644.         inc     a               ; Test success
  6645.         jr      z,l1cd2         ; Nope
  6646.         ld      hl,(l00e6) ;ok ;FIXME   ; Get start record
  6647.         ld      (l005c+_rrn),hl ;ok ;FIXME      ; Set for random record
  6648.         ld      bc,(l00e8) ;ok ;FIXME   ; Get record count
  6649. l1c9d:
  6650.         push    bc
  6651.         push    de
  6652.         ld      c,_setdma
  6653.         call    BDOS            ; Set disk buffer
  6654.         ld      de,l005c
  6655.         ld      c,_rndrd
  6656.         call    BDOS            ; Read from file
  6657.         pop     de
  6658.         pop     bc
  6659.         or      a               ; Verify no error
  6660.         jr      nz,l1cd2        ; Error
  6661.         ld      hl,(l005c+_rrn) ;ok ;FIXME
  6662.         inc     hl              ; Bump record
  6663.         ld      (l005c+_rrn),hl ;ok ;FIXME
  6664.         ld      hl,RecLng
  6665.         add     hl,de           ; Get next address
  6666.         ex      de,hl
  6667.         dec     bc
  6668.         ld      a,b             ; Test done
  6669.         or      c
  6670.         jr      nz,l1c9d        ; Nope
  6671.         ld      de,l005c
  6672.         ld      c,_close
  6673.         call    BDOS            ; Close file
  6674. l1cca:
  6675.         ld      hl,(l00e2)      ; Get caller
  6676.         ld      de,2+Fname+Fext
  6677.         add     hl,de           ; Skip header
  6678.         jp      (hl)            ; Enter overlay
  6679. l1cd2:
  6680.         ld      ix,(l00e2)      ; Get caller's PC
  6681.         ld      a,_OVLerr
  6682.         jp      l2029           ; Abort
  6683. ;
  6684. ; Procedure OVRDRIVE(drive)
  6685. ; ENTRY Reg HL holds drive (1=A, 2=B, etc)
  6686. ;
  6687. l1cdb:
  6688.         call    l04c8           ; Get byte from integer
  6689.         cp      'P'-'@'+1       ; Test max
  6690.         ret     nc              ; Exit on range error
  6691.         ld      (l00dc),a ;ok ;FIXME    ; Set overlay drive
  6692.         ret
  6693. ;
  6694. ; Procedure NEW(pointer)
  6695. ; Procedure GETMEM(pointer,space)
  6696. ; ENTRY Reg HL holds space required
  6697. ;       Variable pointer on stack
  6698. ;
  6699. l1ce5:
  6700.         ld      (l00f0),hl ;ok ;FIXME   ; Save space required
  6701.         ex      de,hl
  6702.         pop     hl
  6703.         ex      (sp),hl
  6704.         ld      (l00f2),hl ;ok ;FIXME   ; Save address of variable
  6705.         inc     de
  6706.         inc     de
  6707.         inc     de
  6708.         ld      a,e
  6709.         and     -HeapLen        ; Get modulo 4
  6710.         ld      e,a
  6711.         ld      hl,l00de
  6712.         ld      (l00f8),hl ;ok ;FIXME   ; Init pointer
  6713.         ld      ix,(l00de) ;ok ;FIXME   ; Get pointer to 1st free address
  6714. l1cff:
  6715.         ld      l,(ix+HeapLOlen)
  6716.         ld      h,(ix+HeapHIlen)
  6717.         ld      a,l             ; Test assignment
  6718.         or      h
  6719.         jr      z,l1d51         ; Maybe free
  6720.         sbc     hl,de           ; Test gap
  6721.         jr      nc,l1d1c
  6722.         ld      l,(ix+HeapLOadr); Get next address
  6723.         ld      h,(ix+HeapHIadr)
  6724.         push    hl
  6725.         ld      (l00f8),ix ;ok ;FIXME   ; Save last address
  6726.         pop     ix              ; Copy chain
  6727.         jr      l1cff
  6728. l1d1c:
  6729.         jr      nz,l1d28        ; Not same gap length
  6730.         ld      e,(ix+HeapLOadr); Get address if so
  6731.         ld      d,(ix+HeapHIadr)
  6732.         push    ix
  6733.         jr      l1d43           ; Save state
  6734. l1d28:
  6735.         ld      c,l             ; Copy length
  6736.         ld      b,h
  6737.         ld      l,(ix+HeapLOadr); Get address
  6738.         ld      h,(ix+HeapHIadr)
  6739. l1d30:
  6740.         push    ix              ; Save pointer
  6741.         add     ix,de           ; Advance
  6742.         ld      (ix+HeapLOadr),l; Set start values
  6743.         ld      (ix+HeapHIadr),h
  6744.         ld      (ix+HeapLOlen),c
  6745.         ld      (ix+HeapHIlen),b
  6746.         push    ix
  6747.         pop     de              ; Copy pointer
  6748. l1d43:
  6749.         ld      hl,(l00f8) ;ok ;FIXME   ; Get pointer
  6750.         ld      (hl),e          ; Set new link
  6751.         inc     hl
  6752.         ld      (hl),d
  6753.         pop     de
  6754.         ld      hl,(l00f2) ;ok ;FIXME
  6755.         ld      (hl),e          ; Set into vriable
  6756.         inc     hl
  6757.         ld      (hl),d
  6758.         ret
  6759. l1d51:
  6760.         push    ix
  6761.         pop     hl
  6762.         add     hl,de
  6763.         ld      (l00c4),hl      ; Set new heap pointer
  6764.         ld      hl,(l00f0)      ; Get space
  6765.         ld      bc,HeapLen
  6766.         add     hl,bc           ; Get complete length
  6767.         push    ix
  6768.         pop     bc
  6769.         add     hl,bc
  6770.         jp      c,l1d75         ; Error if overlapping
  6771.         ld      bc,(l00c6)      ; Get recursion pointer
  6772.         sbc     hl,bc           ; Test against it
  6773.         ld      bc,0
  6774.         ld      hl,0
  6775.         jp      c,l1d30
  6776. ;
  6777. ; Heap error
  6778. ;
  6779. l1d75:
  6780.         ld      a,_HeapErr
  6781.         jp      l2027           ; Set error
  6782. ;
  6783. ; Procedure DISPOSE(pointer)
  6784. ; Procedure FREEMEM(pointer,space)
  6785. ; ENTRY Reg HL holds space
  6786. ;       Variable pointer on stack
  6787. ;
  6788. l1d7a:
  6789.         ex      de,hl           ; Save space
  6790.         pop     hl
  6791.         ex      (sp),hl         ; Get variable pointer
  6792.         ld      a,(hl)          ; Get dynamic pointer
  6793.         inc     hl
  6794.         ld      h,(hl)
  6795.         ld      l,a
  6796.         inc     de              ; Fix space
  6797.         inc     de
  6798.         inc     de
  6799.         ld      a,e
  6800.         and     -HeapLen        ; Get modulo 4
  6801.         ld      e,a
  6802.         ex      de,hl
  6803.         ld      (l00f0),hl      ; Save length
  6804.         ld      hl,(l00de)      ; Load pointer to free heap
  6805.         push    hl
  6806.         pop     ix
  6807.         or      a
  6808.         sbc     hl,de           ; Check pointer addresses
  6809.         jr      nc,l1de9
  6810. l1d97:
  6811.         ld      l,(ix+HeapLOadr); Get address
  6812.         ld      h,(ix+HeapHIadr)
  6813.         push    hl
  6814.         or      a
  6815.         sbc     hl,de           ; Compare
  6816.         jr      nc,l1da7
  6817.         pop     ix
  6818.         jr      l1d97
  6819. l1da7:
  6820.         pop     hl
  6821.         push    de
  6822.         pop     iy
  6823.         ld      bc,(l00f0)      ; Get length
  6824.         ld      (iy+HeapLOlen),c; Store it
  6825.         ld      (iy+HeapHIlen),b
  6826.         ld      (iy+HeapLOadr),l; Store address, too
  6827.         ld      (iy+HeapHIadr),h
  6828.         ld      (ix+HeapLOadr),e
  6829.         ld      (ix+HeapHIadr),d
  6830.         push    ix
  6831.         pop     hl
  6832.         ld      c,(ix+HeapLOlen); Get old length
  6833.         ld      b,(ix+HeapHIlen)
  6834.         call    l1e04           ; Compare
  6835.         jr      z,l1dd8         ; Match
  6836.         ld      e,(ix+HeapLOadr); Get address
  6837.         ld      d,(ix+HeapHIadr)
  6838.         push    de
  6839.         pop     ix
  6840. l1dd8:
  6841.         push    ix
  6842.         pop     hl
  6843.         ld      c,(ix+HeapLOlen)
  6844.         ld      b,(ix+HeapHIlen)
  6845.         ld      e,(ix+HeapLOadr)
  6846.         ld      d,(ix+HeapHIadr)
  6847.         jr      l1e04
  6848. l1de9:
  6849.         ld      hl,(l00de)      ; Get pointer to free heap
  6850.         ld      (l00de),de      ; Set new address
  6851.         push    de
  6852.         pop     ix
  6853.         ld      (ix+HeapLOadr),l; Set chain
  6854.         ld      (ix+HeapHIadr),h
  6855.         ld      bc,(l00f0)      ; Get length
  6856.         ld      (ix+HeapLOlen),c
  6857.         ld      (ix+HeapHIlen),b
  6858.         ex      de,hl
  6859. l1e04:
  6860.         add     hl,bc           ; Bump next
  6861.         or      a
  6862.         sbc     hl,de           ; Test same
  6863.         ret     nz
  6864.         push    de
  6865.         pop     iy              ; Copy pointer
  6866.         ld      hl,(l00c4)      ; Get heap pointer
  6867.         or      a
  6868.         sbc     hl,de           ; Test top found
  6869.         jr      z,l1e2f
  6870.         ld      a,(iy+HeapLOadr); Unpack address
  6871.         ld      (ix+HeapLOadr),a
  6872.         ld      a,(iy+HeapHIadr)
  6873.         ld      (ix+HeapHIadr),a
  6874.         ld      l,(iy+HeapLOlen)
  6875.         ld      h,(iy+HeapHIlen)
  6876.         add     hl,bc
  6877.         ld      (ix+HeapLOlen),l; Unpack new length
  6878.         ld      (ix+HeapHIlen),h
  6879.         xor     a
  6880.         ret
  6881. l1e2f:
  6882.         push    ix
  6883.         pop     hl
  6884.         ld      (l00c4),hl      ; Set new top heap pointer
  6885.         ld      b,HeapLen
  6886. l1e37:
  6887.         ld      (hl),0          ; Clear top
  6888.         inc     hl
  6889.         djnz    l1e37
  6890.         ret
  6891. ;
  6892. ; Get free memory
  6893. ; Function MEMAVAIL:integer
  6894. ; EXIT  Reg HL holds free memory in bytes
  6895. ;
  6896. l1e3d:
  6897.         call    l1e4b           ; Get memory
  6898.         ld      hl,(l00f4)      ; Get available memory
  6899.         ret
  6900. ;
  6901. ; Get max free memory
  6902. ; Function MAXAVAIL:integer
  6903. ; EXIT  Reg HL holds free memory in bytes
  6904. ;
  6905. l1e44:
  6906.         call    l1e4b           ; Get memory
  6907.         ld      hl,(l00f6)      ; Get max memory
  6908.         ret
  6909. ;
  6910. ; Get free memory
  6911. ;
  6912. l1e4b:
  6913.         ld      hl,0
  6914.         ld      (l00f4),hl      ; Init available memory
  6915.         ld      (l00f6),hl
  6916.         ld      ix,(l00de)      ; Get pointer to free heap
  6917. l1e58:
  6918.         ld      c,(ix+HeapLOlen)
  6919.         ld      b,(ix+HeapHIlen)
  6920.         ld      a,c
  6921.         or      b               ; Test end of chain
  6922.         jr      z,l1e80
  6923.         ld      hl,(l00f4)      ; Get old available memory
  6924.         add     hl,bc           ; Add length
  6925.         ld      (l00f4),hl
  6926.         ld      hl,(l00f6)      ; Get max
  6927.         or      a
  6928.         sbc     hl,bc           ; Check it
  6929.         jr      nc,l1e75
  6930.         ld      (l00f6),bc      ; Set new max
  6931. l1e75:
  6932.         ld      l,(ix+HeapLOadr); Get chain
  6933.         ld      h,(ix+HeapHIadr)
  6934.         push    hl
  6935.         pop     ix
  6936.         jr      l1e58           ; Loop
  6937. l1e80:
  6938.         ld      hl,(l00c6)      ; Get recursion pointer
  6939.         ld      bc,-5
  6940.         add     hl,bc           ; Build free address
  6941.         ld      de,(l00c4)      ; Get heap pointer
  6942.         or      a
  6943.         sbc     hl,de           ; Test any free
  6944.         ret     c
  6945.         ex      de,hl
  6946.         ld      hl,(l00f4)      ; Get available memory
  6947.         add     hl,de           ; Add gap
  6948.         ld      (l00f4),hl
  6949.         ld      hl,(l00f6)      ; Get max
  6950.         or      a
  6951.         sbc     hl,de           ; Subtract
  6952.         ret     nc
  6953.         ld      (l00f6),de      ; Set new
  6954.         ret
  6955. ;
  6956. ; Mark heap
  6957. ; Procedure MARK(pointer)
  6958. ; ENTRY Reg HL holds pointer
  6959. ;
  6960. l1ea3:
  6961.         ld      de,(l00c4) ;ok ;FIXME   ; Get heap pointer
  6962.         ld      (hl),e          ; Store into variable
  6963.         inc     hl
  6964.         ld      (hl),d
  6965.         ret
  6966. ;
  6967. ; Release heap
  6968. ; Procedure RELEASE(pointer)
  6969. ; ENTRY Reg HL holds pointer
  6970. ;
  6971. l1eab:
  6972.         ld      e,(hl)          ; Load heap from variable
  6973.         inc     hl
  6974.         ld      d,(hl)
  6975.         ex      de,hl
  6976. ;
  6977. ; Init heap
  6978. ; ENTRY Reg HL points to 1st free location
  6979. ;
  6980. l1eaf:
  6981.         ld      (l00c4),hl ;ok ;FIXME   ; Set heap pointer
  6982.         ld      (l00de),hl ;ok ;FIXME
  6983.         ld      b,HeapLen
  6984. l1eb7:
  6985.         ld      (hl),0          ; Clear 4 bytes
  6986.         inc     hl
  6987.         djnz    l1eb7
  6988.         ret
  6989. ;
  6990. ; Convert number to string
  6991. ; Procedure STR(real,string)
  6992. ; ENTRY Real pushed onto stack with formatting data
  6993. ;       Reg HL points to string
  6994. ;       Reg B holds length of string
  6995. ;
  6996. l1ebd:
  6997.         db      skip
  6998. ;
  6999. ; Procedure STR(integer,string)
  7000. ; ENTRY Integer pushed onto stack with digit count
  7001. ;       Reg HL points to string
  7002. ;       Reg B holds length of string
  7003. ;
  7004. l1ebe:
  7005.         xor     a
  7006.         ld      c,a             ; Save mode
  7007.         ld      (l00e8),hl      ;ok ;FIXME ; Save string
  7008.         xor     a
  7009.         ld      (hl),a          ; Init to empty string
  7010.         ld      (l00d0),a       ;ok ;FIXME ; Clear error
  7011.         ld      a,b
  7012.         ld      (l00ea),a       ;ok ;FIXME ; Save max length
  7013.         ld      hl,(l00e2) ;ok ;FIXME
  7014.         ld      (l00ed),hl      ;ok ;FIXME ; Save current FIB
  7015.         ld      hl,l1f46
  7016.         ld      (l00e2),hl      ;ok ;FIXME ; Set RAM device
  7017.         pop     hl              ; Get caller
  7018.         ld      (l00e4),hl ;ok ;FIXME
  7019.         pop     hl              ; Get digit count/comma places
  7020.         inc     c               ; Test mode
  7021.         dec     c
  7022.         jr      nz,l1ee6
  7023.         call    l1726           ; Get integer string
  7024.         jr      l1ee9
  7025. l1ee6:
  7026.         call    l1779           ; Get real string
  7027. l1ee9:
  7028.         ld      hl,(l00ed) ;ok ;FIXME
  7029.         ld      (l00e2),hl      ;ok ;FIXME ; Restore FIB
  7030.         ld      hl,(l00e4)      ;ok ;FIXME ; Get caller
  7031.         jp      (hl)
  7032. ;
  7033. ; Convert string to number
  7034. ; Procedure VAL(string,real,result)
  7035. ; ENTRY String and address of real pushed onto stack
  7036. ;       Reg HL points to result
  7037. ;
  7038. l1ef3:
  7039.         db      skip
  7040. ;
  7041. ; Procedure VAL(string,integer,result)
  7042. ; ENTRY String and address of integer pushed onto stack
  7043. ;       Reg HL points to result
  7044. ;
  7045. l1ef4:
  7046.         xor     a
  7047.         ld      (l00ec),a       ;ok ;FIXME ; Save mode
  7048.         ld      (l00e8),hl      ;ok ;FIXME ; Save result
  7049.         ld      hl,(l00e2) ;ok ;FIXME
  7050.         ld      (l00ed),hl      ;ok ;FIXME ; Save current FIB
  7051.         ld      hl,l1f46
  7052.         ld      (l00e2),hl      ;ok ;FIXME ; Set RAM FIB
  7053.         pop     hl
  7054.         ld      (l00e4),hl      ;ok ;FIXME ; Save caller
  7055.         pop     hl
  7056.         ld      (l00ea),hl      ;ok ;FIXME ; Save integer/real address
  7057.         ld      hl,l005c
  7058.         ld      b,1eh
  7059.         call    l05e2           ; Assign string from stack
  7060.         xor     a
  7061.         ld      (de),a
  7062.         ld      hl,(l00ea)      ;ok ;FIXME ; Get back variable pointer
  7063.         ld      a,(l00ec)       ;ok ;FIXME ; Test mode
  7064.         or      a
  7065.         jr      nz,l1f27
  7066.         call    l164e           ; Convert to integer
  7067.         jr      l1f2a
  7068. l1f27:
  7069.         call    l1672           ; Convert to real
  7070. l1f2a:
  7071.         ld      hl,l00d0
  7072.         ld      a,(hl)          ; Get IOResult
  7073.         ld      (hl),0          ; Clear
  7074.         or      a
  7075.         ld      h,a
  7076.         ld      l,a
  7077.         jr      z,l1f3d         ; Test error
  7078.         push    ix
  7079.         pop     hl              ; Get last address
  7080.         ld      de,l005c
  7081.         sbc     hl,de           ; Get relative string error
  7082. l1f3d:
  7083.         ex      de,hl
  7084.         ld      hl,(l00e8)      ; Point to result
  7085.         ld      (hl),e          ; Save error or success
  7086.         inc     hl
  7087.         ld      (hl),d
  7088.         jr      l1ee9           ; Exit
  7089. ;
  7090. ; FIB for RAM storage
  7091. ;
  7092. l1f46:
  7093.         db      _.in+_.out+RAMdevice
  7094.         db      0
  7095. ;
  7096. ; Procedure RANDOMIZE
  7097. ;
  7098. l1f48:
  7099.         ld      a,r             ; Get refresh counter
  7100.         ld      (l00c8+3),a     ; Set for random
  7101.         ret
  7102. ;
  7103. ; Fill variable with constant value
  7104. ; Procedure FILLCHAR(var,num,val)
  7105. ; ENTRY Reg HL holds value
  7106. ;       Count and variable address pushed onto stack
  7107. ;
  7108. l1f4e:
  7109.         ex      de,hl
  7110.         pop     ix
  7111.         pop     bc              ; Get count
  7112.         pop     hl              ; Get address
  7113.         ld      a,b
  7114.         or      c               ; Test count zero
  7115.         jr      z,l1f62         ; Skip if so
  7116.         ld      (hl),e          ; Store value
  7117.         dec     bc              ; Fix count
  7118.         ld      a,b
  7119.         or      c               ; Test count one
  7120.         jr      z,l1f62         ; Skip if so
  7121.         ld      d,h             ; Copy address
  7122.         ld      e,l
  7123.         inc     de
  7124. l1f60:
  7125.         ldir                    ; move value for fill
  7126. l1f62:
  7127.         jp      (ix)
  7128. ;
  7129. ; move variable to another
  7130. ; Procedure MOVE(var1,var2,len)
  7131. ; ENTRY Reg HL holds count
  7132. ;       Variables pushed onto stack
  7133. ;
  7134. l1f64:
  7135.         ld      b,h             ; Copy count
  7136.         ld      c,l
  7137.         pop     ix
  7138.         pop     de              ; Get 2nd var
  7139.         pop     hl              ; Get 1st one
  7140.         ld      a,b
  7141.         or      c
  7142.         jr      z,l1f62         ; Test zero length
  7143.         sbc     hl,de
  7144.         add     hl,de           ; Test overlapping
  7145.         jr      nc,l1f60        ; move up if so
  7146.         dec     bc
  7147.         add     hl,bc           ; Point to top
  7148.         ex      de,hl
  7149.         add     hl,bc
  7150.         ex      de,hl
  7151.         inc     bc
  7152.         lddr                    ; move down
  7153.         jp      (ix)
  7154. ;
  7155. ; Get string from OS command line
  7156. ; Function PARAMSTR(num):any_string
  7157. ; ENTRY Reg HL holds number of substring
  7158. ; EXIT  Selected string on stack
  7159. ;
  7160. l1f7d:
  7161.         ld      d,l             ; Get number
  7162.         inc     d
  7163.         dec     d
  7164.         jr      z,l1f85         ; Skip if none
  7165.         call    l1f9d
  7166. l1f85:
  7167.         pop     ix              ; Free stack
  7168.         ld      c,a             ; Get length of string
  7169.         ld      b,0
  7170.         cpl
  7171.         ld      l,a
  7172.         ld      h,-1
  7173.         add     hl,sp           ; Build address on stack
  7174.         ld      sp,hl
  7175.         ld      (hl),c          ; Store length
  7176.         inc     hl
  7177.         ex      de,hl
  7178.         inc     c               ; Test any selected
  7179.         dec     c
  7180.         jr      z,l1f99         ; Nope
  7181.         ldir                    ; Unpack it
  7182. l1f99:
  7183.         jp      (ix)
  7184. ;
  7185. ; Get number of parameters in OS command line
  7186. ; Function PARAMCOUNT:integer;
  7187. ;
  7188. l1f9b:
  7189.         ld      d,0             ; Set dummy selection
  7190. ;
  7191. ; Get parameters of OS command line
  7192. ; ENTRY Reg D holds number of substring selected
  7193. ; EXIT  Reg DE points to selected substring
  7194. ;       Accu   holds length of substring
  7195. ;       Reg HL holds index of substring
  7196. ;
  7197. l1f9d:
  7198.         ld      hl,l0080        ; Init pointer
  7199.         ;ld     a,MaxParams     ; Test parameter count
  7200.         ;ld     b,(hl)
  7201.         ;cp     b
  7202.         ;jr     nc,l1fa8
  7203.         ld      b,MaxParams     ; Truncate to max
  7204. ;l1fa8:
  7205.         ;inc    hl
  7206.         ld      c,0             ; Init count
  7207. l1fab:
  7208.         inc     b
  7209.         dec     b               ; Test end
  7210.         jr      z,l1fbc         ; Yeap
  7211.         ld      a,(hl)
  7212.         cp      ' '
  7213.         jr      z,l1fb8         ; Skip white spaces
  7214.         cp      tab
  7215.         jr      nz,l1fbc
  7216. l1fb8:
  7217.         inc     hl
  7218.         dec     b
  7219.         jr      l1fab
  7220. l1fbc:
  7221.         ld      e,l             ; Save pointer
  7222. l1fbd:
  7223.         inc     b
  7224.         dec     b               ; Test done
  7225.         jr      z,l1fce         ; Yeap
  7226.         ld      a,(hl)
  7227.         cp      ' '
  7228.         jr      z,l1fce         ; Find white space
  7229.         cp      tab
  7230.         jr      z,l1fce
  7231.         inc     hl
  7232.         dec     b
  7233.         jr      l1fbd
  7234. l1fce:
  7235.         ld      a,l
  7236.         sub     e               ; Test same position
  7237.         jr      z,l1fd6
  7238.         inc     c               ; Count up index
  7239.         dec     d               ; Test found
  7240.         jr      nz,l1fab
  7241. l1fd6:
  7242.         ld      l,c             ; Get selected or last index
  7243.         ld      h,0             ; Make pointer relative
  7244.         ld      d,h
  7245.         ret
  7246. ;
  7247. ; Procedure GOTOXY(x_val,y_val)
  7248. ; ENTRY Reg HL holds y_val
  7249. ;       x_val on stack
  7250. ;
  7251. l1fdb:
  7252.         pop     de
  7253.         pop     bc
  7254.         push    de
  7255.         dec     l               ; Fix row
  7256.         ld      h,c
  7257.         dec     h               ; Fix column
  7258.         jp      l02a2           ; Position cursor
  7259. ;
  7260. ; Function UPCASE(char):char
  7261. ; ENTRY Reg HL holds character
  7262. ; EXIT  Reg HL holds UPPER case character
  7263. ;
  7264. l1fe4:
  7265.         ld      a,l             ; Get into accu
  7266.         call    doupcase                ; Convert to upper case
  7267.         ld      l,a             ; Bring it back
  7268.         ret
  7269. ;
  7270. ; Execute BIOS function
  7271. ; Procedures    BIOS(func)
  7272. ;               BIOS(func,param)
  7273. ; Functions     BIOS(func):integer
  7274. ;               BIOS(func,param):integer
  7275. ;               BIOSHL(func,param):integer
  7276. ; ENTRY Reg DE holds BIOS function
  7277. ;       Reg BC holds optional parameter
  7278. ; EXIT  Accu and reg HL hold result
  7279. ;
  7280. l1fea:
  7281.         ld      hl,(OS+1)       ; Get base address
  7282.         add     hl,de           ; Make executable
  7283.         add     hl,de
  7284.         add     hl,de
  7285.         jp      (hl)            ; Execute
  7286. ;
  7287. ; Get IO result
  7288. ; Function IORESULT:integer
  7289. ; EXIT  Reg HL holds result
  7290. ;
  7291. l1ff1:
  7292.         ld      hl,l00d0        ; Point to result
  7293.         ld      a,(hl)          ; Get it
  7294.         ld      (hl),0          ; Clear after request
  7295.         ld      l,a
  7296.         ld      h,0
  7297.         ret
  7298. ;
  7299. ; Control C entry - entered via RST after each statement
  7300. ;
  7301. l1ffb:
  7302.         call    l0316           ; Test key pressed
  7303.         ld      a,h
  7304.         or      l
  7305.         ret     z               ; Nope
  7306.         ld      a,(l00dd)       ;ok ;FIXME ; Get $C mode
  7307.         push    af
  7308.         xor     a
  7309.         ld      (l00dd),a       ;ok ;FIXME ; Set $C-
  7310.         call    l0320           ; Read from keyboard
  7311.         pop     af
  7312.         ld      (l00dd),a       ;ok ;FIXME ; Reset $C mode
  7313.         ld      a,l
  7314.         cp      CtrlC           ; Test Control-C
  7315.         ret     nz              ; Nope
  7316.         pop     ix              ; Fetch PC
  7317. l2016:
  7318.         ld      de,_CBRK        ; Set CtrlC error
  7319.         jr      l202c           ; Enter error routine
  7320. ;
  7321. ; Check IOResult after IO operation
  7322. ; (May be turned off by {$I-})
  7323. ;
  7324. l201b:
  7325.         ld      a,(l00d0)       ;ok ;FIXME ; Test any error
  7326.         or      a
  7327.         ret     z               ; Nope
  7328.         pop     ix              ; Get caller
  7329.         ld      e,a             ; Save code
  7330.         ld      d,_IO           ; Set mode
  7331.         jr      l202c
  7332. l2027:
  7333.         pop     ix              ; Get caller
  7334. l2029:
  7335.         ld      e,a             ; Save code
  7336.         ld      d,_RT           ; Set mode
  7337. ;
  7338. ; Common error handler
  7339. ; ENTRY Reg D holds error mode
  7340. ;       Reg E holds error code
  7341. ;       Reg IX holds callers address
  7342. ;
  7343. l202c:
  7344.          ;jr $
  7345.         push    de
  7346.         call    l037a           ; Reset some things
  7347.         pop     de
  7348.         xor     a
  7349.         ld      (l00dd),a       ; Set $C- mode
  7350.         ld      hl,(l00ce)      ; Get current PC
  7351.         ld      a,h             ; Check zero
  7352.         or      l
  7353.         push    ix
  7354.         pop     hl
  7355.         ld      bc,(l00cc)      ; Get base PC
  7356.         sbc     hl,bc           ; Subtract for base
  7357.         ld      bc,TPhead
  7358.         add     hl,bc           ; Fix for 0100h start
  7359.         ld      (l00ce),hl      ; Set current PC
  7360.         or      a               ; Look for previous zero
  7361.         jr      nz,l2054        ; Nope
  7362.         push    de
  7363.         push    de
  7364.         push    hl
  7365.         call    l00d9           ; Do restart
  7366.         pop     de
  7367. l2054:
  7368.         ld      a,d
  7369.         or      a               ; Test user break
  7370.         jr      nz,l206c
  7371.         call    l0200           ; Tell control C
  7372.         db      '^C'
  7373.         db      cr,lf  
  7374.         db      'User break'
  7375.         db      null
  7376.         jr      l2097
  7377. l206c:
  7378.         dec     a               ; Test I/O error
  7379.         jr      nz,l207a
  7380.         call    l0200           ; Tell I/O error
  7381.         db      cr,lf  
  7382.         db      'I/O'
  7383.         db      null
  7384.         jr      l2088
  7385. l207a:
  7386.         call    l0200           ; Tell run time error
  7387.         db      cr,lf  
  7388.         db      'Run-time'
  7389.         db      null
  7390. l2088:
  7391.         call    l0200
  7392.         db      ' error '
  7393.         db      null
  7394.         ld      a,e
  7395.         call    l04b4           ; Print error byte
  7396. l2097:
  7397.         call    l0200           ; Tell current PC
  7398.         db      ', PC='
  7399.         db      null
  7400.         ld      hl,(l00ce)      ; Get current PC
  7401.         call    l04af           ; Print hex
  7402.         jr      l20bd           ; Abort
  7403. ;
  7404. ; Process memory error
  7405. ;
  7406. l20a8:
  7407.         call    l0200           ; Tell error
  7408.         db      'Not enough memory'
  7409.         db      null
  7410. ;
  7411. ; Error detected, tell abort and break
  7412. ;
  7413. l20bd:
  7414.         call    l0200           ; Tell it
  7415.         db      cr,lf  
  7416.         db      'Program aborted'
  7417.         db      cr,lf,null     
  7418. ;
  7419. ; Halt program
  7420. ;
  7421. l20d4:
  7422.         ld      a,(l00d8)       ;ok ;FIXME ; Test run mode
  7423.         or      a
  7424.         jp      z,l278e         ; Enter TP menue
  7425.         if TERM == 0
  7426.         YIELDGETKEYLOOP
  7427.         endif
  7428.         jp      OS              ; Exit .COM file
  7429. ;
  7430. ; Restart after error
  7431. ;
  7432. l20de:
  7433.         pop     hl              ; Get PC
  7434.         pop     de              ; Clean stack
  7435.         pop     de
  7436.         jp      (hl)            ; Restart
  7437. ;
  7438. ;end of runtime library
  7439.  
  7440. ; %%%%%%%%%%%%%%%%%%%
  7441. ; %%% MENUE ENTRY %%%
  7442. ; %%%%%%%%%%%%%%%%%%%
  7443. ;
  7444. ; Enter here thru cold start
  7445. ;
  7446. l20e2:
  7447.         jp      l215e           ; Go to initializer
  7448. ;
  7449. ; Set up environment
  7450. ;
  7451. l20e5:
  7452.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)     ; Get top of memory
  7453.         pop     bc
  7454.         ld      sp,hl
  7455.         push    bc
  7456.         ld      de,-StkSpc
  7457.         add     hl,de           ; Allow some space
  7458.         ld      (l4548),hl      ; Set top of memory
  7459.         ld      hl,l7ad7        ; Get top of used memory
  7460.         ld      bc,256*0+0      ; No break, no interrupt
  7461.         call    l0364           ; Init pointers
  7462.         call    l030a           ; Give lead in sequence
  7463.         call    setlowvideo             ; Set low video
  7464.         jp      setnormvideo            ; Set normal video
  7465. ;
  7466. ; Init session and load work file if defined
  7467. ;
  7468. l2104:
  7469.         call    l20e5           ; Set up environment
  7470.         ld      a,(l4542)       ; Get compile flag
  7471.         push    af
  7472.         ld      a,(l4541)       ; Test error message file read
  7473.         or      a
  7474.         call    nz,l2da4        ; Yeap, read it
  7475.         call    l2d8f           ; Init session
  7476.         call    l2d4b           ; Test work file defined
  7477.         call    nz,l2506        ; Yeap, load file
  7478.         ld      a,(l44f3)       ; Get compiler mode
  7479.         dec     a
  7480.         jr      z,l2125         ; Compile to memory
  7481.         pop     af
  7482.         ld      (l4542),a       ; Reset compile flag
  7483. l2125:
  7484.         jp      l223b           ; Enter menue
  7485. ;
  7486. ; Give delimiter line
  7487. ;
  7488. l2128:
  7489.         call    l0200
  7490.         db      '---------------------------------------'
  7491.         db      cr,lf,null
  7492.         ret
  7493. ;
  7494. ; Give B blanks
  7495. ;
  7496. l2156:
  7497.         call    l0200           ; Just do it
  7498.         db      ' ',null
  7499.         djnz    l2156
  7500.         ret
  7501. ;
  7502. ; Come here after cold start
  7503. ;
  7504. l215e:
  7505.         ;OS_HIDEFROMPARENT
  7506.         ;ld e,6 ;textmode
  7507.         ;OS_SETGFX
  7508.        
  7509.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)     ; Fetch top of memory
  7510.         ld      bc,-MEMGAP
  7511.         add     hl,bc
  7512.         ld      (l44f6),hl      ; Set for available memory
  7513.         ;ld     c,_retdsk
  7514.         ;call   BDOS            ; Get logged disk (return L=A=current drive)
  7515.        xor a
  7516.         inc     a
  7517.         ld      (l44f8),a       ; Save it
  7518.         call    l20e5           ; Set up environment
  7519.         call    l023e           ; Clear screen
  7520.         call    l2128           ; Give delimiter
  7521.         call    l0200           ; Tell what we are
  7522. l217d:
  7523.         db      'TURBO'
  7524.         db      ' Pascal system',null
  7525.         call    setlowvideo             ; Set low video
  7526.         ld      b,7
  7527.         call    l2156           ; Give blanks
  7528.         call    l0200           ; Tell version
  7529. ;
  7530.         db      'Version 3.00A'
  7531.         db      cr,lf,null
  7532.         ld      b,27
  7533.         call    l2156           ; Give blanks
  7534.         call    l0200           ; Tell type and copyright
  7535. ;
  7536.         db      'CP/M-80, Z80'
  7537.         db      cr,lf,cr,lf
  7538.         db      'Copyright (C) 1983,84,85   '
  7539.         db      null
  7540.         call    setnormvideo            ; Set normal video
  7541.         call    l0200
  7542. ;
  7543.         db      'BORLAND Inc.'
  7544.         db      cr,lf,null
  7545.         call    l2128           ; Give delimiter
  7546.         call    l0200           ; Tell type of terminal
  7547. ;
  7548.         db      lf
  7549.         db      'Terminal: '
  7550.         db      null
  7551.         ld      hl,l0153
  7552.         call    l01d0           ; Give string
  7553.         call    l0200           ; Ask for error messages to be included
  7554. ;
  7555.         db      cr,lf,lf,lf,lf
  7556.         db      'Include error messages'
  7557.         db      null
  7558.         call    l2d21           ; Ask for YES or NO
  7559.         ld      (l4541),a       ; Save result
  7560.         call    nz,l2da4        ; YES, read it
  7561.         call    l2d8f           ; Init session
  7562.         call    l227a           ; Display menue
  7563. ;
  7564. ; %%%%%%%%%%%%%%%%%%%&&&&&
  7565. ; %%% TURBO WARM START %%%
  7566. ; %%%%%%%%%%%%%%%%%%%&&&&&
  7567. ;
  7568. l223b:
  7569.         nop:ld sp,NEDOOSMEMTOP;ld       sp,(TPAtop)     ; Get top of stack
  7570.         ld      hl,l223b
  7571.         push    hl              ; Set return address
  7572.         call    l01fa           ; Indicate input requested
  7573. ;
  7574.         db      cr+MSB,lf+MSB,'>'+MSB
  7575.         db      null
  7576.         call    readfromkbd             ; Read character
  7577.         call    doupcase                ; Convert to upper case
  7578.         call    l01e1           ; Give new line
  7579.         ld      hl,l2460
  7580.         ld      de,l2472
  7581.         ld      b,MainLen
  7582.         call    l2450           ; Find command
  7583.         jr      c,l227a         ; Display menue if not found
  7584.         jp      (hl)            ; Execute command
  7585. ;
  7586. ; Input option string
  7587. ; On exit ^DE points to first non blank
  7588. ;
  7589. l2261:
  7590.         call    l0200           ; Tell what we want
  7591. ;
  7592.         db      ': '
  7593.         db      null
  7594.         call    l14e8           ; Get line
  7595.         call    l01e1           ; Give new line
  7596.         ld      de,l7ad7        ; Point to start of line
  7597. l2270:
  7598.         ld      a,(de)          ; Get character
  7599.         cp      eof             ; End on end of line
  7600.         ret     z
  7601.         cp      ' '             ; Skip blanks
  7602.         ret     nz
  7603.         inc     de
  7604.         jr      l2270
  7605. ;
  7606. ; Display menue
  7607. ;
  7608. l227a:
  7609.         call    l023e           ; Clear screen
  7610.         call    l01fa           ; Give some info
  7611. ;
  7612.         db      'L'+MSB,'ogged drive:',' '+MSB
  7613.         db      null
  7614.         ;ld     c,_retdsk
  7615.         ;call   BDOS            ; Fetch disk (return L=A=current drive)
  7616.        xor a
  7617.         add     a,'A'           ; Make ASCII
  7618.         call    puttoconsole_a          ; Put to console
  7619.         call    l01fa           ; Tell work file
  7620. ;
  7621.         db      cr+MSB,lf+MSB,lf+MSB
  7622.         db      'W'+MSB,'ork file:',' '+MSB
  7623.         db      null
  7624.         call    l3135           ; Type it
  7625.         call    l01fa           ; Tell main file
  7626. ;
  7627.         db      cr+MSB,lf+MSB
  7628.         db      'M'+MSB,'ain file:',' '+MSB
  7629.         db      null
  7630.         ld      de,l44f9
  7631.         call    l2df8           ; Tell name of file
  7632.         call    l01fa           ; Give selection
  7633. ;
  7634.         db      cr+MSB,lf+MSB,lf+MSB
  7635.         db      'E'+MSB,'dit     '
  7636.         db      'C'+MSB,'ompile  '
  7637.         db      'R'+MSB,'un   '
  7638.         db      'S'+MSB,'ave'
  7639.         db      cr,lf,lf
  7640.         db      'e','X'+MSB,'ecute  '
  7641.         db      'D'+MSB,'ir      '
  7642.         db      'Q'+MSB,'uit  compiler '
  7643.         db      'O'+MSB,'ptions'
  7644.         db      cr,lf,lf
  7645.         db      'Text: '
  7646.         db      null
  7647.         ld      de,(l4544)      ; Get start of text
  7648.         ld      hl,(l4546)      ; Get end of text
  7649.         dec     hl
  7650.         call    l2338           ; Tell free bytes
  7651.         ld      de,(l4546)      ; Get end of text
  7652.         ld      hl,(l4548)      ; Get top of available memory
  7653. ;
  7654. ; Tell free memory
  7655. ; ENTRY Reg HL holds  end  address
  7656. ;       Reg DE holds start address
  7657. ;
  7658. l232e:
  7659.         call    l0200           ; Tell free memory
  7660. ;
  7661.         db      'Free: '
  7662.         db      null
  7663. ;
  7664. ; Print decimal free bytes and hex addresses
  7665. ; ENTRY Reg HL holds  end  address
  7666. ;       Reg DE holds start address
  7667. ;
  7668. l2338:
  7669.         push    hl
  7670.         push    de
  7671.         or      a
  7672.         sbc     hl,de           ; Calculate difference
  7673.         call    l2e5c           ; Print it
  7674.         call    l0200           ; Tell bytes
  7675. ;
  7676.         db      ' bytes ('
  7677.         db      null
  7678.         pop     hl              ; Get start address
  7679.         call    l04af           ; Print hex
  7680.         ld      a,'-'
  7681.         call    puttoconsole_a          ; Give delimiter
  7682.         pop     hl              ; Get end address
  7683.         call    l04af           ; Print hex
  7684.         ld      a,')'
  7685.         call    puttoconsole_a          ; Give closure
  7686.         jp      l01e1           ; Give new line
  7687. ;
  7688. ; Display arrow if compile selected
  7689. ;
  7690. l2361:
  7691.         dec     a               ; Test compile selected
  7692.         jr      nz,l2374        ; Nope, erase display
  7693.         call    l01fa
  7694. a2361:
  7695.         db      'compile -> '
  7696. la2361  equ     $-a2361
  7697.         db      null
  7698.         ret
  7699. l2374:
  7700.         ld      b,la2361
  7701.         jp      l2156           ; Give blanks
  7702. ;
  7703. ; ##############################
  7704. ; ### MAIN MENUE O - Options ###
  7705. ; ##############################
  7706. ;
  7707. l2379:
  7708.         ld      hl,l2379
  7709.         push    hl              ; Set return address
  7710.         call    l023e           ; Clear screen
  7711.         ld      a,(l44f3)       ; Get compile mode
  7712.         call    l2361           ; Display arrow
  7713.         call    l01fa
  7714.         db      'M'+MSB,'emory'
  7715.         db      cr,lf,null
  7716.         call    l2361           ; Display arrow
  7717.         call    l01fa
  7718.         db      'C'+MSB,'om-file'
  7719.         db      cr,lf,null
  7720.         call    l2361           ; Display arrow
  7721.         call    l01fa
  7722.         db      'c','H'+MSB,'n-file'
  7723.         db      cr,lf,lf,null
  7724.         ld      a,(l44f3)       ; Get compile mode
  7725.         cp      1               ; Test compile to memory
  7726.         jr      z,l2419         ; Yeap
  7727.         call    l01fa
  7728.         db      'S'+MSB,'tart address:',' '+MSB
  7729.         db      null
  7730.         ld      hl,(l44f4)      ; Get start address
  7731.         call    l04af           ; Print hex
  7732.         call    l01fa
  7733.         db      ' (min '
  7734.         db      null
  7735.         ld      hl,l20e2        ; Get start address
  7736.         call    l04af           ; Print hex
  7737.         call    l01fa
  7738.         db      ')'
  7739.         db      cr,lf
  7740.         db      'E'+MSB,'nd   address:',' '+MSB
  7741.         db      null
  7742.         ld      hl,(l44f6)      ; Get top of available memory
  7743.         call    l04af           ; Print hex
  7744.         call    l01fa
  7745.         db      ' (max '
  7746.         db      null
  7747.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  7748.         call    l04af           ; Print hex
  7749.         call    l01fa
  7750.         db      ')'
  7751.         db      cr,lf,lf,null
  7752. l2419:
  7753.         call    l01fa
  7754.         db      'F'+MSB,'ind run-time error  '
  7755.         db      'Q'+MSB,'uit'
  7756.         db      cr,lf,lf
  7757.         db      '>'+MSB
  7758.         db      null
  7759.         call    readfromkbd             ; Read character
  7760.         call    doupcase                ; Convert to upper case
  7761.         call    l01e1           ; Give new line
  7762.         ld      hl,l246b
  7763.         ld      de,l2488
  7764.         ld      b,SubLen
  7765.         call    l2450           ; Find command
  7766.         ret     c               ; Not found
  7767.         jp      (hl)            ; Execute
  7768. ;
  7769. ; Find character in list ^HL of length in reg B
  7770. ; Return address from table ^DE on success
  7771. ; Set C if not found
  7772. ;
  7773. l2450:
  7774.         cp      (hl)            ; Compare
  7775.         jr      z,l245a         ; Match
  7776.         inc     hl              ; Skip character
  7777.         inc     de              ; Skip address
  7778.         inc     de
  7779.         djnz    l2450           ; Go thru table
  7780.         scf                     ; Indicate no match
  7781.         ret
  7782. l245a:
  7783.         ex      de,hl
  7784.         ld      e,(hl)          ; Fetch address
  7785.         inc     hl
  7786.         ld      d,(hl)
  7787.         ex      de,hl
  7788.         ret
  7789. ;
  7790. l2460:
  7791.         db      'LWMECRSXDQO'
  7792. MainLen equ     $-l2460
  7793. l246b:
  7794.         db      'MCHSEFQ'
  7795. SubLen  equ     $-l246b
  7796. l2472:
  7797.         dw      l2cce           ; L - Log drive
  7798.         dw      l24c9           ; W - Work file
  7799.         dw      l249a           ; M - Main file
  7800.         dw      l2af8           ; E - Edit
  7801.         dw      l2827           ; C - Compile
  7802.         dw      l2a97           ; R - Run
  7803.         dw      l2639           ; S - Save
  7804.         dw      l2b2d           ; X - eXecute
  7805.         dw      l2b93           ; D - Directory
  7806.         dw      l2b24           ; Q - Quit
  7807.         dw      l2379           ; O - Options
  7808. l2488:
  7809.         dw      l2740           ; M - Compile Memory
  7810.         dw      l2744           ; C - Compile Com-file
  7811.         dw      l2748           ; H - Compile cHn-file
  7812.         dw      l2750           ; S - Start address
  7813.         dw      l276e           ; E - End address
  7814.         dw      l279b           ; F - Find run-time error
  7815.         dw      l2496           ; Q - Quit
  7816. ;
  7817. ; ##########################
  7818. ; ### SUB MENUE Q - Quit ###
  7819. ; ##########################
  7820. ;
  7821. l2496:
  7822.         pop     hl
  7823.         jp      l227a           ; Display menue
  7824. ;
  7825. ; ################################
  7826. ; ### MAIN MENUE M - Main file ###
  7827. ; ################################
  7828. ;
  7829. l249a:
  7830.         call    l0200
  7831.         db      cr,lf
  7832.         db      'Main file name'
  7833.         db      null
  7834.         call    l2d9f           ; Init a bit
  7835.         call    l2261           ; Input string
  7836.         ld      a,0
  7837.         ld      (l44f9+Fdrv),a  ; Set default drive
  7838.         ret     z
  7839.         call    l2d2a           ; Prepare .PAS file
  7840.         ld      de,l44f9        ; Point to main file
  7841.         ld      hl,l005c
  7842.         ld      bc,FCBlen
  7843.         ldir                    ; Unpack FCB
  7844.         ret
  7845. ;
  7846. ; ################################
  7847. ; ### MAIN MENUE W - Work file ###
  7848. ; ################################
  7849. ;
  7850. l24c9:
  7851.         ld      hl,l25bc
  7852.         ld      (l259d+1),hl    ; Redirect error
  7853.         call    l2601           ; Save work file
  7854.         call    l0200
  7855.         db      cr,lf
  7856.         db      'Work file name'
  7857.         db      null
  7858.         call    l2261           ; Input string
  7859.         ld      a,0
  7860.         ld      (l451d+Fdrv),a  ; Set no work file
  7861.         jr      nz,l24f6        ; Got input
  7862.         call    l2d8f           ; Init session
  7863.         jp      l223b           ; Enter menue
  7864. l24f6:
  7865.         call    l2d2a           ; Prepare .PAS file
  7866.         ld      de,l451d
  7867.         ld      hl,l005c
  7868.         ld      bc,FCBlen
  7869.         ldir                    ; Unpack work file
  7870.         jr      l250c           ; Init and load text file
  7871. ;
  7872. ; Init a bit and load wirk file into memory
  7873. ;
  7874. l2506:
  7875.         ld      hl,l25b7
  7876.         ld      (l259d+1),hl    ; Redirect error
  7877. l250c:
  7878.         ld      hl,l25eb
  7879.         ld      (l257c+1),hl    ; Set vector for file too big
  7880.         call    l2d8f           ; Init session
  7881.         ld      de,l451d
  7882. ;
  7883. ; Load text file
  7884. ; ENTRY Reg DE points to FCB
  7885. ; EXIT  Reg HL points to  end  of memory
  7886. ;
  7887. l2518:
  7888.         ld      hl,(l4544)      ; Get start of text
  7889.         ld      (l4460),hl      ; Set block start pointer
  7890.         ld      (l4462),hl      ; Set block end pointer
  7891.         ld      (l4450),hl      ; Set current memory pointer
  7892.         ld      (l4454),hl      ; Set block pointer
  7893.         ld      (l4458),hl      ; Set edit pointer
  7894.         ld      (curstartofpage),hl     ; Set start of screen
  7895.         ld      bc,(l4548)      ; Get top of available memory
  7896.         call    l253b           ; Load file
  7897.         ld      (hl),cr         ; Close last line
  7898.         inc     hl
  7899.         ld      (l4546),hl      ; Set end of text
  7900.          push hl
  7901.          ld c,_close
  7902.          call BDOS_with_FCB1 ;WHY DOESN'T HELP???
  7903.          pop hl
  7904.         ret
  7905. ;
  7906. ; Load a file
  7907. ; ENTRY Reg BC holds last available address
  7908. ;       Reg DE holds FCB
  7909. ;       Reg HL holds start address
  7910. ; EXIT  Reg HL holds end address
  7911. ;
  7912.  
  7913. l253b: ;once
  7914.         push    hl
  7915.         push    bc
  7916.         push    de
  7917.         call    l0200           ; Tell action
  7918.         db      cr,lf
  7919.         db      'Loading '
  7920.         db      null
  7921.         call    l2df8           ; Tell name of file
  7922.         ld      de,l005c
  7923.         call    l26dc           ; Clear FCB
  7924.         pop     hl
  7925.         ld      bc,l0024
  7926.         ldir
  7927.         ld      c,_open
  7928.         call    BDOS_with_FCB1          ; Open file
  7929. l2560:
  7930.         ;push   af
  7931.         ;ld     de,TmpBuff
  7932.         ;ld     c,_setdma
  7933.         ;call   _BDOS           ; Set disk buffer
  7934.         ;pop    af
  7935.         pop     bc
  7936.         pop     hl
  7937.         inc     a               ; Test file found
  7938.         jr      z,l259d         ; Nope
  7939.         ld      (l7b6d),bc      ; Set last memory address
  7940. l2573:
  7941.         ld      bc,(l7b6d)      ; Get last memory address
  7942.         dec     b
  7943.         or      a
  7944.         sbc     hl,bc           ; Test room in memory
  7945.         add     hl,bc
  7946. l257c:
  7947.         jp      nc,a_DUMMY      ; Nope
  7948.         push    hl
  7949.          ld     de,TmpBuff
  7950.          ld     c,_setdma
  7951.          call   _BDOS           ; Set disk buffer
  7952.         ld      c,_rdseq
  7953.         call    BDOS_with_FCB1          ; Read record from file
  7954.         pop     hl
  7955.         ;or     a               ; Test end of file
  7956.         ;ret    nz              ; Yeap
  7957.          cp 128
  7958.          ret z ;EOF in NedoOS
  7959.         if 1==1
  7960. ;CP/M has eofs in the end of last sector?
  7961. ;do this by hand:
  7962.         or a
  7963.         jr z,load_noaddeofs ;full sector
  7964. ;a=128+bytes loaded
  7965.         neg
  7966. ;a=128-bytes loaded
  7967.         ld b,a
  7968.         ld de,TmpBuff+127       ; Point to buffer end
  7969.         ld a,eof;-1
  7970.         ld (de),a
  7971.         dec de
  7972.         djnz $-2
  7973. load_noaddeofs
  7974.         endif
  7975.         ld      de,TmpBuff      ; Point to buffer
  7976.         ld      b,RecLng
  7977. l258d:
  7978.          ;ld (hl),eof ;why there was not?
  7979.          ;inc hl
  7980.         ld      a,(de)          ; Scan for EOF
  7981.         cp      -1
  7982.          ;jr z,$
  7983.         ret     z
  7984.         and     NOMSB ;why???
  7985.         cp      eof
  7986.          ;jr z,$
  7987.         ret     z
  7988.          ;dec hl
  7989.         ld      (hl),a          ; Unpack data
  7990.         inc     hl
  7991.         inc     de
  7992.         djnz    l258d
  7993.         jr      l2573
  7994. l259d:
  7995.         jp      a_DUMMY         ; *** REDIRECTED ***
  7996. ;
  7997. ; Tell file not found
  7998. ;
  7999. l25a0:
  8000.         call    l0200
  8001.         db      cr,lf
  8002.         db      'File not found'
  8003.         db      null
  8004. l25b4:
  8005.         jp      l2e76           ; Get ESCape
  8006. ;
  8007. ; Redirected error if work file read error
  8008. ;
  8009. l25b7:
  8010.         call    l25a0           ; Tell file not found
  8011.         jr      l25ee
  8012. ;
  8013. ; Redirected error if work file not found
  8014. ;
  8015. l25bc:
  8016.         call    l0200
  8017.         db      cr,lf
  8018.         db      'New File'
  8019.         db      null
  8020.         inc     hl
  8021.         push    hl
  8022.         ld      hl,1000
  8023.         call    l021d           ; Delay one second
  8024.         pop     hl
  8025.         ret
  8026. ;
  8027. ; Tell file too big
  8028. ;
  8029. l25d4:
  8030.         ld      hl,(l4546)      ; Get end of text
  8031.         call    l0200
  8032.         db      cr,lf
  8033.         db      'File too big'
  8034.         db      null
  8035.         jr      l25b4
  8036. ;
  8037. ; Process file too big error
  8038. ;
  8039. l25eb:
  8040.         call    l25d4           ; Tell file too big
  8041. l25ee:
  8042.         xor     a
  8043.         ld      (l451d+Fdrv),a  ; Indicate no file
  8044.         jp      l223b           ; Enter menue
  8045. ;
  8046. ; Set extension .BAK
  8047. ;
  8048. l25f5:
  8049.         ld      hl,l005c+Fdrv+Fname
  8050.         ld      (hl),'B'
  8051.         inc     hl
  8052.         ld      (hl),'A'
  8053.         inc     hl
  8054.         ld      (hl),'K'
  8055.         ret
  8056. ;
  8057. ; Save work file on request
  8058. ;
  8059. l2601:
  8060.         db      skip
  8061. ;
  8062. ; Save work file on request
  8063. ;
  8064. l2602:
  8065.         xor     a
  8066.         ex      af,af'
  8067.         ld      a,(l447f)       ; Test text changed
  8068.         or      a
  8069.         ret     z               ; Nope
  8070.         ex      af,af'
  8071.         or      a               ; Test request
  8072.         jr      z,l2639         ; Save file if not
  8073.         call    l0200
  8074.         db      'Workfile '
  8075.         db      null
  8076.         call    l3135           ; Type name of file
  8077.         call    l0200
  8078.         db      ' not saved. Save'
  8079.         db      null
  8080.         xor     a
  8081.         ld      (l447f),a       ; Set no text changed
  8082.         call    l2d21           ; Ask for YES or NO
  8083.         ret     z               ; NO
  8084. ;
  8085. ; ###########################
  8086. ; ### MAIN MENUE S - Save ###
  8087. ; ###########################
  8088. ;
  8089. l2639:
  8090.         call    l2d50           ; Get file
  8091.         ld      hl,l451d
  8092.         push    hl
  8093.         ld      de,l005c
  8094.         ld      bc,FCBlen
  8095.         ldir                    ; Unpack file
  8096.         call    l0200           ; Tell action
  8097.         db      cr,lf
  8098.         db      'Saving '
  8099.         db      null
  8100.         ld      de,l005c
  8101.         call    l2df8           ; Tell name of file
  8102.         ld      hl,(l4546)      ; Get end of text
  8103.         dec     hl
  8104.         ld      (hl),eof        ; Close text
  8105.         call    l25f5           ; Set extension .BAK
  8106.         call    l26d9           ; Clear FCB
  8107.         ld      c,_delete
  8108.         call    _BDOS           ; Delete file
  8109.         ld      hl,l005c+Fdrv
  8110.         ld      de,l005c+DIRlen
  8111.         xor     a
  8112.         ld      (l447f),a       ; Set no text changed
  8113.         ld      (de),a
  8114.         inc     a
  8115.         ld      (l44f2),a       ; Set rename flag
  8116.         inc     de
  8117.         ld      bc,DIRlen-1
  8118.         ldir                    ; Unpack name
  8119.         pop     hl
  8120.         ld      de,l005c
  8121.         ld      bc,DIRlen
  8122.         ldir                    ; Get new file
  8123.         ld      c,_rename
  8124.         call    BDOS_with_FCB1          ; Rename it
  8125.         ld      hl,(l4544)      ; Get start of text
  8126. l2692:
  8127.         push    hl
  8128.         call    l26d9           ; Clear FCB
  8129.         ld      c,_make
  8130.         call    _BDOS           ; Create new file
  8131.         pop     hl
  8132.         inc     a
  8133.         jr      z,l26ed         ; Error creating file
  8134.         push    hl
  8135.         ld      de,TmpBuff
  8136.         push    de
  8137.         ld      c,_setdma
  8138.         call    _BDOS           ; Set disk buffer
  8139.         pop     de
  8140.         pop     hl
  8141.         ld      b,RecLng        ; Set length of buffer
  8142. l26ad:
  8143.         ld      a,(hl)          ; Get from memory
  8144.         inc     hl
  8145. l26af:
  8146.         ld      (de),a          ; Put to buffer
  8147.         inc     de
  8148.         djnz    l26c6
  8149.         ld      b,a             ; Save last character
  8150.         push    bc
  8151.         push    hl
  8152.         ld      c,_wrseq
  8153.         call    BDOS_with_FCB1          ; Write record to file
  8154.         pop     hl
  8155.         pop     bc
  8156.         or      a               ; Test success
  8157.         jr      nz,l26fe        ; Nope, write error
  8158.         ld      de,TmpBuff      ; Reset pointer
  8159.         ld      a,b             ; Get back last character
  8160.         ld      b,RecLng        ; Reset buffer length
  8161. l26c6:
  8162.         cp      eof             ; Test end of file
  8163.         jr      nz,l26ad        ; Nope, go on
  8164.         ld      a,b
  8165.         sub     RecLng          ; Test record boundary
  8166.         ld      a,eof
  8167.         jr      nz,l26af        ; Nope, write end
  8168.         ld      c,_close        ; Close file
  8169. ;
  8170. ; Do OS call with standard FCB
  8171. ;
  8172. BDOS_with_FCB1:
  8173.         ld      de,l005c
  8174.         jp      _BDOS           ; Do file call
  8175. ;
  8176. ; Clear FCB
  8177. ;
  8178. l26d9:
  8179.         ld      de,l005c
  8180. ;
  8181. ; Clear FCB ^DE
  8182. ;
  8183. l26dc:
  8184.         push    de
  8185.         ld      hl,_ex
  8186.         add     hl,de           ; Point to extent
  8187.         ld      (hl),0          ; Clear it
  8188.         ld      d,h
  8189.         ld      e,l
  8190.         inc     de
  8191.         ld      bc,FCBlen-_ex-1
  8192.         ldir                    ; Clear remainder
  8193.         pop     de
  8194.         ret
  8195. ;
  8196. ; Create file error
  8197. ;
  8198. l26ed:
  8199.         call    l0200           ; Tell error
  8200.         db      '  Directory'
  8201.         db      null
  8202.         jr      l2708
  8203. ;
  8204. ; Write file error
  8205. ;
  8206. l26fe:
  8207.         call    l0200           ; Tell error
  8208.         db      '  Disk'
  8209.         db      null
  8210. l2708:
  8211.         call    l0200
  8212.         db      ' full'
  8213.         db      null
  8214.         call    l2e76           ; Get ESCape
  8215.         call    l26d9           ; Clear FCB
  8216.         ld      c,_delete
  8217.         call    BDOS_with_FCB1          ; Delete file
  8218.         ld      a,(l44f2)       ; Test to be renamed
  8219.         or      a
  8220.         ret     z               ; Nope
  8221.         ld      (l447f),a       ; Set text changed
  8222.         ld      hl,l005c+Fdrv
  8223.         ld      de,l005c+DIRlen
  8224.         xor     a
  8225.         ld      (l44f2),a       ; Clear rename flag
  8226.         ld      (de),a          ; Clear name entry
  8227.         inc     de
  8228.         ld      bc,DIRlen-1
  8229.         ldir                    ; Unpack FCB
  8230.         call    l25f5           ; Set extension .BAK
  8231.         ld      c,_rename
  8232.         call    BDOS_with_FCB1          ; Rename file
  8233.         jp      l223b           ; Enter menue
  8234. ;
  8235. ; ####################################
  8236. ; ### SUB MENUE M - Compile Memory ###
  8237. ; ####################################
  8238. ;
  8239. l2740:
  8240.         ld      a,1             ; Set memory
  8241.         jr      l274a
  8242. ;
  8243. ; ######################################
  8244. ; ### SUB MENUE C - Compile Com-file ###
  8245. ; ######################################
  8246. ;
  8247. l2744:
  8248.         ld      a,2             ; Set .COM file
  8249.         jr      l274a
  8250. ;
  8251. ; ######################################
  8252. ; ### SUB MENUE H - Compile cHn-file ###
  8253. ; ######################################
  8254. ;
  8255. l2748:
  8256.         ld      a,3             ; Set .CHN file
  8257. l274a:
  8258.         ld      (l44f3),a       ; Set compile mode
  8259.         jp      l2d9f           ; Force compile
  8260. ;
  8261. ; ###################################
  8262. ; ### SUB MENUE S - Start address ###
  8263. ; ###################################
  8264. ;
  8265. l2750:
  8266.         call    l0200           ; Tell what we want
  8267.         db      'Start address'
  8268.         db      null
  8269.         call    l2261           ; Input string
  8270.         ld      hl,l20e2        ; Set default
  8271.         call    nz,l2dd9        ; Get new hex value
  8272.         ld      (l44f4),hl      ; Save new start address
  8273.         ret
  8274. ;
  8275. ; #################################
  8276. ; ### SUB MENUE E - End address ###
  8277. ; #################################
  8278. ;
  8279. l276e:
  8280.         call    l0200           ; Tell what we want
  8281.         db      'End address'
  8282.         db      null
  8283.         call    l2261           ; Input string
  8284.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  8285.         ld      bc,-MEMGAP
  8286.         add     hl,bc           ; Calculate default
  8287.         call    nz,l2dd9        ; Get new hex value
  8288.         ld      (l44f6),hl      ; Set top of available memory
  8289.         ret
  8290. ;
  8291. ; Exit memory resident program
  8292. ;
  8293. l278e:
  8294.         call    l20e5           ; Set up environment
  8295.         ld      hl,(l00ce)      ; Get current PC
  8296.         ld      a,h
  8297.         or      l
  8298.         jr      nz,l27b1        ; Process error
  8299.         jp      l223b           ; Enter menue
  8300. ;
  8301. ; #########################################
  8302. ; ### SUB MENUE F - Find run-time error ###
  8303. ; #########################################
  8304. ;
  8305. l279b:
  8306.         call    l0200           ; Tell what we want
  8307.         db      'Enter PC'
  8308.         db      null
  8309.         call    l2261           ; Input string
  8310.         ret     z               ; Empty
  8311.         call    l2dd9           ; Get hex PC
  8312.         ld      (l00ce),hl      ; Set current PC
  8313. l27b1:
  8314.         call    l01e1           ; Give new line
  8315.         call    l27d7           ; Load file into memory
  8316.         ld      hl,0
  8317.         ld      (l7904),hl      ; Clear address
  8318.         ld      a,2
  8319.         ld      (CmpTyp),a      ; Set searching
  8320.         call    l0200           ; Tell searching
  8321.         db      cr,lf
  8322.         db      'Searching'
  8323.         db      null
  8324.         call    l2d9f           ; Force compile
  8325.         jp      l28d0           ; Go compile
  8326. ;
  8327. ; Load file into memory
  8328. ;
  8329. l27d7:
  8330.         call    l2d4b           ; Test work file defined
  8331.         call    z,l2d50         ; Get file if not
  8332.         call    l2d7a           ; Test main file here
  8333. l27e0:
  8334.         ld      hl,l451d
  8335.         jr      nz,l27ea        ; Got any file
  8336.         call    l2d50           ; Get file
  8337.         jr      l2808
  8338. l27ea:
  8339.         call    l2d7f           ; Test same files
  8340.         jr      z,l27e0         ; Yeap, get another one
  8341.         call    l2602           ; Save work file
  8342.         ld      hl,l25eb
  8343.         ld      (l257c+1),hl    ; Set vector for file too big
  8344.         ld      hl,l25b7
  8345.         ld      (l259d+1),hl    ; Set vector for read error
  8346.         ld      de,l44f9        ; Point to main file
  8347.         push    de
  8348.         call    l2518           ; Load text file ;closes automatically
  8349.         ld      a,1
  8350.         pop     hl
  8351. l2808:
  8352.         ld      (l44f1),a       ; Re/Set file flag
  8353.         ld      de,FFCB
  8354.         ld      bc,FCBlen
  8355.         ldir                    ; Unpack file
  8356.         xor     a
  8357.         ld      (CmpTyp),a      ; Set compile to memory
  8358.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  8359.         ld      (l790a),hl      ; Set end of code
  8360. l281d:
  8361.         ld      hl,(l4546)      ; Get end of text
  8362.         ld      (hl),eof        ; Set end of file
  8363.         inc     hl
  8364.         ld      (l7904),hl      ; Set for code start address
  8365.         ret
  8366. ;
  8367. ; ##############################
  8368. ; ### MAIN MENUE C - Compile ###
  8369. ; ##############################
  8370. ;
  8371. l2827:
  8372.         call    l27d7           ; Load file into memory
  8373.         ld      a,(l44f3)       ; Get compile mode
  8374.         dec     a               ; Test compile to memory
  8375.         jp      z,l28aa         ; Yeap
  8376.         dec     a               ; Test compile to .COM file
  8377.         push    af
  8378.         jr      nz,l283c        ; Nope
  8379.         ld      a,'C'           ; Load .COM
  8380.         ld      hl,'O'+'M'*256
  8381.         jr      l2841
  8382. l283c:
  8383.         ld      a,'C'           ; Load .CHN
  8384.         ld      hl,'H'+'N'*256
  8385. l2841:
  8386.         ld      (FFCB+Fdrv+Fname),a
  8387.         ld      (FFCB+Fdrv+Fname+1),hl
  8388.         ld      a,1
  8389.         ld      (CmpTyp),a      ; Set compile to file
  8390.         ld      hl,(l44f4)      ; Get start address of compiler
  8391.         ld      (l7904),hl      ; Save
  8392.         ld      hl,(l44f6)      ; Get top of available memory
  8393.         ld      (l790a),hl      ; Save also
  8394.         ld      de,FFCB
  8395.         push    de
  8396.         call    l26dc           ; Clear FCB
  8397.         ld      c,_delete
  8398.         call    _BDOS           ; Delete file
  8399.         pop     de
  8400.         ld      c,_make
  8401.         call    _BDOS           ; Create new file
  8402.         inc     a               ; Test success
  8403.         jp      z,l2a5a         ; Nope, error
  8404.         pop     af              ; Get back .COM or .CHN
  8405.         ld      hl,0x0100;TPA
  8406.         jr      z,l2877         ; Got .COM
  8407.         ld      hl,(l7904)      ; Get code start address
  8408. l2877:
  8409.         ld      (CodePC),hl     ; Save for current PC
  8410.         ex      de,hl
  8411. l287b:
  8412.         ld      hl,(l7904)      ; Get code start address
  8413.         scf
  8414.         sbc     hl,de           ; Test end reached
  8415.         jr      c,l28a9         ; Yeap
  8416.         ld      hl,(l7904)      ; Get code start address
  8417.         ld      (progstartaddr),hl;(TPA+1),hl   ; Set as start address
  8418.         push    de
  8419.         ld      c,_setdma
  8420.         call    _BDOS           ; Set disk buffer
  8421.         ld      c,_wrseq
  8422.         ld      de,FFCB
  8423.         call    _BDOS           ; Write record to file
  8424.         pop     de
  8425.         ld      hl,l20e2
  8426.         ld      (progstartaddr),hl;(TPA+1),hl   ; Reset start address
  8427.         ;or     a               ; Test I/O success
  8428.         ;jp     nz,l2a5a        ; Error, disk full
  8429.         ld      hl,RecLng
  8430.         add     hl,de           ; Advance buffer
  8431.         ex      de,hl
  8432.         jr      l287b
  8433. l28a9:
  8434.         db      skip
  8435. l28aa:
  8436.         xor     a
  8437.         call    l0200           ; Tell compiling
  8438. ;
  8439.         db      cr,lf
  8440.         db      'Compiling '
  8441.         db      null
  8442.         ld      de,FFCB
  8443.         or      a               ; Test compile to memory
  8444.         jr      z,l28cd         ; Yeap
  8445.         call    l0200           ; Indicate file
  8446. ;
  8447.         db      ' --> '
  8448.         db      null
  8449.         call    l2df8           ; Tell name of file
  8450. l28cd:
  8451.         call    l2d9f           ; Force compile
  8452. l28d0:
  8453.         call    l01e1           ; Give new line
  8454.         call    COMPILE         ; Compile             ;must close output file!!!
  8455.         ld      a,(l7901)       ; Get error code
  8456.         cp      _ABORT          ; Test abort
  8457.         jr      nz,l28fa        ; Nope
  8458.         call    l0200           ; Tell abortion
  8459. ;
  8460.         db      cr,lf,lf
  8461.         db      'Compilation aborted'
  8462.         db      null
  8463.         jp      l223b           ; Enter menue
  8464. l28fa:
  8465.         call    l0200           ; Tell lines
  8466.         db      ' lines'
  8467.         db      cr,lf,lf,null
  8468.         ld      a,(l7901)       ; Get error code
  8469.         or      a               ; Test any error
  8470.         jp      nz,l2970        ; Yeap
  8471.         ld      a,(CmpTyp)      ; Get compile flag
  8472.         cp      2               ; Test searching
  8473.         jr      nz,l292a        ; Nope
  8474.         call    l2a7a           ; Tell error position
  8475.         call    l0200
  8476.         db      'not found'
  8477.         db      cr,lf,null
  8478.         jp      l223b           ; Re-enter menue
  8479. l292a:
  8480.         or      a               ; Test compile to memory
  8481.         jr      z,l293a         ; Yeap
  8482.         ld      hl,(l7904)      ; Get code start address
  8483.         ld      de,l20e2        ; Get start of application
  8484.         or      a
  8485.         sbc     hl,de
  8486.         add     hl,de
  8487.         call    nz,l232e        ; Tell free
  8488. l293a:
  8489.         call    l0200
  8490.         db      'Code: '
  8491.         db      null
  8492.         ld      de,(l7904)      ; Get code start address
  8493.         ld      hl,(l7906)      ; Get code end address
  8494.         push    hl
  8495.         dec     hl
  8496.         call    l2338           ; Tell free bytes
  8497.         pop     de
  8498.         ld      hl,(DataBeg)    ; Get start of data
  8499.         push    hl
  8500.         call    l232e           ; Tell free
  8501.         pop     de
  8502.         inc     de
  8503.         ld      hl,(l790a)      ; Get end of code
  8504.         call    l0200
  8505.         db      'Data: '
  8506.         db      null
  8507.         call    l2338           ; Tell free bytes
  8508.         ld      a,-1
  8509.         ld      (l4542),a       ; Set no compile
  8510.         ret
  8511. ;
  8512. ; Process compiler error
  8513. ;
  8514. l2970:
  8515.         cp      _DskFull        ; Test disk error
  8516.         jp      nc,l2a5a        ; Error, disk full
  8517.         cp      _FndRTerr       ; Test run-time error found
  8518.         jr      nc,l29ec        ; Yeap
  8519.         ld      b,a             ; Save error number
  8520.         call    l0200           ; Tell error
  8521.         db      'Error '
  8522.         db      null
  8523.         ld      h,0
  8524.         ld      l,b             ; Build 16 bit number
  8525.         push    bc
  8526.         call    l2e61           ; Print it
  8527.         pop     bc
  8528.         ld      a,(l4541)       ; Test error message file read
  8529.         or      a
  8530.         jr      z,l29f8         ; No message file
  8531.         ld      hl,(l429e)      ; Get base of message file
  8532. l2995:
  8533.         ld      a,(hl)          ; Get character
  8534.         cp      eof             ; Test end of message
  8535.         jr      z,l29f8         ; Yeap
  8536.         cp      ' '             ; Test control
  8537.         jr      c,l29ad         ; Yeap, skip it
  8538.         sub     '0'             ; Build number - always two digits
  8539.         ld      c,a
  8540.         add     a,a
  8541.         add     a,a
  8542.         add     a,c
  8543.         add     a,a
  8544.         inc     hl
  8545.         add     a,(hl)          ; Combine number
  8546.         sub     '0'             ; Fix it
  8547.         inc     hl
  8548.         cp      b               ; Test message found
  8549.         jr      z,l29b6         ; Got it
  8550. l29ad:
  8551.         ld      a,(hl)
  8552.         inc     hl
  8553.         cp      cr              ; Skip to end of line
  8554.         jr      nz,l29ad
  8555.         inc     hl
  8556.         jr      l2995           ; Try next line
  8557. l29b6:
  8558.         call    l0200           ; Tell result
  8559. ;
  8560.         db      ': '
  8561.         db      null
  8562. l29bc:
  8563.         ld      a,(hl)          ; Get character
  8564.         cp      cr              ; Test end of text
  8565.         jr      z,l29f8         ; That's all
  8566.         cp      ' '             ; Test combined message
  8567.         jr      nc,l29e6        ; Nope
  8568.         ld      de,(l429e)      ; Get base of message file
  8569. l29c9:
  8570.         ld      a,(de)          ; Get character
  8571.         inc     de
  8572.         cp      ' '             ; Test printable
  8573.         jr      nc,l29dd        ; Yeap, skip it
  8574.         cp      (hl)            ; Test extension found
  8575.         jr      nz,l29dd        ; Nope
  8576. l29d2:
  8577.         ld      a,(de)          ; Get from extended part
  8578.         cp      cr              ; Test end of line
  8579.         jr      z,l29e9         ; Yeap
  8580.         call    puttoconsole_a          ; Put substring to console
  8581.         inc     de
  8582.         jr      l29d2
  8583. l29dd:
  8584.         ld      a,(de)
  8585.         inc     de
  8586.         cp      cr              ; Skip this line
  8587.         jr      nz,l29dd
  8588.         inc     de
  8589.         jr      l29c9
  8590. l29e6:
  8591.         call    puttoconsole_a          ; Put to console
  8592. l29e9:
  8593.         inc     hl
  8594.         jr      l29bc           ; Loop on
  8595. ;
  8596. ; Got position of run-time error
  8597. ;
  8598. l29ec:
  8599.         call    l2a7a           ; Tell error position
  8600.         call    l0200
  8601.         db      'found'
  8602.         db      null
  8603. l29f8:
  8604.         xor     a
  8605.         ld      (l44f1),a       ; Clear file flag
  8606.         ld      a,(IncFlg)      ; Test read from memory
  8607.         or      a
  8608.         jr      z,l2a41         ; Nope
  8609.         ld      a,'.'
  8610.         call    puttoconsole_a          ; Put to console
  8611.         call    l2602           ; Save work file
  8612.         ld      de,l451d
  8613.         ld      hl,l790f
  8614.         ld      bc,Fdrv+Fname+Fext
  8615.         ldir                    ; Copy include file
  8616.         call    l2506           ; Load it
  8617.         call    l0200
  8618.         db      cr,lf
  8619.         db      'Error found in above include file'
  8620.         db      null
  8621.         jr      l2a51
  8622. l2a41:
  8623.         call    l2d7a           ; Test main file here
  8624.         jr      z,l2a51         ; Nope
  8625.         ld      de,l451d
  8626.         ld      hl,l44f9        ; Point to main file
  8627.         ld      bc,Fdrv+Fname+Fext
  8628.         ldir                    ; Copy file
  8629. l2a51:
  8630.         call    l2e76           ; Get ESCape
  8631.         ld      hl,(l790c)      ; Fetch current editor address
  8632.         jp      l2afe           ; And fall into edit
  8633. ;
  8634. ; Process disk full
  8635. ;
  8636. l2a5a:
  8637.         call    l0200           ; Tell error
  8638. ;
  8639.         db      'Disk or directory full'
  8640.         db      null
  8641.         call    l2e76           ; Get ESCape
  8642.         jp      l223b           ; Enter menue
  8643. ;
  8644. ; Tell error position message
  8645. ;
  8646. l2a7a:
  8647.         call    l0200
  8648.         db      'Run-time error position '
  8649.         db      null
  8650.         ret
  8651. ;
  8652. ; ##########################
  8653. ; ### MAIN MENUE R - Run ###
  8654. ; ##########################
  8655. ;
  8656. l2a97:
  8657.         ld      a,(l4542)       ; Get compile flag
  8658.         or      a
  8659.         call    z,l2827         ; Compile before run
  8660.         ld      a,(l44f3)       ; Get compile flag
  8661.         dec     a
  8662.         jr      z,l2adf         ; Got to memory
  8663.         dec     a
  8664.         ret     nz              ; Skip chain
  8665.         call    l2b33           ; Load overlay file
  8666.         ret     z               ; Not found
  8667.         call    l2d7a           ; Test main file here
  8668.         ld      hl,l451d
  8669.         jr      z,l2ab5         ; Nope
  8670.         ld      hl,l44f9        ; Point to main file
  8671. l2ab5:
  8672.         ld      de,FFCB
  8673.         ld      bc,Fdrv+Fname+Fext
  8674.         ldir                    ; Unpack FCB
  8675.         ld      a,'C'           ; Set .COM
  8676.         ld      hl,'O'+'M'*256
  8677.         ld      (FFCB+Fdrv+Fname),a
  8678.         ld      (FFCB+Fdrv+Fname+1),hl
  8679.         ld      de,FFCB
  8680.         call    l26dc           ; Clear FCB
  8681.         push    de
  8682.         ld      c,_open
  8683.         call    _BDOS           ; Open file ;WHERE IS CLOSE???
  8684.         pop     hl
  8685.         inc     a               ; Test file here
  8686.         jp      z,l2104         ; Nope, init session
  8687.         ld      de,l42a0        ; Set dummy parameter
  8688.         jp      l2b7a           ; Prepare overlay
  8689. l2adf:
  8690.         ld      (l0080),a       ; Clear parameter
  8691.         call    l281d           ; Set text and code pointer
  8692.         call    l0200           ; Tell running
  8693.         db      cr,lf
  8694.         db      'Running'
  8695.         db      cr,lf,null
  8696.         ld      hl,(l7904)      ; Get code start address
  8697.         jp      (hl)            ; And go
  8698. ;
  8699. ; ###########################
  8700. ; ### MAIN MENUE E - Edit ###
  8701. ; ###########################
  8702. ;
  8703. l2af8:
  8704.         call    l2d50           ; Get file
  8705.         ld      hl,-1           ; Set zero offset
  8706. l2afe:
  8707.         push    hl
  8708.         ld      hl,(l00a6+1) ;ok ;FIXME
  8709.         ld      (l421e),hl      ; Change I/O
  8710.         ld      hl,l4214
  8711.         ld      (l00a6+1),hl ;ok ;FIXME
  8712.         pop     hl
  8713.         jp      l2e91           ; Go edit
  8714. ;
  8715. ; Control: EXIT EDITOR
  8716. ;
  8717. l2b0f:
  8718.         call    l3e40           ; Sample character
  8719.         ld      hl,(l0169)      ; Get screen lines
  8720.         dec     l               ; Fix row
  8721.         ld      h,0             ; Set column
  8722.         call    l02a2           ; Position cursor
  8723.         ld      hl,(l421e)
  8724.         ld      (l00a6+1),hl    ; Reset I/O
  8725.         jp      l223b
  8726. ;
  8727. ; ###########################
  8728. ; ### MAIN MENUE Q - Quit ###
  8729. ; ###########################
  8730. ;
  8731. l2b24:
  8732.         call    l2601           ; Save work file
  8733.         call    l0310           ; Give lead out sequence
  8734.         jp      OS              ; Exit to OS
  8735. ;
  8736. ; ##############################
  8737. ; ### MAIN MENUE X - eXecute ###
  8738. ; ##############################
  8739. ;
  8740. l2b2d:
  8741.         call    l2b33           ; Load overlay file
  8742.         ret     z               ; Not found
  8743.         jr      l2b5a           ; Go
  8744. ;
  8745. ; Load overlay file
  8746. ; Z set says not found
  8747. ;
  8748. l2b33:
  8749.         call    l2601           ; Save work file
  8750.         ld      de,l217d        ; Set name
  8751.         ld      a,'O'
  8752.         ld      hl,'V'+'R'*256
  8753.         call    l2e20           ; Prepare .OVR file
  8754.         ret     z
  8755.         ld      de,a_OVLADR-RecLng
  8756. l2b45:
  8757.         ld      hl,RecLng
  8758.         add     hl,de           ; Build disk buffer address
  8759.         push    hl
  8760.         ex      de,hl
  8761.         ld      c,_setdma
  8762.         call    BDOS            ; Set disk buffer
  8763.         ld      c,_rdseq
  8764.         call    BDOS_with_FCB1          ; Read record
  8765.         pop     de
  8766.         ;or     a               ; Test end of file
  8767.         ;jr     z,l2b45         ; Nope, loop on
  8768.          cp 128 ;EOF in NedoOS
  8769.          jr nz,l2b45            ; Read was successfull
  8770.         ret
  8771. ;
  8772. ; Execute file
  8773. ;
  8774. l2b5a:
  8775.         call    l0200           ; Tell program
  8776.         db      cr,lf
  8777.         db      'Program'
  8778.         db      null
  8779.         call    l2261           ; Input string
  8780.         jp      z,l2104         ; No input
  8781.         ld      a,'C'
  8782.         ld      hl,'O'+'M'*256
  8783.         call    l2e20           ; Prepare .COM file
  8784.         jr      z,l2b5a         ; Not there, retry
  8785.         ld      hl,l005c
  8786. l2b7a:
  8787.         push    de              ; Set argument pointer
  8788.         push    hl              ; Set FCB
  8789.         ld      a,(l44f8)
  8790.         push    af              ; Set logged disk
  8791.         ld      hl,l03ee
  8792.         push    hl              ; Set parse file routine
  8793.         ld      hl,l00f4
  8794.         push    hl              ; Set available memory
  8795.         ld      hl,l4450
  8796.         push    hl              ; Set current memory pointer
  8797.         ld      hl,l2104
  8798.         push    hl              ; Set return address
  8799.         jp      a_OVLADR                ; Execute overlay
  8800. ;
  8801. ; ################################
  8802. ; ### MAIN MENUE D - Directory ###
  8803. ; ################################
  8804. fcbmask
  8805.         db 0
  8806.         db "???????????"
  8807.         ds FCB_sz-11-1
  8808. fcbmask_filename=fcbmask+FCB_FNAME
  8809. ;
  8810. l2b93:
  8811.         call    l0200
  8812.         db      'Dir mask'
  8813.         db      null
  8814.         call    l2261           ; Input string
  8815.         call    l03ee           ; Parse file
  8816.         ;ld     c,_retdsk
  8817.         ;call   _BDOS           ; Return current disk (return L=A=current drive)
  8818.        xor a
  8819.         push    af
  8820.         push    af
  8821.         ld      a,(l005c)       ;ok ;FIXME ; Get disk
  8822.         or      a               ; Test default
  8823.         jr      z,l2bbb         ; Yeap
  8824.         pop     hl              ; Clean stack
  8825.         dec     a
  8826.         ld      e,a
  8827.         push    af              ; Set new disk
  8828.         ;ld     c,_seldsk
  8829.         ;call   _BDOS           ; Select disk
  8830. l2bbb:
  8831.         pop     af
  8832.         ;add    a,'A'           ; Make disk ASCII
  8833.         ;ld     (l2c8d),a       ; Save disk
  8834.         ;ld     de,TmpBuff
  8835.         ;ld     c,_setdma
  8836.         ;call   _BDOS           ; Set disk buffer
  8837.         ld      de,0            ; Clear flag and count
  8838.         ld      c,_srcfrs
  8839. l2bce:
  8840.         push    de
  8841.          push bc
  8842.          ld     de,TmpBuff
  8843.          ld     c,_setdma
  8844.          call   _BDOS           ; Set disk buffer
  8845.          pop bc
  8846.          ld de,fcbmask
  8847.         call    BDOS_with_FCB1          ; Search for file
  8848.         pop     de
  8849.         ld      c,a
  8850.         inc     a               ; Test valid one
  8851.         jr      z,l2c29         ; Nope
  8852.         ld      a,c
  8853.         add     a,a             ; Result *32
  8854.         add     a,a
  8855.         add     a,a
  8856.         add     a,a
  8857.         add     a,a
  8858.         ld      c,a
  8859.         ld      b,0
  8860.         ld      hl,TmpBuff+_SYS
  8861.         add     hl,bc           ; Point to SYS bit
  8862.         bit     7,(hl)          ; Test set
  8863.         jr      nz,l2c25        ; Yeap, skip display
  8864.         ld      d,-1            ; Set any found flag
  8865.         ld      hl,TmpBuff
  8866.         add     hl,bc           ; Point to entry
  8867.         inc     e               ; Test first file
  8868.         dec     e
  8869.         jr      nz,l2bff        ; Nope
  8870.         ld      a,(l0168)       ; Get screen columns
  8871.         dec     a
  8872.         ld      e,-1
  8873. l2bf8:
  8874.         inc     e
  8875.         sub     Dirlng          ; Calculate files per line
  8876.         jr      nc,l2bf8
  8877.         jr      l2c05
  8878. l2bff:
  8879.         call    l0200
  8880. ;
  8881.         db      ': '
  8882.         db      null
  8883. l2c05:
  8884.         ld      b,Fname+Fext    ; Set length
  8885. l2c07:
  8886.         inc     hl
  8887.         ld      a,(hl)
  8888.         and     NOMSB           ; Strip off offset
  8889.         call    puttoconsole_a          ; Put to console
  8890.         ld      a,b
  8891.         cp      Fext+1          ; Test extension
  8892.         ld      a,' '
  8893.         call    z,puttoconsole_a                ; Put blank to console if so
  8894.         djnz    l2c07
  8895.         dec     e               ; Test remainder in line
  8896.         jr      z,l2c22         ; Nope
  8897.         ld      a,' '
  8898.         call    puttoconsole_a          ; Put to console
  8899.         jr      l2c25
  8900. l2c22:
  8901.         call    l01e1           ; Give new line
  8902. l2c25:
  8903.         ld      c,_srcnxt       ; Search next
  8904.         jr      l2bce
  8905. l2c29:
  8906.         inc     e               ; Test any file left
  8907.         dec     e
  8908.         call    nz,l01e1        ; Give new line if so
  8909.         inc     d               ; Test any file found
  8910.         jr      z,l2c3e         ; Yeap
  8911.         call    l0200           ; Else tell it
  8912. ;
  8913.         db      'No file'
  8914.         db      cr,lf,null
  8915. l2c3e:
  8916.         call    l01e1           ; Give new line
  8917.       if 0
  8918. ;
  8919. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8920. ; !!! FOLLOWING IS ERRONEOUS ON CP/M 3.x !!!
  8921. ; !!! USES BDOS FUNCTION 46 ON CP/M 3.x  !!!
  8922. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8923. ;
  8924.         ld      c,_getdpb
  8925.         call    BDOS            ; Fetch disk parameter block
  8926.         push    hl
  8927.         pop     ix              ; Copy it
  8928.         ld      a,(ix+3)        ; Get block mask
  8929.         inc     a               ; Fix
  8930.         rra                     ; DIV 8 (1-> 1k, 2->2k etc.)
  8931.         rra
  8932.         rra
  8933.         and     DPBMASK         ; Mask it
  8934.         ld      (l7b71),a       ; Save block size
  8935.         ld      l,(ix+5)        ; Fetch block count
  8936.         ld      h,(ix+6)
  8937.         ld      (l7b6f),hl      ; Save it
  8938.         inc     hl              ; Fix
  8939.         call    l2cc6           ; Build size in bytes
  8940.         push    hl              ; Save it
  8941. ;
  8942. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8943. ; !!! THE ALLOCATION VECTOR MAY BE FOUND IN ANOTHER !!!
  8944. ; !!! MEMORY BANK RUNNING CP/M 3.X.                 !!!
  8945. ; !!! THE NEXT CALCULATION MAY BE WRONG THEREFORE   !!!
  8946. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8947. ;
  8948.         ld      c,_getalv
  8949.         call    BDOS            ; Get allocation vector
  8950.         ex      de,hl
  8951.         ld      hl,(l7b6f)      ; Get block count
  8952.         ld      bc,0
  8953.         call    l2ca5           ; Get free blocks
  8954.         ld      h,b
  8955.         ld      l,c
  8956.         call    l2cc6           ; Build size in bytes
  8957.         call    l0200           ; Tell size
  8958. ;
  8959.         db      'Bytes Remaining On '
  8960. l2c8d:
  8961.         db      'X: '
  8962.         db      null
  8963.         ex      de,hl
  8964.         pop     hl              ; Get back total size
  8965.         or      a
  8966.         sbc     hl,de           ; Calculate free bytes
  8967.         call    l2e61           ; Print number
  8968.         ld      a,'k'
  8969.         call    puttoconsole_a          ; Put to console
  8970.       endif
  8971.         pop     af              ; Get back selected disk
  8972.         ld      e,a
  8973.        ret
  8974.         ;ld     c,_seldsk
  8975.         ;jp     _BDOS           ; Select disk
  8976. ;
  8977. ; BC holds resulting block count
  8978. ; DE holds allocation vector
  8979. ; HL holds block count
  8980. ;
  8981. ; BC holds free blocks
  8982. ;
  8983. l2ca5:
  8984.         push    bc
  8985.         ld      bc,-8
  8986.         add     hl,bc           ; Fix block count
  8987.         pop     bc
  8988.         ld      a,h             ; Get hi
  8989.         or      a
  8990.         ld      a,(de)
  8991.         jp      p,l2cb8
  8992. l2cb1:
  8993.         inc     l
  8994.         jr      z,l2cbd         ; Done, calculate free blocks
  8995.         or      a
  8996.         rra
  8997.         jr      l2cb1
  8998. l2cb8:
  8999.         call    l2cbd           ; Calculate free blocks from bits
  9000.         jr      l2ca5
  9001. ;
  9002. ; Calculate free blocks in reg BC from vector in Accu
  9003. ;
  9004. l2cbd:
  9005.         inc     de              ; Advance allocation vector
  9006. l2cbe:
  9007.         or      a               ; Test end of bit stream
  9008.         ret     z               ; Yeap
  9009.         rra                     ; Get resulting bit
  9010.         jr      nc,l2cbe        ; Not set
  9011.         inc     bc              ; Advance block count
  9012.         jr      l2cbe
  9013. ;
  9014. ; Build bytes in blocks
  9015. ;
  9016. l2cc6:
  9017.         ld      a,(l7b71)       ; Get block size
  9018. l2cc9:
  9019.         rra                     ; Get bit
  9020.         ret     c               ; Got it
  9021.         add     hl,hl           ; Double byte count
  9022.         jr      l2cc9
  9023. ;
  9024. ; ################################
  9025. ; ### MAIN MENUE L - Log drive ###
  9026. ; ################################
  9027. ;
  9028. l2cce:
  9029.         call    l0200           ; Tell what we expect
  9030. ;
  9031.         db      'New drive'
  9032.         db      null
  9033.         call    l2261           ; Input string
  9034.         ld      a,(de)
  9035.         cp      eof             ; Test empty input
  9036.         jr      nz,l2ce8        ; Nope
  9037.         ld      a,(DU)          ;ok ;FIXME ; Get from caller
  9038.         jr      l2cf1
  9039. l2ce8:
  9040.         call    doupcase                ; Convert to upper case
  9041.         sub     'A'             ; Verify in range
  9042.         ret     c
  9043.         cp      'P'-'A'+1
  9044.         ret     nc
  9045. l2cf1:
  9046.         if 1==1
  9047.         ret
  9048.         else
  9049.         push    af
  9050.         ld      c,_resdsk
  9051.         call    _BDOS           ; Reset disk system
  9052.         pop     af
  9053.         ld      (DU),a          ; Set new disk
  9054.         ld      e,a
  9055.         ld      c,_seldsk
  9056.         jp      _BDOS           ; Select disk
  9057.         endif
  9058. ;
  9059. ; Ask for YES or NO - Z set is NO
  9060. ;
  9061. l2d01:
  9062.         call    l0200           ; Tell what we does expect
  9063. ;
  9064.         db      ' (Y/N)? '
  9065.         db      null
  9066. l2d0d:
  9067.         call    readfromkbd             ; Read character
  9068.         call    doupcase                ; Convert to upper case
  9069.         cp      'Y'             ; Test YES
  9070.         jr      z,l2d1b
  9071.         cp      'N'             ; Test NO
  9072.         jr      nz,l2d0d
  9073. l2d1b:
  9074.         call    puttoconsole_a          ; Put to console
  9075.         sub     'N'
  9076.         ret
  9077. ;
  9078. ; Get response Y or N - Z set is NO
  9079. ;
  9080. l2d21:
  9081.         call    l2d01           ; Ask for YES or NO
  9082.         push    af
  9083.         call    l01e1           ; Give new line
  9084.         pop     af
  9085.         ret
  9086. ;
  9087. ; Build file <name>.PAS
  9088. ;
  9089. l2d2a:
  9090.         ld      a,'P'           ; Set .PAS
  9091.         ld      hl,'A'+'S'*256
  9092. l2d2f:
  9093.         ld      (l005c+Fdrv+Fname),a
  9094.         ld      (l005c+Fdrv+Fname+1),hl
  9095.         ld      c,0             ; Set no wild card
  9096.         call    l0406           ; Parse file
  9097.         ld      a,(l005c)       ;ok ;FIXME ; Test drive given
  9098.         or      a
  9099.         ret     nz              ; Yeap
  9100.         push    de
  9101.         ;ld     c,_retdsk
  9102.         ;call   _BDOS           ; Return current disk (return L=A=current drive)
  9103.        xor a
  9104.         inc     a
  9105.         ld      (l005c),a       ; Set disk
  9106.         pop     de
  9107.         ret
  9108. ;
  9109. ; Test work file defined - Z set says no
  9110. ;
  9111. l2d4b:
  9112.         ld      a,(l451d+Fdrv)  ; Fetch name
  9113.         or      a
  9114.         ret
  9115. ;
  9116. ; Get file
  9117. ;
  9118. l2d50:
  9119.         call    l2d4b           ; Test work file defined
  9120.         jr      nz,l2d6f        ; Yeap
  9121.         call    l2d7a           ; Test main file defined
  9122.         jr      nz,l2d5f        ; Yeap
  9123.         call    l24c9           ; Get work file
  9124.         jr      l2d6f
  9125. l2d5f:
  9126.         ld      de,l451d
  9127.         ld      hl,l44f9        ; Point to main file
  9128.         ld      bc,l0024
  9129.         ldir
  9130.         ld      a,1
  9131.         ld      (l44f1),a       ; Set file flag
  9132. l2d6f:
  9133.         ld      a,(l44f1)       ; Test file flag
  9134.         or      a
  9135.         ret     z               ; No file
  9136.         call    l2602           ; Save work file
  9137.         jp      l2506
  9138. ;
  9139. ; Test main file defined - Z set says no
  9140. ;
  9141. l2d7a:
  9142.         ld      a,(l44f9+Fdrv)  ; Fetch name
  9143.         or      a
  9144.         ret
  9145. ;
  9146. ; Compare main and work file - Z says same
  9147. ;
  9148. l2d7f:
  9149.         ld      de,l451d        ; Point to work file
  9150.         ld      hl,l44f9        ; Point to main file
  9151.         ld      b,Fdrv+Fname+Fext
  9152. l2d87:
  9153.         ld      a,(de)
  9154.         sub     (hl)            ; Compare
  9155.         ret     nz              ; Not same
  9156.         inc     de
  9157.         inc     hl
  9158.         djnz    l2d87
  9159.         ret
  9160. ;
  9161. ; Init session
  9162. ;
  9163. l2d8f:
  9164.         ld      hl,(l4544)      ; Get start of text
  9165.         ld      (hl),' '        ; Clear it
  9166.         inc     hl
  9167.         ld      (l4546),hl      ; Save pointer
  9168.         xor     a
  9169.         ld      (l447f),a       ; Clear text change flag
  9170.         ld      (l44f1),a       ; Clear file flag
  9171. l2d9f:
  9172.         xor     a
  9173.         ld      (l4542),a       ; Force compile
  9174.         ret
  9175. ;
  9176. ; Read error message file
  9177. ;
  9178. l2da4:
  9179.         ld      hl,(l429e)      ; Get base of message file
  9180.         ld      (l4544),hl      ; Set as start of text
  9181.         ld      de,l217d        ; Point to filename
  9182.         ld      a,'M'
  9183.         ld      hl,'S'+'G'*256
  9184.         call    l2e20           ; Prepare .MSG file
  9185.         ld      (l4541),a       ; Set error message file read
  9186.         call    z,l2e76         ; Get ESCape
  9187.         jr      z,l2dcf
  9188.         ld      hl,l25a0
  9189.         ld      (l259d+1),hl    ; Set vector for file not found
  9190.         ld      hl,l25d4
  9191.         ld      (l257c+1),hl    ; Set vector for file too big
  9192.         ld      de,l005c
  9193.         call    l2518           ; Load text file ;closes automatically
  9194. l2dcf:
  9195.         ld      hl,(l4546)      ; Get end of text
  9196.         ld      (hl),eof
  9197.         inc     hl
  9198.         ld      (l4544),hl      ; Set start of text
  9199.         ret
  9200. ;
  9201. ; Convert string ^DE to hex number in reg HL
  9202. ;
  9203. l2dd9:
  9204.         ld      hl,0            ; Init result
  9205. l2ddc:
  9206.         ld      a,(de)          ; Get character
  9207.         call    doupcase                ; Convert to upper case
  9208.         sub     '0'             ; Strip off offset
  9209.         ret     c               ; Out of range
  9210.         cp      9+1             ; Test decimal
  9211.         jr      c,l2def         ; Yeap
  9212.         sub     'A'-'0'-10      ; Fix for hex
  9213.         cp      10              ; Verify correct range
  9214.         ret     c
  9215.         cp      15+1
  9216.         ret     nc
  9217. l2def:
  9218.         add     hl,hl           ; Old * 16
  9219.         add     hl,hl
  9220.         add     hl,hl
  9221.         add     hl,hl
  9222.         or      l
  9223.         ld      l,a             ; Insert digit
  9224.         inc     de
  9225.         jr      l2ddc
  9226. ;
  9227. ; Tell name of file ^DE
  9228. ;
  9229. l2df8:
  9230.         inc     de
  9231.         ld      a,(de)          ; Get name
  9232.         dec     de
  9233.         or      a               ; Test defined
  9234.         ret     z               ; Nope
  9235.         ld      a,(de)          ; Get drive
  9236.         add     a,'A'-1
  9237.         cp      'A'-1           ; Test default drive
  9238.         call    nz,puttoconsole_a       ; Put to console if not
  9239.         ld      a,':'
  9240.         call    nz,puttoconsole_a       ; Give delimiter
  9241.         ld      b,Fname+Fext    ; Set length
  9242. l2e0c:
  9243.         inc     de
  9244.         ld      a,(de)          ; Get character
  9245.         and     NOMSB           ; Strip off attribute
  9246.         cp      ' '             ; Test blank
  9247.         call    nz,puttoconsole_a       ; Put to console if not
  9248.         ld      a,b
  9249.         cp      Fext+1          ; Test extension follows
  9250.         ld      a,'.'
  9251.         call    z,puttoconsole_a                ; Put delimiter to console if so
  9252.         djnz    l2e0c
  9253.         ret
  9254. ;
  9255. ; Prepare file ^DE with extensin in A,L,H
  9256. ; Z set if file not found
  9257. ;
  9258. l2e20:
  9259.         call    l2d2f           ; Parse file and build extension
  9260.         ld      hl,l005c
  9261.         call    l2e51           ; Open file
  9262.         ret     nz              ; Got it
  9263.         ld      a,(l44f8)       ; Get logged disk
  9264.         cp      (hl)            ; Test same drive
  9265.         ld      (hl),a          ; Set logged one
  9266.         call    nz,l2e51        ; Open file if different drives
  9267.         ret     nz
  9268.         ld      a,'A'-'@'
  9269.         cp      (hl)            ; Test base drive
  9270.         ld      (hl),a          ; Force it
  9271.         call    nz,l2e51        ; Open file if not base
  9272.         ret     nz              ; Got it
  9273.         ld      (hl),0          ; Set default drive
  9274.         ex      de,hl           ; And tell error
  9275. ;
  9276. ; Tell file ^DE not found
  9277. ;
  9278. l2e3e:
  9279.         call    l2df8           ; Tell name of file
  9280.         call    l0200           ; Tell not found
  9281. ;
  9282.         db      ' not found'
  9283.         db      null
  9284.         xor     a
  9285.         ret
  9286. ;
  9287. ; Open standard file - Z set says not found
  9288. ;
  9289. l2e51:
  9290.         push    de
  9291.         push    hl
  9292.         ld      c,_open
  9293.         call    BDOS_with_FCB1          ; Open file
  9294.         pop     hl
  9295.         pop     de
  9296.         inc     a               ; Fix result
  9297.         ret
  9298. ;
  9299. ; Print integer in reg HL fixed sized
  9300. ;
  9301. l2e5c:
  9302.         ld      de,-5           ; Set size
  9303.         jr      l2e64
  9304. ;
  9305. ; Print integer number in reg HL
  9306. ;
  9307. l2e61:
  9308.         ld      de,-1           ; Set no size
  9309. l2e64:
  9310.         push    ix
  9311.         push    iy
  9312.         push    hl
  9313.         push    de
  9314.         call    l149b           ; Set standard device
  9315.         pop     hl
  9316.         call    l1726           ; Write integer
  9317.         pop     iy
  9318.         pop     ix
  9319.         ret
  9320. ;
  9321. ; Get ESCape character
  9322. ;
  9323. l2e76:
  9324.         push    af
  9325.         call    l0200           ; Tell it
  9326. ;
  9327.         db      '. Press <ESC>'
  9328.         db      null
  9329. l2e88:
  9330.         call    readfromkbd             ; Read character
  9331.         jp      l0128           ; &PATCH&: Test special keys
  9332.         nop
  9333. l2e8f:
  9334.         pop     af
  9335.         ret
  9336. ;
  9337. ; %%%%%%%%%%%%%%%%%%%%
  9338. ; %%% EDITOR PART %%%%
  9339. ; %%%%%%%%%%%%%%%%%%%%
  9340. ;
  9341. l2e91:
  9342.         push    hl
  9343.         ld      de,256*lf+cr
  9344.         ld      hl,(l4546)      ; Get end of text
  9345.         ld      (hl),d          ; Close line
  9346.         dec     hl
  9347.         ld      (hl),e
  9348.         ld      (l7b74+_LinLen),de
  9349.         xor     a
  9350.         ld      (l4474),a       ; Clear change flag
  9351.         inc     a
  9352.         ld      (l4475),a       ; Init row
  9353.         ld      hl,l43de
  9354.         ld      (l7b72),hl      ; Init pointer to all delimiters
  9355.         ld      iy,l446c
  9356.         call    l023e           ; Clear screen
  9357.         pop     de              ; Get offset
  9358.         inc     de              ; Fix it
  9359.         ld      hl,(l4544)      ; Get start of text
  9360.         add     hl,de           ; Add to offset
  9361.         call    l33a9 ;status line?
  9362. l2ebd:
  9363.         ld      a,(l4482)       ; Get control character count
  9364.         dec     a
  9365.         jr      z,l2ed5         ; Got one
  9366.         ld      hl,256*0+0
  9367.         call    l02a2           ; Set cursor to control position
  9368.         ld      a,(l4482)       ; Get control character count
  9369.         add     a,a             ; Double it
  9370.         ld      b,a             ; For count
  9371.         ld      a,' ' ;TODO speedup spaces
  9372. l2ed0:
  9373.         call    puttoconsole_a          ; Blank control characters
  9374.         djnz    l2ed0
  9375. l2ed5:
  9376.         call    l3b96 ;set edit cursor?
  9377.         call    l2ff7           ; Give status
  9378.         call    l2f3a           ; Get character
  9379.         jr      nc,l2f0e        ; No control
  9380.         jr      z,l2ebd
  9381.         ld      hl,l2ebd
  9382.         ld      a,d
  9383.         cp      (HIGH MMSB)-1   ; Test special address
  9384.         jr      c,l2ef4         ; Nope
  9385.         ld      (l447f),a       ; Set text changed
  9386.         and     NOMSB
  9387.         ld      d,a
  9388.         xor     a
  9389.         ld      (l4542),a       ; Force compile
  9390. l2ef4:
  9391.         push    hl              ; Set return address
  9392.         push    de              ; Save control address
  9393.         ld      hl,l4456+1
  9394.         ld      de,l445a+1
  9395.         ld      bc,l0008
  9396.         lddr                    ; Save a bit
  9397.         ret
  9398. ;
  9399. ; Control: CONTROL PREFIX
  9400. ;
  9401. l2f02::
  9402.         call    l2f8a           ; Get character
  9403.         ld      (iy+22),3
  9404.         call    l4271           ; Get character
  9405.         jr      l2f16
  9406. l2f0e:
  9407.         ld      (l447f),a       ; Re/Set text changed
  9408.         ld      hl,l4542
  9409.         ld      (hl),0          ; Force compile
  9410. l2f16:
  9411.         ld      hl,(l4452)      ; Get current edit pointer
  9412.         ld      de,l7b74+_LinLen-2
  9413.         call    cmp_hl_de               ; Compare HL:DE
  9414.         jr      nc,l2ebd        ; Line too long
  9415.         bit     0,(iy+6)        ; Test insert
  9416.         push    af
  9417.         call    z,l41eb         ; Yeap, so make room
  9418.         pop     af
  9419.         ld      (hl),a          ; Store character
  9420.         inc     hl              ; Bump buffer
  9421.         push    hl
  9422.         call    l4197
  9423.         pop     hl
  9424.         ld      (l4452),hl      ; Set current edit pointer
  9425.         call    l3fe7 ;set column?
  9426.         jp      l2ebd
  9427. ;
  9428. ; Get character
  9429. ; C set indicates control
  9430. ;
  9431. l2f3a:
  9432.         call    l4271           ; Get character
  9433.         cp      '~'+1           ; Test printable range
  9434.         jr      nc,l2f44        ; Nope
  9435.         cp      ' '             ; Test once again
  9436.         ret     nc
  9437. l2f44:
  9438.         ld      hl,l4482        ; Point to control character count
  9439.         ld      (hl),1          ; Init count
  9440.         inc     hl
  9441.         ld      (hl),a          ; Save control
  9442. l2f4b:
  9443.         ;push   hl
  9444.         ;ld     hl,l4482        ; Point to control character count
  9445.         ;ld     de,l42a1
  9446.         ;ld     b,11111111b
  9447.         ;call   l2fc1           ; Find control
  9448.         ;pop    hl
  9449.         ;or     a               ; Test found
  9450.         ;jr     nz,l2f6b        ; Yeap
  9451.         push    hl
  9452.         ld      hl,l4482        ; Point to control character count
  9453.         ld      de,l4369
  9454.         ;ld     b,00011111b
  9455.         ld      b,11111111b
  9456.         call    l2fc1           ; Find control
  9457.         pop     hl
  9458.         or      a               ; Test found
  9459.         scf
  9460.         ret     z               ; Nope
  9461. l2f6b:
  9462.         dec     a               ; Test all found
  9463.         jr      z,l2f78         ; Nope
  9464.         ld      hl,l43f4
  9465.         add     hl,bc           ; Go into table
  9466.         add     hl,bc
  9467.         ld      e,(hl)          ; Fetch address
  9468.         inc     hl
  9469.         ld      d,(hl)
  9470.         scf                     ; Set result
  9471.         ret
  9472. l2f78:
  9473.         call    l2f8a           ; Get character
  9474.         push    af
  9475.         call    l4271           ; Get character
  9476.         inc     (iy+22)
  9477.         inc     hl
  9478.         ld      (hl),a
  9479.         pop     af
  9480.         call    z,l2f8a         ; Get character
  9481.         jr      l2f4b
  9482. ;
  9483. ; Get character
  9484. ;
  9485. l2f8a:
  9486.         call    l4232           ; Poll character from input
  9487.         call    l428f           ; Test look ahead buffer empty
  9488.         ret     nz              ; Nope
  9489.         push    hl
  9490.         ld      hl,256*0+0
  9491.         call    l02a2           ; Position cursor
  9492.         ld      hl,l4482        ; Point to control character count
  9493.         ld      a,(hl)          ; Get length
  9494. l2f9c:
  9495.         push    af
  9496.         inc     hl
  9497.         ld      a,(hl)          ; Get character
  9498.         call    l2fa8           ; Dispaly as control
  9499.         pop     af
  9500.         dec     a
  9501.         jr      nz,l2f9c
  9502.         pop     hl
  9503.         ret
  9504. ;
  9505. ; Display character in Accu
  9506. ;
  9507. l2fa8:
  9508.         push    af
  9509.         call    l3cec           ; Make normal video
  9510.         pop     af
  9511.         cp      ' '             ; Test control
  9512.         jp      nc,puttoconsole_a       ; Put to console if not
  9513.         push    af
  9514.         push    af
  9515.         ld      a,'^'
  9516.         call    puttoconsole_a          ; Indicate control
  9517.         pop     af
  9518.         add     a,'@'
  9519.         call    puttoconsole_a          ; Put to console as ASCII
  9520.         pop     af
  9521.         ret
  9522. ;
  9523. ; ^HL points to key sequence searched for in list ^DE with mask in reg B
  9524. ; Accu= 0 says not found
  9525. ; Accu= 1 says part found
  9526. ; Accu=-1 says found
  9527. ;
  9528. l2fc1:
  9529.         ld      c,-1            ; Init index
  9530.         push    bc
  9531.         push    hl
  9532. l2fc5:
  9533.         pop     hl
  9534.         pop     bc
  9535.         ld      a,(de)          ; Get length from list
  9536.         inc     de
  9537.         or      a               ; Test end
  9538.         ret     z               ; Yeap
  9539.         inc     c               ; Advance index
  9540.         push    bc
  9541.         push    hl
  9542.         ld      c,(hl)          ; Get length from input
  9543.         sub     c               ; Get difference
  9544.         inc     hl
  9545.         jr      nc,l2fd7        ; In range
  9546.         add     a,c             ; Else fix it
  9547.         ld      c,a
  9548.         jr      l2ff0           ; Go adjust
  9549. l2fd7:
  9550.         push    af
  9551. l2fd8:
  9552.         ld      a,(de)          ; Get from list
  9553.         sub     (hl)            ; Compare
  9554.         and     b               ; Set mask
  9555.         jr      nz,l2fed        ; No match
  9556.         inc     de
  9557.         inc     hl
  9558.         dec     c
  9559.         jr      nz,l2fd8
  9560.         pop     af
  9561.         pop     hl
  9562.         pop     bc
  9563.         ld      b,0
  9564.         ld      a,-1
  9565.         ret     z               ; Got exact length
  9566.         ld      a,1             ; Fix for partial success
  9567.         ret
  9568. l2fed:
  9569.         pop     af
  9570.         add     a,c
  9571.         ld      c,a
  9572. l2ff0:
  9573.         ld      b,0
  9574.         ex      de,hl
  9575.         add     hl,bc
  9576.         ex      de,hl
  9577.         jr      l2fc5
  9578. ;
  9579. ; Give editor status
  9580. ;
  9581. l2ff7:
  9582.         call    l4232           ; Poll character from input
  9583.         call    l428f           ; Test look ahead buffer empty
  9584.         ret     nz              ; Nope
  9585.         ld      hl,l4474
  9586.         ld      a,(hl)          ; Test status changed
  9587.         or      a
  9588.         jr      nz,l3078        ; No change
  9589.         ld      (hl),-1         ; Reset it
  9590.         ld      hl,256*0+0
  9591.         ld      (l4476),hl
  9592.         xor     a
  9593.         ld      (l4478),a
  9594.         call    l02a2           ; Position cursor
  9595.         call    l3c12           ; Clear line
  9596.         call    l3cdf           ; Set low video
  9597.         ld      a,(l0168)       ; Get screen columns
  9598.         cp      MINWID          ; Test room for filename
  9599.         jr      c,l302a         ; Nope
  9600.         ld      hl,256*42+0
  9601.         call    l02a2           ; Position cursor
  9602.         call    l3135           ; Type work file
  9603. l302a:
  9604.         ld      hl,256*6+0
  9605.         call    l420e           ; Position cursor and tell line
  9606.         db      'Line '
  9607.         db      null
  9608.         ld      hl,256*16+0
  9609.         call    l420e           ; Position cursor and tell column
  9610.         db      'Col '
  9611.         db      null
  9612.         ld      hl,256*24+0
  9613.         ld      a,(l4472)       ; Get insert mode
  9614.         or      a
  9615.         jr      nz,l305a        ; Overwrite
  9616.         call    l420e           ; Position cursor and tell insert
  9617.         db      'Insert    '
  9618.         db      null
  9619.         jr      l3068
  9620. l305a:
  9621.         call    l420e           ; Position cursor and tell overwrite
  9622.         db      'Overwrite '
  9623.         db      null
  9624. l3068:
  9625.         ld      a,(l4479)       ; Get tabulate state
  9626.         or      a
  9627.         jr      nz,l3078
  9628.         call    l4211
  9629.         db      'Indent'
  9630.         db      null
  9631. l3078:
  9632.         ld      a,(l446c) ;xscroll???
  9633.         add     a,(iy+4)        ; Add column
  9634.         inc     a
  9635.         ld      hl,(l4478)
  9636.         cp      l
  9637.         jr      z,l309b
  9638.         ld      (l4478),a
  9639.         push    af
  9640.         ld      hl,256*20+0
  9641.         call    l02a2           ; Position cursor
  9642.         call    l3cdf           ; Set low video
  9643.         pop     af
  9644.         ld      l,a
  9645.         ld      h,0
  9646.         ld      a,3             ; Set number of digits
  9647.         call    l30ec           ; Give count
  9648. l309b:
  9649.         ld      de,(l4476)
  9650.         ld      hl,(l4450)      ; Get current memory pointer
  9651.         call    cmp_hl_de               ; Compare HL:DE
  9652.         jp      z,l37a4         ; Same, set edit cursor
  9653.         call    l37a4           ; Set edit cursor
  9654.         ld      de,(l4544)      ; Get start of text
  9655.         ld      hl,(l4450)      ; Get current memory pointer
  9656.         or      a
  9657.         sbc     hl,de           ; Get relative position
  9658.         ld      c,l
  9659.         ld      b,h
  9660.         ex      de,hl
  9661.         ld      de,1
  9662.         ld      a,c
  9663.         or      b               ; Test any
  9664.         jr      z,l30d3         ; Nope
  9665. l30bf:
  9666.         ld      a,lf
  9667.         inc     de
  9668.         cpir                    ; Find new line
  9669.         jp      po,l30d3        ; Got it
  9670.         dec     e
  9671.         inc     e
  9672.         call    z,l4232         ; Poll character from input
  9673.         call    l428f           ; Test look ahead buffer empty
  9674.         jr      nz,l30e9        ; Nope
  9675.         jr      l30bf
  9676. l30d3:
  9677.         ld      hl,256*11+0
  9678.         push    de
  9679.         call    l02a2           ; Position cursor
  9680.         call    l3cdf           ; Set low video
  9681.         pop     hl
  9682.         ld      a,5             ; Set number of digits
  9683.         call    l30ec           ; Give count
  9684.         ld      hl,(l4450)      ; Get current memory pointer
  9685.         ld      (l4476),hl
  9686. l30e9:
  9687.         jp      l37a4           ; Set edit cursor
  9688. ;
  9689. ; Print fixed format integer
  9690. ; ENTRY Reg HL holds number to be printed
  9691. ;       Accu holds decimal places
  9692. ;
  9693. l30ec:
  9694.         push    af
  9695.         ld      b,0             ; Clear count
  9696.         call    l30fe           ; Print number
  9697.         pop     af
  9698.         add     a,b             ; Test all digits typed
  9699.         ret     z               ; Yeap
  9700.         ld      b,a
  9701.         ld      a,' '
  9702. l30f8:
  9703.         call    puttoconsole_a          ; Fill remainder with blanks
  9704.         djnz    l30f8
  9705.         ret
  9706. ;
  9707. ; Print decimal number
  9708. ; ENTRY Reg HL holds number
  9709. ;       Reg B  holds places
  9710. ;
  9711. l30fe:
  9712.         ld      a,h
  9713.         or      l               ; Test zero output
  9714.         ld      a,'0'
  9715.         jr      z,l3131         ; Yeap, print it
  9716.         ld      de,10000
  9717.         call    l311f           ; Get ten thousands
  9718.         ld      de,1000
  9719.         call    l311f           ; Get thousands
  9720.         ld      de,100
  9721.         call    l311f           ; Get hundreds
  9722.         ld      de,10
  9723.         call    l311f           ; Get tens
  9724.         ld      de,1            ; Finally units
  9725. ;
  9726. ; Print modulo
  9727. ; ENTRY Reg HL holds number
  9728. ;       Reg DE holds divisor
  9729. ;       Reg B  holds places
  9730. ; EXIT  Reg HL fixed
  9731. ;       Reg B  decremented if digit is printed
  9732. ;
  9733. l311f:
  9734.         xor     a               ; Clear digit
  9735. l3120:
  9736.         sbc     hl,de           ; Divide
  9737.         jr      c,l3127
  9738.         inc     a               ; Bump digit
  9739.         jr      l3120
  9740. l3127:
  9741.         add     hl,de           ; Make remainder positive
  9742.         add     a,'0'           ; Make ASCII
  9743.         cp      '0'             ; Test zero
  9744.         jr      nz,l3131
  9745.         inc     b               ; Test leading zero
  9746.         dec     b
  9747.         ret     z               ; Suppress it
  9748. l3131:
  9749.         dec     b               ; Fix count
  9750.         jp      puttoconsole_a          ; Put to console
  9751. ;
  9752. ; Type work file
  9753. ;
  9754. l3135:
  9755.         ld      de,l451d
  9756.         jp      l2df8           ; Tell name of file
  9757. ;
  9758. ; Get string for search and file function
  9759. ; ENTRY Reg DE points to line buffer
  9760. ;       Byte 0 holds max characters
  9761. ;       Byte 1 holds resulting length
  9762. ;
  9763. l313b:
  9764.         call    l0200           ; Indicate input
  9765. ;
  9766.         db      ': '
  9767.         db      null
  9768.         ex      de,hl
  9769.         push    hl
  9770.         pop     ix              ; Copy buffer
  9771.         inc     hl
  9772.         ld      d,(hl)
  9773.         ld      (hl),0
  9774.         inc     hl
  9775. l314a:
  9776.         res     _LB,(iy+_Video) ; Disable video
  9777.         push    de
  9778.         push    hl
  9779.         call    l2f3a           ; Get character
  9780.         pop     hl
  9781.         pop     de
  9782.         set     _LB,(iy+_Video) ; Allow video
  9783.         jr      nc,l31b9        ; No control
  9784.         jr      nz,l3165
  9785.         ld      a,(l4483)       ; Get character
  9786.         call    l3ef6           ; Test function cancelled
  9787.         jr      l314a
  9788. l3165:
  9789.         ld      a,c
  9790.         cp      0
  9791.         jr      nz,l316d
  9792.         ld      (hl),1ah
  9793.         ret
  9794. l316d:
  9795.         cp      3
  9796.         jr      nz,l317c
  9797.         ld      a,(ix+1)
  9798.         cp      d
  9799.         jr      nc,l314a
  9800.         inc     (ix+1)
  9801.         jr      l31c6
  9802. l317c:
  9803.         cp      5
  9804.         jr      nz,l3190
  9805. l3180:
  9806.         ld      a,(ix+1)
  9807.         cp      d
  9808.         jr      z,l314a
  9809.         ld      a,(hl)          ; Get character
  9810.         call    l2fa8           ; Display as control
  9811.         inc     hl
  9812.         inc     (ix+1)
  9813.         jr      l3180
  9814. l3190:
  9815.         cp      4
  9816.         jr      nz,l319b
  9817. l3194:
  9818.         call    l31d7
  9819.         jr      nz,l3194
  9820.         jr      l314a
  9821. l319b:
  9822.         cp      '-'
  9823.         jr      nz,l31a4
  9824.         call    l4271           ; Get character
  9825.         jr      l31b9
  9826. l31a4:
  9827.         cp      1bh
  9828.         jr      z,l31b4
  9829.         cp      1ch
  9830.         jr      z,l31b4
  9831.         cp      1
  9832.         jr      z,l31b4
  9833.         cp      2
  9834.         jr      nz,l314a
  9835. l31b4:
  9836.         call    l31d7
  9837. l31b7:
  9838.         jr      l314a
  9839. l31b9:
  9840.         ld      e,a
  9841.         ld      a,(ix+1)
  9842.         cp      (ix+0)
  9843.         jr      nc,l314a
  9844.         inc     (ix+1)
  9845.         ld      (hl),e
  9846. l31c6:
  9847.         ld      a,(hl)          ; Get character
  9848.         inc     hl
  9849.         call    l2fa8           ; Display as control
  9850.         ld      a,(ix+1)
  9851.         cp      d
  9852.         jr      c,l31b7
  9853.         ld      d,(ix+1)
  9854.         jp      l31b7
  9855. l31d7:
  9856.         ld      a,(ix+1)
  9857.         or      a
  9858.         ret     z
  9859.         dec     (ix+1)
  9860.         dec     hl
  9861.         ld      a,(hl)
  9862.         cp      ' '
  9863.         call    c,l31e6
  9864. l31e6:
  9865.         call    l4211
  9866.         db      bs+MSB,' '+MSB,bs+MSB
  9867.         db      null
  9868.         ld      a,0ffh
  9869.         or      a
  9870.         ret
  9871. ;
  9872. ; Control: FIND STRING
  9873. ;
  9874. l31f1:
  9875.         xor     a
  9876.         ld      (l447e),a       ; Set find flag
  9877.         call    l31fd           ; Get string searched for
  9878.         call    l3220           ; Get options
  9879.         jr      l3252           ; Enter process
  9880. ;
  9881. ; Get string searched for
  9882. ;
  9883. l31fd:
  9884.         call    l3e04           ; Tell what we want
  9885.         db      'Find'
  9886.         db      null
  9887.         ld      de,l4490        ; Point to buffer
  9888. l3208:
  9889.         jp      l313b           ; Get search string
  9890. ;
  9891. ; Get string to be replaced
  9892. ;
  9893. l320b:
  9894.         call    l3e07           ; Tell what we want
  9895.         db      'Replace with'
  9896.         db      null
  9897.         ld      de,l44b1        ; Point to buffer
  9898.         jr      l3208           ; Get replace string
  9899. ;
  9900. ; Get options
  9901. ;
  9902. l3220:
  9903.         call    l3e07           ; Tell what we want
  9904.         db      'Options'
  9905.         db      null
  9906.         ld      de,l44d2        ; Get buffer
  9907.         call    l313b           ; Get search string
  9908.         ld      a,(l0168)       ; Get screen columns
  9909.         ld      h,a
  9910.         dec     h               ; Fix column
  9911.         ld      l,0             ; Set row
  9912.         jp      l02a2           ; Position cursor
  9913. ;
  9914. ; Control: FIND AND REPLACE STRING
  9915. ;
  9916. l323b:
  9917.         ld      a,-1
  9918.         ld      (l447e),a       ; Set replace flag
  9919.         call    l31fd           ; Get string searched for
  9920.         call    l320b           ; Get replace string
  9921.         call    l3220           ; Get options
  9922.         jr      l3252           ; Enter process
  9923. ;
  9924. ; Control: REPEAT LAST SEARCH
  9925. ;
  9926. l324b:
  9927.         call    l2f8a           ; Get character
  9928.         ld      (iy+22),3       ; Init count
  9929. l3252:
  9930.         call    l3e40           ; Sample character
  9931.         call    l3e23           ; Find last non blank
  9932.         inc     hl
  9933.         ld      de,(l4452)      ; Get current edit pointer
  9934.         call    l4191           ; Find min
  9935.         ld      de,l7b74
  9936.         or      a
  9937.         sbc     hl,de           ; Subtract base
  9938.         ld      de,(l4450)      ; Get current memory pointer
  9939.         add     hl,de           ; Add for real address
  9940.         ld      (l4488),hl      ; Set end
  9941.         ld      de,0            ; Clear counter
  9942.         ld      hl,l44d2+1      ; Init buffer
  9943.         ld      b,(hl)          ; Fetch length
  9944.         ld      (iy+17),0       ; Clear flag
  9945.         inc     b               ; Test any in buffer
  9946.         dec     b
  9947.         jr      z,l32c0         ; Nope
  9948. l327d:
  9949.         inc     hl
  9950.         ld      a,(hl)          ; Get character
  9951.         cp      '0'             ; Test possible count
  9952.         jr      c,l3293         ; Nope
  9953.         cp      '9'+1
  9954.         jr      nc,l3293
  9955.         call    l3426
  9956.         sub     '0'
  9957.         add     a,e             ; Add digit to count
  9958.         ld      e,a
  9959.         jr      nc,l32be
  9960.         inc     d               ; Remember carry
  9961.         jr      l32be
  9962. l3293:
  9963.         call    doupcase                ; Convert to upper case
  9964.         cp      'W'             ; Test whole word search
  9965.         jr      nz,l329e
  9966.         set     _W,(iy+17)
  9967. l329e:
  9968.         cp      'U'             ; Test ignore case
  9969.         jr      nz,l32a6
  9970.         set     _U,(iy+17)
  9971. l32a6:
  9972.         cp      'N'             ; Test no request
  9973.         jr      nz,l32ae
  9974.         set     _N,(iy+17)
  9975. l32ae:
  9976.         cp      'G'             ; Test global
  9977.         jr      nz,l32b6
  9978.         set     _G,(iy+17)
  9979. l32b6:
  9980.         cp      'B'             ; Test backwards
  9981.         jr      nz,l32be
  9982.         set     _B,(iy+17)
  9983. l32be:
  9984.         djnz    l327d
  9985. l32c0:
  9986.         ld      a,e             ; Test loop count
  9987.         or      d
  9988.         jr      nz,l32c7        ; Yeap
  9989.         ld      de,1            ; Set default
  9990. l32c7:
  9991.         ld      (l448a),de      ; Save loop count
  9992.         ld      hl,(l4544)      ; Get start of text
  9993.         ld      a,(l447d)       ; Get option flags
  9994.         bit     _B,a            ; Test backwards
  9995.         jr      z,l32d8         ; Nope
  9996.         ld      hl,(l4546)      ; Get end of text
  9997. l32d8:
  9998.         bit     _G,a            ; Test global search
  9999.         jr      nz,l32df        ; Yeap
  10000.         ld      hl,(l4488)      ; Get end of search pointer
  10001. l32df:
  10002.         ld      (l4488),hl      ; Set end of search pointer
  10003.         bit     _B,(iy+17)      ; Test backwards
  10004.         jr      nz,l32f5        ; Yeap
  10005.         ld      de,(l4546)      ; Get end of text
  10006.         dec     de
  10007.         call    cmp_hl_de               ; Compare HL:DE
  10008.         jp      nc,l3380
  10009.         jr      l32fb
  10010. l32f5:
  10011.         call    l3bee           ; Fix to start of line
  10012.         jp      c,l3380
  10013. l32fb:
  10014.         ld      de,l4492
  10015.         ld      a,(l4491)
  10016.         ld      b,a
  10017.         bit     _B,(iy+17)      ; Test backwards
  10018.         jr      z,l330e         ; Nope
  10019.         dec     a
  10020.         add     a,e
  10021.         ld      e,a
  10022.         jr      nc,l330e
  10023.         inc     d
  10024. l330e:
  10025.         bit     _W,(iy+17)      ; Test whole word search
  10026.         jr      z,l3323         ; Nope
  10027.         push    de
  10028.         push    hl
  10029.         call    l33fb
  10030.         ld      a,(hl)
  10031.         pop     hl
  10032.         pop     de
  10033.         jr      c,l3323
  10034.         call    l33e4
  10035.         jr      c,l3377
  10036. l3323:
  10037.         dec     b
  10038.         inc     b
  10039.         jr      z,l332e
  10040. l3327:
  10041.         call    l340f
  10042.         jr      nz,l3377
  10043.         djnz    l3364
  10044. l332e:
  10045.         bit     _W,(iy+17)      ; Test whole word search
  10046.         jr      z,l3341         ; Nope
  10047.         push    hl
  10048.         call    l3406
  10049.         ld      a,(hl)
  10050.         pop     hl
  10051.         jr      c,l3341
  10052.         call    l33e4
  10053.         jr      c,l3377
  10054. l3341:
  10055.         bit     _B,(iy+17)      ; Test backwards
  10056.         call    z,l3bdd         ; Nope
  10057.         ld      a,(l447e)       ; Get find flag
  10058.         or      a
  10059.         call    nz,l3430        ; Replace selected
  10060.         bit     _G,(iy+17)      ; Test global search
  10061. l3353:
  10062.         jr      nz,l32df
  10063.         ld      bc,(l448a)      ; Get loop count
  10064.         dec     bc              ; Decrement
  10065.         ld      (l448a),bc
  10066.         ld      a,b
  10067.         or      c
  10068.         jr      nz,l3353
  10069.         jr      l33a9
  10070. l3364:
  10071.         push    de
  10072.         call    l3406
  10073.         pop     de
  10074.         jr      c,l3380
  10075.         bit     _B,(iy+17)      ; Test backwards
  10076.         jr      z,l3374         ; Nope
  10077.         dec     de
  10078.         jr      l3327
  10079. l3374:
  10080.         inc     de
  10081.         jr      l3327
  10082. l3377:
  10083.         ld      hl,(l4488)      ; Get end of search pointer
  10084.         call    l3406
  10085.         jp      nc,l32df
  10086. l3380:
  10087.         call    l33d6
  10088.         call    l33a9
  10089.         bit     _G,(iy+17)      ; Test global search
  10090.         ret     nz
  10091.         call    l3e04
  10092.         db      'Search string not found'
  10093.         db      null
  10094.         jp      l3f12
  10095. ;status line???
  10096. l33a9:
  10097.         call    l33af
  10098.         jp      l3d2c           ; Restore line
  10099. l33af:
  10100.         ld      de,(l4546)      ; Get end of text
  10101.         dec     de
  10102.         call    cmp_hl_de               ; Compare HL:DE
  10103.         jr      c,l33ba ;hl<de
  10104.         ex      de,hl
  10105. l33ba:
  10106.         push    hl
  10107.         push    hl
  10108.         call    l3bf5           ; Get previous EOL
  10109.         ld      (l4450),hl      ; Set current memory pointer
  10110.         or      a
  10111.         ex      de,hl
  10112.         pop     hl
  10113.         sbc     hl,de
  10114.         ld      de,l7b74
  10115.         add     hl,de
  10116.         ld      (l4452),hl      ; Set current edit pointer
  10117.         call    l3fe7 ;set column?
  10118.         call    l401f
  10119.         pop     hl
  10120.         ret
  10121. l33d6:
  10122.         ld      de,(l4544)      ; Get start of text
  10123.         call    l4191           ; Find min
  10124.         ld      hl,(l4546)      ; Get end of text
  10125.         dec     hl
  10126.         jp      l4191           ; Find min
  10127. l33e4:
  10128.         cp      '0'
  10129.         jr      c,l33f9
  10130.         cp      ':'
  10131.         ret     c
  10132.         cp      'A'
  10133.         jr      c,l33f9
  10134.         cp      5bh
  10135.         ret     c
  10136.         cp      61h
  10137.         jr      c,l33f9
  10138.         cp      7bh
  10139.         ret     c
  10140. l33f9:
  10141.         or      a
  10142.         ret
  10143. l33fb:
  10144.         bit     _B,(iy+17)      ; Test backwards
  10145.         jr      z,l340c         ; Nope
  10146. l3401:
  10147.         call    l3bdd
  10148.         ccf
  10149.         ret
  10150. l3406:
  10151.         bit     _B,(iy+17)      ; Test backwards
  10152.         jr      z,l3401         ; Nope
  10153. l340c:
  10154.         jp      l3bee           ; Fix to start of line
  10155. l340f:
  10156.         ld      a,(de)
  10157.         cp      1
  10158.         ret     z
  10159.         cp      (hl)
  10160.         ret     z
  10161.         bit     _U,(iy+17)      ; Test ignore case
  10162.         jr      z,l3424         ; Yeap
  10163.         call    l33e4
  10164.         jr      nc,l3424
  10165.         xor     (hl)
  10166.         and     0dfh
  10167.         ret
  10168. l3424:
  10169.         cp      (hl)
  10170.         ret
  10171. l3426:
  10172.         push    hl
  10173.         ld      l,e
  10174.         ld      h,d
  10175.         add     hl,hl
  10176.         add     hl,hl
  10177.         add     hl,de
  10178.         add     hl,hl
  10179.         ex      de,hl
  10180.         pop     hl
  10181.         ret
  10182. l3430:
  10183.         push    hl
  10184.         call    l428f           ; Test look ahead buffer empty
  10185.         jr      z,l343c         ; Yeap
  10186.         bit     _N,(iy+17)      ; Test no request
  10187.         jr      nz,l349d        ; Yeap
  10188. l343c:
  10189.         call    l33a9
  10190.         call    l3b96
  10191.         bit     _N,(iy+17)      ; Test no request
  10192.         jr      nz,l349d        ; Yeap
  10193.         call    l3e07
  10194.         db      'Replace (','Y'+MSB,'/','N'+MSB,'): '
  10195.         db      null
  10196. l345b:
  10197.         ld      l,(iy+5)        ; Get row
  10198.         ld      h,(iy+4)        ; Get column
  10199.         call    l02a2           ; Position cursor
  10200.         ld      bc,l07d0
  10201. l3467:
  10202.         call    l4232           ; Poll character from input
  10203.         call    l428f           ; Test look ahead buffer empty
  10204.         jr      nz,l348c        ; Nope
  10205.         dec     bc
  10206.         ld      a,c
  10207.         or      b
  10208.         jr      nz,l3467
  10209.         ld      hl,256*15+0
  10210.         call    l02a2           ; Position cursor
  10211.         ld      bc,l07d0
  10212. l347d:
  10213.         call    l4232           ; Poll character from input
  10214.         call    l428f           ; Test look ahead buffer empty
  10215.         jr      nz,l348c        ; Nope
  10216.         dec     bc
  10217.         ld      a,c
  10218.         or      b
  10219.         jr      nz,l347d
  10220.         jr      l345b
  10221. l348c:
  10222.         call    l4271           ; Get character
  10223.         call    l3ef6           ; Test function cancelled
  10224.         call    doupcase                ; Convert to upper case
  10225.         cp      'Y'
  10226.         jr      z,l349d
  10227.         cp      19h
  10228.         jr      nz,l34eb
  10229. l349d:
  10230.         set     0,(iy+19)
  10231.         xor     a
  10232.         ld      (l4542),a       ; Force compile
  10233.         ld      a,(l44b2)
  10234.         ld      c,a
  10235.         ld      b,0
  10236.         pop     hl
  10237.         push    hl
  10238.         push    bc
  10239.         ld      a,(l4491)
  10240.         sub     c
  10241.         ld      c,a
  10242.         push    af
  10243.         jr      nc,l34b7
  10244.         dec     b
  10245. l34b7:
  10246.         bit     _B,(iy+17)      ; Test backwards
  10247.         jr      nz,l34c0        ; Yeap
  10248.         ld      hl,(l4488)      ; Get end of search pointer
  10249. l34c0:
  10250.         pop     af
  10251.         push    hl
  10252.         call    nz,l3f18
  10253.         pop     de
  10254.         pop     bc
  10255.         ld      a,b
  10256.         or      c
  10257.         jr      z,l34d0
  10258.         ld      hl,l44b3
  10259.         ldir
  10260. l34d0:
  10261.         call    l428f           ; Test look ahead buffer empty
  10262.         push    af
  10263.         call    nz,l4147        ; Nope, so reset row
  10264.         pop     af
  10265.         jr      nz,l34e2        ; Eas not empty
  10266.         push    de
  10267.         call    l3d2c           ; Restore line
  10268.         call    l4139
  10269.         pop     de
  10270. l34e2:
  10271.         bit     _B,(iy+17)      ; Test backwards
  10272.         jr      nz,l34eb        ; Yeap
  10273.         pop     hl
  10274.         ex      de,hl
  10275.         ret
  10276. l34eb:
  10277.         pop     hl
  10278.         ret
  10279. ;
  10280. ; Control: WRITE BLOCK TO FILE
  10281. ;
  10282. l34ed:
  10283.         bit     0,(iy+20)       ; Test block set
  10284.         ret     nz              ; Nope
  10285.         call    l3e40           ; Sample character
  10286.         call    l3d2c           ; Restore line
  10287.         ld      hl,(l4460)      ; Get block start pointer
  10288.         ld      de,(l4462)      ; Get block end pointer
  10289.         call    cmp_hl_de               ; Compare HL:DE
  10290.         ret     nc              ; Start >= end
  10291.         call    l363c
  10292.         call    l3d2c           ; Restore line
  10293. l3509:
  10294.         call    l3e04           ; Tell what we want
  10295.         db      'Write block to file'
  10296.         db      null
  10297.         call    l3566           ; Get name of file
  10298.         ret     z
  10299.         call    l2d2a           ; Prepare .PAS file
  10300.         ld      c,_open
  10301.         call    BDOS_with_FCB1          ; Open file ;WHERE IS CLOSE???
  10302.         inc     a               ; Test file already exist
  10303.         jr      z,l3551         ; Nope
  10304.         call    l3e07
  10305.         db      'Overwrite old '
  10306.         db      null
  10307.         ld      de,l005c
  10308.         call    l2df8           ; Tell name of file
  10309.         call    l2d01           ; Ask for YES or NO
  10310.         jr      z,l3509         ; No
  10311.         ld      c,_delete
  10312.         call    BDOS_with_FCB1          ; Delete file
  10313. l3551:
  10314.         ld      hl,(l4462)      ; Get block end pointer
  10315.         ld      a,(hl)          ; Save character
  10316.         push    af
  10317.         push    hl
  10318.         ld      (hl),eof        ; Set end of file
  10319.         call    l3e0d           ; Set cursor
  10320.         ld      hl,(l4460)      ; Get block start pointer
  10321.         call    l2692           ; Save block to file
  10322.          ld     c,_close
  10323.          call   BDOS_with_FCB1
  10324.         pop     hl
  10325.         pop     af
  10326.         ld      (hl),a          ; Restore character
  10327.         ret
  10328. ;
  10329. ; Get name of file
  10330. ;
  10331. l3566:
  10332.         ld      de,l44df
  10333.         call    l313b           ; Get filename
  10334.         ld      de,l44df+2
  10335.         ld      a,(de)
  10336.         cp      eof             ; Test empty name
  10337.         ret
  10338. ;
  10339. ; Control: READ BLOCK FROM FILE
  10340. ;
  10341. l3573:
  10342.         call    l3e04           ; Tell what we want
  10343.         db      'Read block from file'
  10344.         db      null
  10345.         call    l3566           ; Get name of file
  10346.         ret     z
  10347.         call    l2d2a           ; Prepare .PAS file
  10348.         ld      c,_open
  10349.         call    BDOS_with_FCB1          ; Open file ;WHERE IS CLOSE???
  10350.         inc     a               ; Test success
  10351.         jr      nz,l35a8        ; Yeap
  10352.         call    l3e0d           ; Set cursor
  10353.         ld      de,l005c
  10354.         call    l2e3e           ; Tell not found
  10355.         call    l3f12
  10356.         jr      l3573
  10357. l35a8:
  10358.         res     0,(iy+20)       ; Mark block
  10359.         call    l363c
  10360.         ld      hl,(l4546)      ; Get end of text
  10361.         ld      de,(l4548)      ; Get top of available memory
  10362.         ld      bc,l00fe
  10363.         add     hl,bc           ; Build top
  10364.         or      a
  10365.         sbc     hl,de           ; Calculate size
  10366.         push    hl
  10367.         ld      b,h
  10368.         ld      c,l
  10369.         ld      hl,(l448c)
  10370.         scf
  10371.         call    l3f18
  10372.          ld     c,_close
  10373.          call   BDOS_with_FCB1
  10374.         pop     de
  10375.         ld      hl,l35dd        ; Set return address
  10376.         push    hl
  10377.         ld      hl,(l448c)
  10378.         push    hl
  10379.         xor     a
  10380.         sbc     hl,de
  10381.         push    hl
  10382.         ld      hl,l35f1
  10383.         ld      (l257c+1),hl    ; Redirect load error
  10384.         jp      l2560           ; Load the block
  10385. ;
  10386. ; Process end of read
  10387. ;
  10388. l35dd:
  10389.         ld      (l4462),hl      ; Set block end pointer
  10390.         ex      de,hl
  10391.         ld      hl,(l448c)
  10392.         ld      (l4460),hl      ; Set block start pointer
  10393. l35e7:
  10394.         ld      hl,(l7b6d)      ; Get last memory address
  10395.         or      a
  10396.         sbc     hl,de           ; Build difference
  10397.         ld      b,h
  10398.         ld      c,l
  10399.         jr      l3612
  10400. ;
  10401. ; Redirected load error
  10402. ;
  10403. l35f1:
  10404.         ld      de,(l448c)
  10405.         call    l35e7
  10406.         jp      l3ed9
  10407. ;
  10408. ; Control: MOVE BLOCK
  10409. ;
  10410. l35fb:
  10411.         call    l363c
  10412.         jp      nc,l3d2c        ; Restore line
  10413.         call    l3687
  10414.         ld      hl,(l448c)
  10415.         ld      de,(l4460)      ; Get block start pointer
  10416.         ld      (l4460),hl      ; Set block start pointer
  10417.         add     hl,bc
  10418.         ld      (l4462),hl      ; Set block end pointer
  10419. l3612:
  10420.         ex      de,hl
  10421.         or      a
  10422.         call    l3f18
  10423.         ld      hl,(l4460)      ; Get block start pointer
  10424.         call    l33a9
  10425.         jp      l3762
  10426. ;
  10427. ; Control: COPY BLOCK
  10428. ;
  10429. l3620:
  10430.         call    l363c
  10431.         jp      nc,l3d2c        ; Restore line
  10432.         call    l3687
  10433.         ld      hl,(l448c)
  10434.         ld      (l4460),hl      ; Set block start pointer
  10435.         add     hl,bc
  10436.         ld      (l4462),hl      ; Set block end pointer
  10437.         call    l401f
  10438.         call    l3d2c           ; Restore line
  10439.         jp      l3762
  10440. ;
  10441. ;
  10442. ;
  10443. l363c:
  10444.         bit     0,(iy+20)       ; Test block set
  10445.         jr      z,l3644         ; Yeap
  10446.         xor     a
  10447.         ret
  10448. l3644:
  10449.         call    l3e23           ; Find last non blank
  10450.         inc     hl
  10451.         ld      de,(l4452)      ; Get current edit pointer
  10452.         push    de
  10453.         call    l4191           ; Find min
  10454.         ex      de,hl
  10455.         call    l3e44           ; Sample character
  10456.         pop     hl
  10457.         ld      de,l7b74
  10458.         or      a
  10459.         sbc     hl,de           ; Subtract base
  10460.         ld      de,(l4450)      ; Get current memory pointer
  10461.         add     hl,de           ; Build real pointer
  10462.         ld      (l448c),hl
  10463.         push    hl
  10464.         ld      de,(l4460)      ; Get block start pointer
  10465.         inc     de
  10466.         call    cmp_hl_de               ; Compare HL:DE
  10467.         ld      de,(l4462)      ; Get block end pointer
  10468.         jr      c,l367a         ; HL < Start_Of_Block
  10469.         call    cmp_hl_de               ; Compare HL:DE
  10470.         jr      nc,l367a        ; HL >= End_Of_Block
  10471.         or      a
  10472.         jr      l3685
  10473. l367a:
  10474.         ld      hl,(l4460)      ; Get block start pointer
  10475.         or      a
  10476.         sbc     hl,de
  10477.         ld      (l448e),hl
  10478.         ld      c,l
  10479.         ld      b,h
  10480. l3685:
  10481.         pop     hl
  10482.         ret
  10483. ;
  10484. ;
  10485. ;
  10486. l3687:
  10487.         call    l3f18
  10488.         ld      bc,(l448e)
  10489.         ld      a,c             ; Negate value
  10490.         cpl
  10491.         ld      c,a
  10492.         ld      a,b
  10493.         cpl
  10494.         ld      b,a
  10495.         inc     bc
  10496.         ld      de,(l448c)
  10497.         ld      hl,(l4460)      ; Get block start pointer
  10498.         push    bc
  10499.         ldir
  10500.         pop     bc
  10501.         ret
  10502. ;
  10503. ; Control: DELETE BLOCK
  10504. ;
  10505. l36a1:
  10506.         bit     0,(iy+20)       ; Test block set
  10507.         ret     nz              ; Nope
  10508.         call    l3e40           ; Sample character
  10509.         ld      hl,(l4460)      ; Get block start pointer
  10510.         call    l3bf5           ; Get previous EOL
  10511.         ld      (l4450),hl      ; Set current memory pointer
  10512.         ld      hl,(l4454)      ; Get block pointer
  10513.         ld      de,(l4460)      ; Get block start pointer
  10514.         inc     de
  10515.         call    cmp_hl_de               ; Compare HL:DE
  10516.         jr      c,l36ce         ; HL < Start_Of_Block
  10517.         ld      de,(l4462)      ; Get block end pointer
  10518.         call    cmp_hl_de               ; Compare HL:DE
  10519.         jr      nc,l36ce        ; HL >= End_Of_Block
  10520.         ld      hl,(l4450)      ; Get current memory pointer
  10521.         ld      (l4454),hl      ; Set block pointer
  10522. l36ce:
  10523.         ld      hl,(l4462)      ; Get block end pointer
  10524.         ld      de,(l4460)      ; Get block start pointer
  10525.         or      a
  10526.         sbc     hl,de
  10527.         jp      c,l3d2c         ; Restore line if End < Start
  10528.         ld      c,l
  10529.         ld      b,h
  10530.         ex      de,hl
  10531.         push    hl
  10532.         push    bc
  10533.         push    af
  10534.         call    l401f
  10535.         pop     af
  10536.         pop     bc
  10537.         pop     hl
  10538.         call    l3f18
  10539.         ld      hl,(l4450)      ; Get current memory pointer
  10540.         ld      (l4460),hl      ; Set block start pointer
  10541.         ld      (l4462),hl      ; Set block end pointer
  10542.         call    l3d2c           ; Restore line
  10543.         jp      l3762
  10544. ;
  10545. ; Control: TOGGLE BLOCK DISPLAY
  10546. ;
  10547. l36f9:
  10548.         ld      hl,l4480        ; Point to block mark
  10549.         call    l3796           ; Toggle block bit
  10550.         jp      l3762
  10551. ;
  10552. ; Control: MARK END OF BLOCK
  10553. ;
  10554. l3702:
  10555.         ld      hl,(l4452)      ; Get current edit pointer
  10556.         ld      (l4466),hl      ; Set for end of block
  10557.         ld      hl,(l4450)      ; Get current memory pointer
  10558.         ld      (l4462),hl      ; Set block end pointer
  10559.         bit     1,(iy+1)        ; Test end block
  10560.         set     1,(iy+1)
  10561. l3716:
  10562.         ex      af,af'
  10563.         bit     0,(iy+20)       ; Test previous block set
  10564.         res     0,(iy+20)       ; Set now
  10565.         jr      nz,l3762        ; Was not set
  10566.         ex      af,af'
  10567.         jr      z,l3762         ; Prevous was also not set
  10568.         jr      l374e
  10569. ;
  10570. ; Control: MARK BEGIN OF BLOCK
  10571. ;
  10572. l3726:
  10573.         ld      hl,(l4452)      ; Get current edit pointer
  10574.         ld      (l4464),hl      ; Save address
  10575.         ld      hl,(l4450)      ; Get current memory pointer
  10576.         ld      (l4460),hl      ; Set block start pointer
  10577.         bit     0,(iy+1)        ; Test start block
  10578.         set     0,(iy+1)
  10579.         jr      l3716
  10580. ;
  10581. ; Control: BEGIN OF BLOCK
  10582. ;
  10583. l373c:
  10584.         call    l3e40           ; Sample character
  10585.         ld      hl,(l4460)      ; Get block start pointer
  10586.         jp      l33a9
  10587. ;
  10588. ; Control: END OF BLOCK
  10589. ;
  10590. l3745:
  10591.         call    l3e40           ; Sample character
  10592.         ld      hl,(l4462)      ; Get block end pointer
  10593.         jp      l33a9
  10594. ;
  10595. ;
  10596. ;
  10597. l374e:
  10598.         ld      h,0             ; Set left column
  10599.         call    l37a7           ; Set editor cursor
  10600.         ld      hl,l7b74        ; Load base address
  10601.         set     0,(iy+16)
  10602.         call    l3c1a
  10603.         res     0,(iy+16)
  10604.         ret
  10605. ;
  10606. ;
  10607. ;
  10608. l3762:
  10609.         call    l374e
  10610.         jp      l4147           ; Reset row
  10611. ;
  10612. ; Control: END OF TEXT
  10613. ;
  10614. l3768:
  10615.         call    l3e40           ; Sample character
  10616.         ld      hl,(l4546)      ; Get end of text
  10617.         jp      l33a9
  10618. ;
  10619. ; Control: LINE LEFT
  10620. ;
  10621. l3771:
  10622.         ld      hl,l7b74        ; Set start of line
  10623.         ld      (l4452),hl      ; Set current edit pointer
  10624.         jp      l3fe7 ;set column?
  10625. ;
  10626. ; Control: LINE RIGHT
  10627. ;
  10628. l377a:
  10629.         call    l3e23           ; Find last non blank
  10630.         inc     hl
  10631.         ld      de,l7b74+_LinLen
  10632.         call    cmp_hl_de               ; Compare HL:DE
  10633.         jr      c,l3789
  10634.         ld      hl,l7b74+_LinLen-1
  10635. l3789:
  10636.         ld      (l4452),hl      ; Set current edit pointer
  10637.         jp      l3fe7 ;set column?
  10638. ;
  10639. ; Control: TOGGLE INSERT/OVERWRITE
  10640. ;
  10641. l378f:
  10642.         ld      (iy+8),0        ; Set no change
  10643.         ld      hl,l4472        ; Point to insert mode
  10644. ;
  10645. ; Toggle status bit ^HL
  10646. ;
  10647. l3796:
  10648.         ld      a,(hl)          ; Get value
  10649.         xor     1               ; Toggle bit
  10650.         ld      (hl),a
  10651.         ret
  10652. ;
  10653. ; Control: TOGGLE TABULATE
  10654. ;
  10655. l379b:
  10656.         ld      (iy+8),0        ; Set no change
  10657.         ld      hl,l4479
  10658.         jr      l3796           ; Toggle tabulate bit
  10659. ;
  10660. ; Set current edit cursor
  10661. ;
  10662. l37a4:
  10663.         ld      h,(iy+4)        ; Get column
  10664. ;
  10665. ; Set editor cursor to current row
  10666. ; ENTRY Reg H holds column position
  10667. ;
  10668. l37a7:
  10669.         ld      l,(iy+5)        ; Get row
  10670.         jp      l02a2           ; Position cursor
  10671. ;
  10672. ; Control: LINE DOWN
  10673. ;
  10674. l37ad:
  10675.         ld      hl,(l4450)      ; Get current memory pointer
  10676.         call    findnexteol             ; Find next end of line
  10677.         ret     c               ; Out of text
  10678.         call    l3e40           ; Sample character
  10679.         ld      hl,(l4450)      ; Get current memory pointer
  10680.         call    findnexteol             ; Find next end of line
  10681. l37bd:
  10682.         ld      (l4450),hl      ; Set current memory pointer
  10683.         res     0,(iy+14)
  10684.         set     0,(iy+21)
  10685.         call    l401f
  10686.         res     0,(iy+21)
  10687.         jp      l3d2c           ; Restore line
  10688. ;
  10689. ; Control: LINE UP
  10690. ;
  10691. l37d2:
  10692.         ld      hl,(l4450)      ; Get current memory pointer
  10693.         call    findprevline            ; Find previous line
  10694.         ret     c               ; Below start of text
  10695.         push    hl
  10696.         call    l3e40           ; Sample character
  10697.         pop     hl
  10698.         jr      l37bd
  10699. ;
  10700. ; Control: SCROLL UP
  10701. ;
  10702. l37e0:
  10703.         ld      hl,(curstartofpage)     ; Get start of screen
  10704.         ld      de,(l4544)      ; Get start of text
  10705.         call    cmp_hl_de               ; Compare HL:DE
  10706.         ret     z
  10707.         call    l3e40           ; Sample character
  10708.         ld      b,0
  10709.         ld      hl,(l4450)      ; Get current memory pointer
  10710. l37f3:
  10711.         ld      de,(curstartofpage)     ; Get start of screen
  10712.         call    cmp_hl_de               ; Compare HL:DE
  10713.         jr      z,l3802         ; Match
  10714.         call    findprevline            ; Find previous line
  10715.         inc     b
  10716.         jr      l37f3
  10717. l3802:
  10718.         ld      de,(l4450)      ; Get current memory pointer
  10719.         ld      (l4450),hl      ; Set current memory pointer
  10720.         ex      de,hl
  10721.         ld      a,(l0169)       ; Get screen lines
  10722.         sub     3               ; Less status
  10723.         cp      b
  10724.         jr      nz,l3815
  10725.         call    findprevline            ; Find previous line
  10726. l3815:
  10727.         push    hl
  10728.         ld      hl,(l4450)      ; Get current memory pointer
  10729.         call    findprevline            ; Find previous line
  10730.         call    l37bd
  10731.         pop     hl
  10732. l3820:
  10733.         jr      l37bd
  10734. ;
  10735. ; Control: SCROLL DOWN
  10736. ;
  10737. l3822:
  10738.         call    l3e40           ; Sample character
  10739.         ld      hl,(l4450)      ; Get current memory pointer
  10740.         push    hl
  10741.         ld      hl,(curstartofpage)     ; Get start of screen
  10742.         ld      a,(l0169)       ; Get screen lines
  10743.         sub     2               ; Less status
  10744.         ld      b,a
  10745. l3832:
  10746.         call    findnexteol             ; Find next end of line
  10747.         djnz    l3832
  10748.         push    af
  10749.         call    l37bd
  10750.         pop     af
  10751.         pop     hl
  10752.         jr      c,l3820
  10753.         ld      de,(curstartofpage)     ; Get start of screen
  10754.         call    cmp_hl_de               ; Compare HL:DE
  10755.         jr      nc,l3820        ; HL >= Start_Of_Screen
  10756.         call    findnexteol             ; Find next end of line
  10757.         jr      l3820
  10758. ;
  10759. ; Control: BOTTOM OF SCREEN
  10760. ;
  10761. l384d:
  10762.         ld      hl,(curstartofpage)     ; Get start of screen
  10763.         ld      de,(l4450)      ; Get current memory pointer
  10764.         call    cmp_hl_de               ; Compare HL:DE
  10765.         ret     z               ; Same
  10766.         push    hl
  10767.         call    l3e40           ; Sample character
  10768.         pop     hl
  10769.         jr      l3820
  10770. ;
  10771. ; Control: TOP OF SCREEN
  10772. ;
  10773. l385f:
  10774.         call    l3e40           ; Sample character
  10775.         ld      hl,(curstartofpage)     ; Get start of screen
  10776.         ld      a,(l0169)       ; Get screen lines
  10777.         sub     3               ; Less status
  10778.         ld      b,a
  10779. l386b:
  10780.         call    findnexteol             ; Find next end of line
  10781.         djnz    l386b
  10782.         jr      l3820
  10783. ;
  10784. ; Control: PAGE DOWN
  10785. ;
  10786. l3872:
  10787.         call    l3e40           ; Sample character
  10788.         ld      a,(l0169)       ; Get screen lines
  10789.         sub     2               ; Less status
  10790.         ld      c,a
  10791.         ld      b,a
  10792.         ld      hl,(curstartofpage)     ; Get start of screen
  10793. l387f:
  10794.         call    findnexteol             ; Find next end of line
  10795.         djnz    l387f
  10796.         ld      (curstartofpage),hl     ; Set start of screen
  10797.         ld      b,c
  10798.         ld      hl,(l4450)      ; Get current memory pointer
  10799. l388b:
  10800.         call    findnexteol             ; Find next end of line
  10801.         djnz    l388b
  10802. l3890:
  10803.         ld      (l4450),hl      ; Set current memory pointer
  10804.         call    l401f
  10805.         call    l4147           ; Reset row
  10806.         jp      l3d2c           ; Restore line
  10807. ;
  10808. ; Control: PAGE UP
  10809. ;
  10810. l389c:
  10811.         call    l3e40           ; Sample character
  10812.         ld      a,(l0169)       ; Get screen lines
  10813.         sub     2               ; Less status
  10814.         ld      b,a
  10815.         ld      c,a
  10816.         ld      hl,(curstartofpage)     ; Get start of screen
  10817. l38a9:
  10818.         call    findprevline            ; Find previous line
  10819.         djnz    l38a9
  10820.         ld      (curstartofpage),hl     ; Set start of screen
  10821.         ld      b,c
  10822.         ld      hl,(l4450)      ; Get current memory pointer
  10823. l38b5:
  10824.         call    findprevline            ; Find previous line n-times
  10825.         djnz    l38b5
  10826.         jr      l3890
  10827. ;
  10828. ; Control: BEGIN OF TEXT
  10829. ;
  10830. l38bc:
  10831.         ld      hl,(curstartofpage)     ; Get start of screen
  10832.         ld      de,(l4544)      ; Get start of text
  10833.         call    cmp_hl_de               ; Compare HL:DE
  10834.         jr      z,l38cb         ; Same
  10835.         call    l4147           ; Reset row
  10836. l38cb:
  10837.         call    l3e40           ; Sample character
  10838.         ld      hl,(l4544)      ; Get start of text
  10839.         ld      (l4450),hl      ; Set current memory pointer
  10840.         ld      (curstartofpage),hl     ; Set start of screen
  10841.         call    l401f
  10842.         call    l3d2c           ; Restore line
  10843.         ld      hl,l7b74
  10844.         ld      (l4452),hl      ; Init edit pointer
  10845.         jp      l3fe7 ;set column?
  10846. ;
  10847. ; Control: NEW LINE
  10848. ;
  10849. l38e6:
  10850.         bit     0,(iy+6)        ; Test insert
  10851.         jr      z,l38f2         ; New line
  10852.         call    l37ad           ; Line down
  10853.         jp      l3771           ; Goto start of line
  10854. l38f2:
  10855.         set     0,(iy+19)
  10856.         xor     a
  10857.         ld      (l4542),a       ; Force compile
  10858.         ld      a,lf
  10859.         call    puttoconsole_a          ; Put new line to console
  10860.         call    l3918
  10861.         call    l37a4           ; Set edit cursor
  10862.         bit     0,(iy+13)       ; Test auto tab
  10863.         ret     nz              ; Yeap
  10864.         call    l3a6b           ; Position to previous line
  10865.         ret     c               ; Below start of text
  10866.         ld      de,l43f2
  10867.         call    l412e           ; Find blank
  10868.         jp      c,l3a72         ; Yeap, insert tab
  10869.         ret
  10870. ;
  10871. ;
  10872. ;
  10873. l3918:
  10874.         call    l3950
  10875.         ld      hl,(l4450)      ; Get current memory pointer
  10876.         push    hl
  10877.         call    l3d2c           ; Restore line
  10878.         call    l3e40           ; Sample character
  10879.         pop     hl
  10880.         call    findnexteol             ; Find next end of line
  10881.         ld      (l4450),hl      ; Set current memory pointer
  10882.         ld      hl,l7b74
  10883. l392f:
  10884.         ld      (l4452),hl      ; Set current edit pointer
  10885.         call    l3fe7 ;set column?
  10886.         call    l401f
  10887.         jp      l3d2c           ; Restore line
  10888. ;
  10889. ; Control: INSERT LINE
  10890. ;
  10891. l393b::
  10892.         call    l3950
  10893.         call    l0200
  10894.         db      cr,lf,null
  10895.         ld      hl,(l4450)      ; Get current memory pointer
  10896.         call    findnexteol             ; Find next end of line
  10897.         call    l3c1a
  10898.         jp      l3d2c           ; Restore line
  10899. ;
  10900. ;
  10901. ;
  10902. l3950:
  10903.         call    l3e40           ; Sample character
  10904.         ld      a,(l01ae)       ; Test insert line implemented
  10905.         or      a
  10906.         push    af
  10907.         call    nz,l0262        ; Yeap: insert line
  10908.         pop     af
  10909.         call    z,l4139         ; Nope
  10910.         call    l3e23           ; Find last non blank
  10911.         inc     hl              ; Skip
  10912.         ld      de,(l4452)      ; Get current edit pointer
  10913.         call    l4191           ; Find min
  10914.         ld      de,l7b74
  10915.         or      a
  10916.         sbc     hl,de           ; Subtract base
  10917. l3970:
  10918.         ex      de,hl
  10919.         ld      hl,(l4450)      ; Get current memory pointer
  10920.         add     hl,de           ; Add offset
  10921.         push    hl
  10922.         scf
  10923.         ld      bc,-2
  10924.         call    l3f18
  10925.         pop     hl
  10926.         ld      (hl),cr         ; Close line
  10927.         inc     hl
  10928.         ld      (hl),lf
  10929.         ret
  10930. ;
  10931. ; Control: CURSOR LEFT
  10932. ;
  10933. l3984:
  10934.         ld      hl,(l4452)      ; Get current edit pointer
  10935.         call    l3c02           ; move character left
  10936.         ret     c               ; Not possible
  10937. l398b:
  10938.         ld      (l4452),hl      ; Set current edit pointer
  10939.         jp      l3fe7 ;set column?
  10940. ;
  10941. ; Control: CURSOR RIGHT
  10942. ;
  10943. l3991:
  10944.         ld      hl,(l4452)      ; Get current edit pointer
  10945.         call    l3be8           ; move character right
  10946.         ret     nc              ; Out off limit
  10947.         jr      l398b           ; Save new position
  10948. ;
  10949. ; Control: LAST CURSOR POSITION
  10950. ;
  10951. l399a:
  10952.         call    l3e40           ; Sample character
  10953.         ld      hl,(l4458)      ; Get edit pointer
  10954.         call    l3bf5           ; Get previous EOL
  10955.         ld      (l4450),hl      ; Set current memory pointer
  10956.         ld      hl,(l445a)
  10957.         jp      l392f
  10958. ;
  10959. ; Control: MARK SINGLE WORD
  10960. ;
  10961. l39ac:
  10962.         call    l3a0b           ; Word right
  10963.         call    l39ea           ; Word left
  10964.         ld      hl,(l4452)      ; Get current edit pointer
  10965. l39b5:
  10966.         call    l412a           ; Find delimiter
  10967.         jr      c,l39bf         ; Yeap
  10968.         call    l3be8           ; move character right
  10969.         jr      c,l39b5         ; Still in limit
  10970. l39bf:
  10971.         ld      (l4452),hl      ; Set current edit pointer
  10972.         call    l3702           ; Mark end
  10973.         call    l39ea           ; Word left
  10974.         jp      l3726           ; Mark start
  10975. ;
  10976. ;
  10977. ;
  10978. l39cb:
  10979.         ld      hl,(l4450)      ; Get current memory pointer
  10980.         call    findprevline            ; Find previous line
  10981.         jr      c,l3a05         ; Below start
  10982.         push    hl
  10983.         call    l3e40           ; Sample character
  10984.         pop     hl
  10985.         ld      (l4450),hl      ; Set current memory pointer
  10986.         res     0,(iy+14)
  10987.         call    l401f
  10988.         call    l3d2c           ; Restore line
  10989.         call    l3e23           ; Find last non blank
  10990.         jr      l3a01
  10991. ;
  10992. ; Control: WORD LEFT
  10993. ;
  10994. l39ea:
  10995.         ld      hl,(l4452)      ; Get current edit pointer
  10996. l39ed:
  10997.         call    l3c02           ; move character left
  10998.         jr      c,l39cb         ; At beginning of line
  10999.         call    l412a           ; Find delimiter
  11000.         jr      c,l39ed         ; Yeap
  11001. l39f7:
  11002.         call    l3c02           ; move character left
  11003.         jr      c,l3a01         ; At beginning of line
  11004.         call    l412a           ; Find delimiter
  11005.         jr      nc,l39f7        ; Nope
  11006. l3a01:
  11007.         inc     hl
  11008. l3a02:
  11009.         ld      (l4452),hl      ; Set current edit pointer
  11010. l3a05:
  11011.         ld      hl,(l4452)      ; Get current edit pointer
  11012.         jp      l3fe7 ;set column?
  11013. ;
  11014. ; Control: WORD RIGHT
  11015. ;
  11016. l3a0b:
  11017.         call    l3e23           ; Find last non blank
  11018.         ld      de,(l4452)      ; Get current edit pointer
  11019.         push    de
  11020.         xor     a
  11021.         sbc     hl,de
  11022.         jr      nc,l3a19
  11023.         inc     a
  11024. l3a19:
  11025.         ld      (l7b71),a       ; Set direction flag
  11026.         pop     hl
  11027. l3a1d:
  11028.         dec     hl
  11029. l3a1e:
  11030.         call    l3be8           ; move character right
  11031.         jr      c,l3a4e         ; Still in limit
  11032. l3a23:
  11033.         ld      hl,(l4450)      ; Get current memory pointer
  11034.         call    findnexteol             ; Find next end of line
  11035.         ret     c               ; Out of text
  11036.         call    l3e40           ; Sample character
  11037.         ld      hl,(l4450)      ; Get current memory pointer
  11038.         call    findnexteol             ; Find next end of line
  11039.         ld      (l4450),hl      ; Set current memory pointer
  11040.         res     0,(iy+14)
  11041.         call    l401f
  11042.         call    l3d2c           ; Restore line
  11043.         ld      hl,l7b74
  11044.         ld      (l4452),hl      ; Init current edit pointer
  11045.         call    l412a           ; Find delimiter
  11046.         jr      c,l3a1d         ; Yeap
  11047.         jp      l3fe7 ;set column?
  11048. l3a4e:
  11049.         call    l412a           ; Find delimiter
  11050.         jr      nc,l3a1e        ; Nope
  11051. l3a53:
  11052.         call    l3be8           ; move character right
  11053.         jr      c,l3a64         ; Still in limit
  11054.         ld      a,(l7b71)       ; Get direction
  11055.         or      a
  11056.         jr      nz,l3a23
  11057.         call    l3e23           ; Find last non blank
  11058.         inc     hl              ; Skip
  11059.         jr      l3a02
  11060. l3a64:
  11061.         call    l412a           ; Find delimiter
  11062.         jr      c,l3a53         ; Yeap
  11063.         jr      l3a02
  11064. ;
  11065. ; Position to previous line
  11066. ; EXIT  Reg HL points to line
  11067. ;       Carry set if below start of text
  11068. ;
  11069. l3a6b:
  11070.         ld      hl,(l4450)      ; Get current memory pointer
  11071.         call    findprevline            ; Find previous line
  11072.         ret
  11073. ;
  11074. ; Control: TABULATE
  11075. ;
  11076. l3a72:
  11077.         call    l3a6b           ; Position to previous line
  11078.         ret     c               ; Below start of text
  11079.         ld      a,(l4471)       ; Get row
  11080.         push    af              ; Save it
  11081.         ld      hl,(l4452)      ; Get current edit pointer
  11082.         ld      (l4468),hl      ; Save it
  11083.         res     0,(iy+7)        ; Disable video
  11084.         call    l3e40           ; Sample character
  11085.         ld      hl,(l4450)      ; Get current memory pointer
  11086.         push    hl
  11087.         call    findprevline            ; Find previous line
  11088.         ld      (l4450),hl      ; Set current memory pointer
  11089.         call    l3d2c           ; Restore line
  11090.         ld      hl,l43f2
  11091.         ld      (l7b72),hl      ; Set pointer to reduced delimiters
  11092.         call    l3a0b           ; Word right
  11093.         ld      hl,l43de
  11094.         ld      (l7b72),hl      ; Reset pointer to delimiters
  11095.         pop     hl
  11096.         pop     af
  11097.         ld      (l4471),a       ; Reset row
  11098.         ld      (l4450),hl      ; Reset current memory pointer
  11099.         call    l3d2c           ; Restore line
  11100.         set     0,(iy+7)        ; Enable video
  11101.         bit     0,(iy+6)        ; Test insert
  11102.         jp      nz,l374e        ; Nope
  11103.         ld      hl,(l4452)      ; Get current edit pointer
  11104.         ld      de,(l4468)      ; Get back previous pointer
  11105.         sbc     hl,de           ; Get difference
  11106.         ret     c               ; Nothing to clear
  11107.         ret     z
  11108.         ex      de,hl           ; Get length
  11109. l3ac5:
  11110.         push    de
  11111.         call    l41eb           ; Make room
  11112.         ld      (hl),' '        ; Insert blank
  11113.         pop     de
  11114.         dec     e
  11115.         jr      nz,l3ac5
  11116.         jp      l374e
  11117. ;
  11118. ; Control: DELETE TO END OF LINE
  11119. ;
  11120. l3ad2:
  11121.         ld      hl,(l4452)      ; Get current edit pointer
  11122.         push    hl
  11123.         call    l3fc5
  11124.         pop     hl
  11125.         push    hl
  11126.         ld      de,l7b74+_LinLen-1
  11127. l3ade:
  11128.         ld      (hl),' '        ; Clear character
  11129.         call    cmp_hl_de               ; Compare HL:DE
  11130.         jr      z,l3ae8         ; Match
  11131.         inc     hl              ; Advance
  11132.         jr      l3ade
  11133. l3ae8:
  11134.         pop     hl
  11135.         jp      l4197
  11136. ;
  11137. ; Control: DELETE LINE
  11138. ;
  11139. l3aec::
  11140.         ld      hl,l7b74
  11141.         ld      (l4452),hl      ; Set current edit pointer
  11142.         call    l3fe7 ;set column?
  11143.         call    l3ad2           ; Delete to end of line
  11144.         call    l3e40           ; Sample character
  11145.         ld      hl,(l4450)      ; Get current memory pointer
  11146.         push    hl
  11147.         push    hl
  11148.         call    findnexteol             ; Find next end of line
  11149.         pop     de
  11150.         jr      c,l3b10         ; Out of text
  11151.         or      a
  11152.         sbc     hl,de           ; Fet length
  11153.         ld      c,l
  11154.         ld      b,h
  11155.         pop     hl
  11156.         jp      nz,l3b26
  11157.         ret
  11158. l3b10:
  11159.         pop     hl
  11160.         jp      l3d2c           ; Restore line
  11161. l3b14:
  11162.         call    l3e44           ; Sample character
  11163.         ld      hl,(l4450)      ; Get current memory pointer
  11164.         call    findnexteol             ; Find next end of line
  11165.         jp      c,l3d2c         ; Restore line if out of text
  11166.         dec     hl
  11167.         dec     hl
  11168.         ld      bc,2
  11169.         or      a
  11170. l3b26:
  11171.         call    l3f18
  11172.         ld      a,(l01b4)       ; Test delete line implemented
  11173.         or      a
  11174.         jr      z,l3b3c         ; Nope
  11175.         call    l0259           ; Delete line
  11176.         ld      a,(l0169)       ; Get screen lines
  11177.         dec     a
  11178.         call    l3bbc
  11179.         jp      l3d2c           ; Restore line
  11180. l3b3c:
  11181.         call    l4139
  11182.         jp      l3d2c           ; Restore line
  11183. ;
  11184. ; Control: DELETE RIGHT WORD
  11185. ;
  11186. l3b42:
  11187.         call    l3e23           ; Find last non blank
  11188.         ld      de,(l4452)      ; Get current edit pointer
  11189.         call    cmp_hl_de               ; Compare HL:DE
  11190.         ex      de,hl
  11191.         jr      c,l3b14         ; HL<DE
  11192.         ld      a,(hl)
  11193.         cp      ' '             ; Test blank
  11194.         jr      z,l3b8c
  11195.         call    l412a           ; Find delimiter
  11196.         jr      c,l3b83         ; Yeap
  11197. l3b59:
  11198.         call    l4173
  11199.         call    l412a           ; Find delimiter
  11200.         jr      c,l3b86         ; Yeap
  11201.         jr      l3b59
  11202. ;
  11203. ;
  11204. ;
  11205. l3b63:
  11206.         ld      hl,(l4450)      ; Get current memory pointer
  11207.         call    findprevline            ; Find previous line
  11208.         ret     c               ; Below start of text
  11209.         call    l37d2           ; Line up
  11210.         call    l377a           ; Line right
  11211.         jp      l3b42           ; Delete right word
  11212. ;
  11213. ; Control: DELETE RIGHT CHARACTER
  11214. ;
  11215. l3b73:
  11216.         ld      hl,(l4452)      ; Get current edit pointer
  11217.         jr      l3b83           ; Go delete
  11218. ;
  11219. ; Control: DELETE LEFT CHARACTER
  11220. ;
  11221. l3b78:
  11222.         ld      hl,(l4452)      ; Get current edit pointer
  11223.         call    l3c02           ; move character left
  11224.         jr      c,l3b63         ; Beginning of line
  11225.         ld      (l4452),hl      ; Set current edit pointer
  11226. l3b83:
  11227.         call    l4173
  11228. l3b86:
  11229.         call    l3fe7 ;set column?
  11230.         jp      l4197
  11231. l3b8c:
  11232.         call    l4173
  11233.         ld      a,(hl)
  11234.         cp      ' '             ; Test blank
  11235.         jr      z,l3b8c         ; Skip them
  11236.         jr      l3b86
  11237. ;
  11238. ;
  11239. ;
  11240. l3b96:
  11241.         call    l428f           ; Test look ahead buffer empty
  11242.         jp      nz,l37a4        ; Nope, set edit cursor
  11243.         call    l3bac
  11244.         jr      nc,l3b96
  11245.         jp      l37a4           ; Set edit cursor
  11246. ;
  11247. ;
  11248. ;
  11249. l3ba4:
  11250.         call    l3bac
  11251.         jr      nc,l3ba4
  11252.         jp      l37a4           ; Set edit cursor
  11253. ;
  11254. ; ????????????????????????????????????????????
  11255. ; EXIT  Carry set if row same as screen height
  11256. ;
  11257. l3bac:
  11258.         ld      a,(l4475)       ; Get current row
  11259.         ld      hl,l0169        ; Get screen lines
  11260.         cp      (hl)            ; Compare
  11261.         scf
  11262.         ret     z               ; Same, so exit
  11263.         inc     (iy+9)          ; Bump row
  11264.         cp      (iy+5)          ; Test aginst row
  11265.         ret     z
  11266. ;
  11267. ;
  11268. ;
  11269. l3bbc:
  11270.         ld      h,0             ; Set column
  11271.         ld      l,a             ; Get row
  11272.         push    af
  11273.         call    l02a2           ; Position cursor
  11274.         pop     af
  11275.         ld      hl,(curstartofpage)     ; Get start of screen
  11276.         ld      b,a
  11277. l3bc8:
  11278.         dec     b
  11279.         jr      z,l3bd8
  11280.         call    findnexteol             ; Find next end of line
  11281.         jr      nc,l3bc8
  11282.         call    l3cec           ; Make normal video
  11283.         call    l3c12           ; Clear line
  11284.         xor     a
  11285.         ret
  11286. l3bd8:
  11287.         call    l3c1a
  11288.         xor     a
  11289.         ret
  11290. ;
  11291. ;
  11292. ;
  11293. l3bdd:
  11294. ;gotonextchar,check eof
  11295.         inc     hl
  11296.         ld      de,(l4546)      ; Get end of text
  11297. ;
  11298. ; Compare addresses
  11299. ; ENTRY Regs HL and DE hold addresses
  11300. ; EXIT  Zero  set if HL=DE
  11301. ;       Carry set if HL<DE
  11302. ;
  11303. cmp_hl_de:
  11304.         push    hl
  11305.         or      a
  11306.         sbc     hl,de           ; Compare
  11307.         pop     hl
  11308.         ret
  11309. ;
  11310. ; move pointer right
  11311. ; ENTRY Reg HL holds pointer
  11312. ; EXIT  Carry reset if pointer ou of limit
  11313. ;
  11314. l3be8:
  11315.         inc     hl              ; Point to next
  11316.         ld      de,l7b74+_LinLen-2
  11317.         jr      cmp_hl_de               ; Compare HL:DE
  11318. ;
  11319. ; Fix to start of line
  11320. ; ENTRY Reg HL holds text pointer
  11321. ; EXIT  Reg HL decremented by 1
  11322. ;       Carry set if HL < Start_of_Text
  11323. ;
  11324. l3bee:
  11325.         dec     hl
  11326.         ld      de,(l4544)      ; Get start of text
  11327.         jr      cmp_hl_de               ; Compare HL:DE
  11328. ;
  11329. ; Find EOL of previous line
  11330. ; ENTRY Reg HL holds current pointer
  11331. ; EXIT  Reg HL points to previous end
  11332. ;
  11333. l3bf5:
  11334.         ld      a,lf
  11335. l3bf7:
  11336.         call    l3bee           ; Fix to start of line
  11337.         ret     z               ; Got it
  11338.         jr      c,l3c00         ; Here before start
  11339.         cp      (hl)            ; Find new line
  11340.         jr      nz,l3bf7        ; Nope
  11341. l3c00:
  11342.         inc     hl              ; Adjust pointer
  11343.         ret
  11344. ;
  11345. ; move pointer left
  11346. ; ENTRY Reg HL holds pointer
  11347. ; EXIT  Carry set if pointer out of limit
  11348. ;
  11349. l3c02:
  11350.         dec     hl              ; Get previous
  11351.         ld      de,l7b74        ; Init pointer
  11352.         jr      cmp_hl_de               ; Compare HL:DE
  11353. ;
  11354. ;
  11355. ;
  11356. l3c08:
  11357. ;nextline
  11358.         cp      cr              ; Test return
  11359.         ret     nz              ; Nope
  11360.         ld      a,(hl)
  11361.         call    l3bdd ;gotonextchar,check eof
  11362.         ret     nc ;eof
  11363.         jr      l3c08
  11364. ;
  11365. ; Clear line
  11366. ;
  11367. l3c12:
  11368.         ld      a,(l0168)       ; Get screen columns
  11369.         dec     a
  11370.         ld      b,a
  11371. l3c17:
  11372.         jp      l3cf9           ; Clear to end of line
  11373. ;
  11374. ;
  11375. ;
  11376. l3c1a:
  11377.         call    l3ca1
  11378.         call    l3cc0
  11379.         ld      a,(l446c) ;xscroll???
  11380.         ld      b,a
  11381.         or      a
  11382.         jr      z,l3c36
  11383. l3c27:
  11384.         ld      a,(hl)
  11385.         call    l3bdd
  11386.         jr      nc,l3c12        ; Clear line
  11387.         call    l3c08 ;nextline (hl after cr)
  11388.         cp      lf              ; Test new line
  11389.         jr      z,l3c12         ; Clear line if so
  11390.         djnz    l3c27 ;skip xscroll chars???
  11391. l3c36:
  11392.         ld      a,(l0168)       ; Get screen columns
  11393.         dec     a
  11394.         ld      b,a
  11395.         bit     0,(iy+16)
  11396.         jr      z,l3c5e
  11397. l3c41:
  11398.         call    l3ca1
  11399.         call    l3cc0
  11400.         push    hl
  11401.         call    l3e23           ; Find last non blank
  11402.         ld      de,(l4452)      ; Get current edit pointer
  11403.         call    l4191           ; Find min
  11404.         ex      de,hl           ; Change to max
  11405.         inc     hl
  11406.         ld      (l4486),hl
  11407.         ex      de,hl
  11408.         pop     hl
  11409.         call    cmp_hl_de               ; Compare HL:DE
  11410.         jr      nc,l3c89        ; Clear if HL>=DE
  11411. l3c5e:
  11412.         call    l3ca1
  11413.         call    l3cc0
  11414.         ld      de,(l4486)
  11415.         call    cmp_hl_de               ; Compare HL:DE
  11416.         jr      z,l3c89         ; Clear if same
  11417.         ld      a,(hl)
  11418.         call    l3bdd ;gotonextchar,check eof
  11419.         jr      nc,l3c17        ; Clear line
  11420.         call    l3c08 ;nextline (hl after cr)
  11421.         cp      lf              ; Test end of line
  11422.         jr      z,l3c17         ; Clear on new line
  11423.         call    l3c8b           ; Process control character
  11424.         djnz    l3c5e
  11425. l3c7f:
  11426.         ld      a,(hl)
  11427.         call    l3bdd
  11428.         jr      nc,l3c89        ; Clear line
  11429.         cp      lf              ; Test new line
  11430.         jr      nz,l3c7f
  11431. l3c89:
  11432.         jr      l3c17           ; Clear line
  11433. ;
  11434. ; Process control character
  11435. ;
  11436. l3c8b:
  11437.         cp      ' '             ; Test control character
  11438.         jr      nc,l3c96        ; Nope
  11439.         add     a,'@'           ; Make ASCII
  11440.         push    af
  11441.         call    l3c99           ; Select video
  11442.         pop     af
  11443. l3c96:
  11444.         jp      puttoconsole_a          ; Put to console ;TODO speedup
  11445. ;
  11446. ; Select video
  11447. ;
  11448. l3c99:
  11449.         ld      a,(l00e0)       ;ok ;FIXME ; Get video mode
  11450.         or      a
  11451.         jr      z,l3cec         ; Make normal video
  11452.         jr      l3cdf           ; Set low video
  11453. ;
  11454. ;
  11455. ;
  11456. l3ca1:
  11457.         bit     0,(iy+16)
  11458.         ret     z
  11459.         bit     0,(iy+20)       ; Test block set
  11460.         jr      nz,l3cec        ; Nope, make normal video
  11461.         ld      de,(l4464)      ; Get block start address
  11462.         call    cmp_hl_de               ; Compare HL:DE
  11463.         jr      c,l3cec         ; Make normal video
  11464.         ld      de,(l4466)      ; Get end of block pointer
  11465.         call    cmp_hl_de               ; Compare HL:DE
  11466.         jr      c,l3cdf         ; Set low video
  11467.         jr      l3cec           ; Make normal video
  11468. ;
  11469. ;
  11470. ;
  11471. l3cc0:
  11472.         bit     0,(iy+16)
  11473.         ret     nz
  11474.         bit     0,(iy+20)       ; Test block set
  11475.         jr      nz,l3cec        ; Nope, make normal video
  11476.         ld      de,(l4460)      ; Get block start pointer
  11477.         call    cmp_hl_de               ; Compare HL:DE
  11478.         jr      c,l3cec         ; Make normal video
  11479.         ld      de,(l4462)      ; Get block end pointer
  11480.         call    cmp_hl_de               ; Compare HL:DE
  11481.         jr      z,l3cec         ; Make normal video
  11482.         jr      nc,l3cec        ; Make normal video
  11483. ;
  11484. ; Set low video
  11485. ;
  11486. l3cdf:
  11487.         ld      a,(l00e0)       ;ok ;FIXME ; Get video mode
  11488.         or      a               ; Test enabled
  11489.         ret     z               ; Nope
  11490.         bit     0,(iy+7)        ; Test selected
  11491.         ret     z               ; Nope
  11492.         jp      setlowvideo             ; Set low video
  11493. ;
  11494. ; Set normal video
  11495. ;
  11496. l3cec:
  11497.         ld      a,(l00e0)       ;ok ;FIXME ; Get video mode
  11498.         or      a               ; Test enabled
  11499.         ret     nz              ; Yeap
  11500.         bit     0,(iy+7)        ; Test selected
  11501.         ret     z               ; Nope
  11502.         jp      setnormvideo            ; Set normal video
  11503. ;
  11504. ; Clear to end of line
  11505. ; ENTRY Reg B holds column position
  11506. ;
  11507. l3cf9:
  11508.         inc     b               ; Test position
  11509.         dec     b
  11510.         ret     z               ; Ignore left margin
  11511.         ld      a,(l01bc)       ; Test clear to end of line implemented
  11512.         or      a
  11513.         jp      nz,l0299        ; Yeap
  11514. l3d03:
  11515.         ld      a,' '
  11516.         call    puttoconsole_a          ; Put blanks to console
  11517.         djnz    l3d03
  11518.         ret
  11519. ;
  11520. ; Delete current line
  11521. ;
  11522. l3d0b:
  11523.         ld      a,(l01b4)       ; Test delete line implemented
  11524.         or      a
  11525.         jr      nz,l3d23        ; Yeap
  11526.         ld      (l4474),a       ; Set no change
  11527.         ld      a,(l0169)       ; Get screen lines
  11528.         dec     a
  11529.         ld      l,a             ; Set row
  11530.         ld      h,0             ; Set column
  11531.         call    l02a2           ; Position cursor
  11532.         ld      a,lf
  11533.         jp      puttoconsole_a          ; Put new line to console
  11534. l3d23:
  11535.         ld      hl,256*0+1
  11536.         call    l02a2           ; Position cursor
  11537.         jp      l0259           ; Delete line
  11538. ;
  11539. ; Control: RESTORE DELETED LINE
  11540. ;
  11541. l3d2c:
  11542.         ld      hl,(l4450)      ; Get current memory pointer
  11543.         ld      de,0
  11544.         ld      (l4464),de      ; Reset start of block pointer
  11545.         ld      (l4466),de      ; Reset end of block pointer
  11546.         ld      b,_LinLen       ; Set max length
  11547.         ld      ix,l7b74        ; Set base address
  11548.         ld      (iy+1),0        ; Clear block state
  11549. l3d44: ;;;;;;
  11550.         ld      a,(hl)
  11551.         ld      de,(l4460)      ; Get block start pointer
  11552.         call    cmp_hl_de               ; Compare HL:DE
  11553.         jr      nz,l3d56        ; Not same addresses
  11554.         ld      (l4464),ix      ; Set start of block pointer
  11555.         set     0,(iy+1)        ; Set start block
  11556. l3d56:
  11557.         ld      de,(l4462)      ; Get block end pointer
  11558.         call    cmp_hl_de               ; Compare HL:DE
  11559.         jr      nz,l3d67        ; Not same addresses
  11560.         ld      (l4466),ix      ; Set end of block pointer
  11561.         set     1,(iy+1)        ; Set end block
  11562. l3d67:
  11563.         cp      cr              ; Test end of line
  11564.         jr      nz,l3dc3        ; Nope
  11565.         ld      (ix+0),' '      ; Fill with blank
  11566.         inc     ix
  11567.         dec     b
  11568.         jr      z,l3dd9
  11569.         call    l3bdd
  11570.         jr      nc,l3d44
  11571. l3d79:
  11572.         ld      de,(l4462)      ; Get block end pointer
  11573.         call    cmp_hl_de               ; Compare HL:DE
  11574.         jr      nc,l3d8a        ; HL>= Start_Of_Block
  11575.         push    hl
  11576.         ld      hl,-1
  11577.         ld      (l4466),hl      ; Set end of block pointer
  11578.         pop     hl
  11579. l3d8a:
  11580.         ld      de,(l4460)      ; Get block start pointer
  11581.         call    cmp_hl_de               ; Compare HL:DE
  11582.         jr      nc,l3d99        ; HL>= End_Of_Block
  11583.         ld      hl,-1
  11584.         ld      (l4464),hl      ; Set start of block pointer
  11585. l3d99: ;;;;;
  11586.         ld      a,_LinLen
  11587.         sub     b               ; Calculate remaining length
  11588.         ld      (l446f),a       ; Save relative column
  11589. l3d9f:
  11590.         ld      (ix+0),' '      ; Fill with blanks
  11591.         inc     ix
  11592.         djnz    l3d9f
  11593.         ld      hl,(l4452)      ; Get current edit pointer
  11594.         call    l3fe7 ;set column?
  11595.         bit     0,(iy+14)
  11596.         set     0,(iy+14)
  11597.         jp      nz,l374e
  11598.         ld      a,(l4475)       ; Get current row
  11599.         dec     a
  11600.         cp      (iy+5)          ; Test against row
  11601.         ret     nc
  11602.         jp      l374e
  11603. l3dc3:
  11604.         cp      lf              ; Test end of line
  11605.         jr      z,l3d79         ; Yeap
  11606.         ld      (ix+0),a        ; Store character
  11607.         inc     ix
  11608.         dec     b               ; Test still room
  11609.         jr      nz,l3dd1        ; Yeap
  11610.         jr      l3dd9           ; Line too long
  11611. l3dd1:
  11612.         call    l3bdd
  11613.         jr      nc,l3d79
  11614.         jp      l3d44
  11615. l3dd9:
  11616.         call    l3e04           ; Tell error
  11617.         db      'Line too long - CR inserted'
  11618.         db      null
  11619.         call    l3f12
  11620.         ld      hl,_LinLen-2
  11621.         call    l3970
  11622.         jp      l3d2c           ; Restore line
  11623. ;
  11624. ;
  11625. ;
  11626. l3e04:
  11627.         call    l3ba4
  11628. l3e07:
  11629.         call    l3e0d           ; Set cursor
  11630.         jp      l4211
  11631. ;
  11632. ; Set cursor home
  11633. ;
  11634. l3e0d:
  11635.         ld      (iy+8),0        ; Set no change
  11636.         ld      hl,256*0+0
  11637.         call    l02a2           ; Position cursor
  11638.         call    l3c12           ; Clear line
  11639.         ld      hl,256*0+0
  11640.         call    l02a2           ; Position cursor
  11641.         jp      l3cdf           ; Set low video
  11642. ;
  11643. ; Find last non blank in current line
  11644. ; EXIT  Reg HL holds pointer to non blank
  11645. ;
  11646. l3e23:
  11647.         ld      a,' '           ; Set what we are looking for
  11648.         ld      hl,l7b74+_LinLen-1
  11649.         ld      de,l7b74-1      ; Init pointers
  11650. l3e2b:
  11651.         cp      (hl)            ; Test match
  11652.         ret     nz              ; Nope, got it
  11653.         dec     hl
  11654.         call    cmp_hl_de               ; Test beginning
  11655.         jr      nz,l3e2b        ; Nope
  11656.         ret
  11657. ;
  11658. ; Get pointer within limits
  11659. ; ENTRY Reg HL holds 1st pointer
  11660. ;       Reg BC holds 2nd pointer
  11661. ; EXIT  Reg HL unchanged if out of line
  11662. ;       Reg HL holds MIN(HL,BC) else
  11663. ;
  11664. l3e34:
  11665.         ld      de,l7b74+_LinLen
  11666.         call    cmp_hl_de               ; Compare HL:DE
  11667.         ret     nc              ; End found
  11668.         ld      d,b
  11669.         ld      e,c
  11670.         jp      l4191           ; Find min
  11671. ;
  11672. ; Poll character, insert at end of line
  11673. ;
  11674. l3e40:
  11675.         call    l3e23           ; Find last non blank
  11676.         inc     hl              ; Skip over
  11677. ;
  11678. ; Poll character, insert at current position
  11679. ; ENTRY Reg HL holds current text address
  11680. ;
  11681. l3e44:
  11682.         ld      c,l             ; Copy pointer
  11683.         ld      b,h
  11684.         ld      hl,(l4464)      ; Get start of block pointer
  11685.         call    l3e34           ; Fix it
  11686.         ld      (l4464),hl      ; Set start of block pointer
  11687.         ld      hl,(l4466)      ; Get end of block pointer
  11688.         call    l3e34           ; Fix it
  11689.         ld      (l4466),hl      ; Set end of block pointer
  11690.         ld      l,c
  11691.         ld      h,b
  11692.         inc     hl
  11693.         ld      de,l7b74
  11694.         or      a
  11695.         sbc     hl,de           ; Get relative position
  11696.         push    hl
  11697.         ld      a,(l446f)       ; Get relative column
  11698.         sub     l               ; Subtract it
  11699.         ld      c,a
  11700.         ld      b,0             ; Expand for 16 bits
  11701.         jr      nc,l3e6d
  11702.         ld      b,-1            ; Signed expansion
  11703. l3e6d:
  11704.         ld      hl,(l4450)      ; Get current memory pointer
  11705.         call    nz,l3f18
  11706.         pop     bc
  11707.         ld      ix,(l4450)      ; Get current memory pointer
  11708.         ld      hl,l7b74        ; Load base
  11709.         ld      b,c             ; Copy position
  11710.         dec     b               ; Test any
  11711.         inc     b
  11712.         jr      z,l3ea5         ; Nope
  11713. l3e80:
  11714.         ld      a,(hl)          ; Get character
  11715.         ld      de,(l4464)      ; Get start of block pointer
  11716.         call    cmp_hl_de               ; Compare HL:DE
  11717.         jr      nz,l3e8e        ; Not the same
  11718.         ld      (l4460),ix      ; Set block start pointer
  11719. l3e8e:
  11720.         ld      de,(l4466)      ; Get end of block pointer
  11721.         call    cmp_hl_de               ; Compare HL:DE
  11722.         jr      nz,l3e9b        ; Not the same
  11723.         ld      (l4462),ix      ; Set block end pointer
  11724. l3e9b:
  11725.         ld      (ix+0),a        ; Unpack character
  11726.         inc     hl
  11727.         inc     ix
  11728.         djnz    l3e80
  11729.         dec     ix
  11730. l3ea5:
  11731.         ld      a,cr
  11732.         ld      (ix+0),a        ; Set end of line
  11733.         ret
  11734. ;
  11735. ; Display characters left and check enough memory
  11736. ;
  11737. l3eab:
  11738.         ld      hl,(l4548)      ; Get top of available memory
  11739.         or      a
  11740.         sbc     hl,de           ; Test remainder
  11741.         jr      c,l3ed9         ; Nope
  11742.         ld      bc,l00fe
  11743.         sbc     hl,bc           ; Test min
  11744.         ret     nc              ; Yeap
  11745.         add     hl,bc
  11746.         push    hl
  11747.         call    l3e0d           ; Set cursor
  11748.         pop     hl
  11749.         ld      b,0
  11750.         call    l30fe           ; Tell bytes left
  11751.         call    l4211
  11752.         db      ' byte(s) left'
  11753.         db      null
  11754.         call    l3f12           ; Wait for quit
  11755.         ret
  11756. l3ed9:
  11757.         call    l3e04
  11758.         db      'ERROR: Out of space'
  11759.         db      null
  11760.         call    l3f12           ; Wait for quit
  11761.         jp      l2ebd
  11762. ;
  11763. ; Test editor function cancelled
  11764. ;
  11765. l3ef6:
  11766.         cp      a_CAN           ; Test cancel
  11767.         ret     nz              ; Nope
  11768.         call    l3e04
  11769.         db      '*** INTERRUPTED'
  11770.         db      null
  11771.         call    l3f12           ; Wait for quit
  11772.         jp      l2ebd
  11773. ;
  11774. ; Clear ahaed buffer and wait for user quit
  11775. ;
  11776. l3f12:
  11777.         call    l422b           ; Clear look ahead buffer
  11778.         jp      l2e76           ; Get ESCape
  11779. ;
  11780. ;
  11781. ;
  11782. l3f18:
  11783.         push    hl
  11784.         push    bc
  11785.         jr      nc,l3f96
  11786.         ld      de,(l4546)      ; Get end of text
  11787.         push    de
  11788.         push    de
  11789.         ex      de,hl
  11790.         or      a
  11791.         sbc     hl,de
  11792.         ex      (sp),hl
  11793.         or      a
  11794.         sbc     hl,bc
  11795.         jp      nc,l3ed9
  11796.         ld      e,l
  11797.         ld      d,h
  11798.         push    de
  11799.         call    l3eab           ; Test enough room
  11800.         pop     de
  11801.         pop     bc
  11802.         inc     bc
  11803.         pop     hl
  11804.         ld      (l4546),de      ; Set end of text
  11805.         ld      a,b
  11806. l3f3c:
  11807.         sub     HIGH _SavLen
  11808.         jr      c,l3f4d
  11809.         ld      b,a
  11810.         push    bc
  11811.         ld      bc,_SavLen
  11812.         lddr                    ; move down
  11813.         pop     bc
  11814.         call    l4232           ; Poll character from input
  11815.         jr      l3f3c
  11816. l3f4d:
  11817.         ld      a,c
  11818.         or      b
  11819.         jr      z,l3f53
  11820.         lddr
  11821. l3f53:
  11822.         pop     bc
  11823.         pop     hl
  11824.         ex      de,hl
  11825.         inc     de
  11826.         ld      hl,(l4460)      ; Get block start pointer
  11827.         call    l3f8e
  11828.         ld      (l4460),hl      ; Set block start pointer
  11829.         ld      hl,(l4462)      ; Get block end pointer
  11830.         call    l3f8e
  11831.         ld      (l4462),hl      ; Set block end pointer
  11832.         ld      hl,(curstartofpage)     ; Get start of screen
  11833.         call    l3f8e
  11834.         ld      (curstartofpage),hl     ; Set start of screen
  11835.         ld      hl,(l4450)      ; Get current memory pointer
  11836.         call    l3f8e
  11837.         ld      (l4450),hl      ; Set current memory pointer
  11838.         ld      hl,(l4454)      ; Get block pointer
  11839.         call    l3f8e
  11840.         ld      (l4454),hl      ; Set block pointer
  11841.         ld      hl,(l4458)      ; Get edit pointer
  11842.         call    l3f8e
  11843.         ld      (l4458),hl      ; Set edit pointer
  11844.         ret
  11845. ;
  11846. ;
  11847. ;
  11848. l3f8e:
  11849.         call    cmp_hl_de               ; Compare HL:DE
  11850.         ret     c
  11851.         or      a
  11852.         sbc     hl,bc
  11853.         ret
  11854. ;
  11855. ;
  11856. ;
  11857. l3f96:
  11858.         push    hl
  11859.         add     hl,bc
  11860.         push    hl
  11861.         ld      de,(l4546)      ; Get end of text
  11862.         inc     de
  11863.         ex      de,hl
  11864.         or      a
  11865.         sbc     hl,de
  11866.         ld      c,l
  11867.         ld      b,h
  11868.         pop     hl
  11869.         pop     de
  11870.         ld      a,b
  11871. l3fa7:
  11872.         sub     HIGH _SavLen
  11873.         jr      c,l3fb8
  11874.         ld      b,a
  11875.         push    bc
  11876.         ld      bc,_SavLen
  11877.         ldir                    ; move up
  11878.         pop     bc
  11879.         call    l4232           ; Poll character from input
  11880.         jr      l3fa7
  11881. l3fb8:
  11882.         ld      a,c
  11883.         or      b
  11884.         jr      z,l3fbf
  11885.         ldir
  11886.         dec     de
  11887. l3fbf:
  11888.         ld      (l4546),de      ; Set end of text
  11889.         jr      l3f53
  11890. ;
  11891. ;
  11892. ;
  11893. l3fc5:
  11894.         push    hl
  11895.         ld      de,(l4464)      ; Get start of block pointer
  11896.         call    l4191           ; Find min
  11897.         bit     0,(iy+1)        ; Test start block
  11898.         jr      z,l3fd6         ; Nope
  11899.         ld      (l4464),hl      ; Set start of block pointer
  11900. l3fd6:
  11901.         pop     hl
  11902.         bit     1,(iy+1)        ; Test end block
  11903.         ret     z               ; Nope
  11904.         ld      de,(l4466)      ; Get end of block pointer
  11905.         call    l4191           ; Find min
  11906.         ld      (l4466),hl      ; Set end of block pointer
  11907.         ret
  11908. ;
  11909. ;
  11910. ;set column?
  11911. l3fe7:
  11912.         ld      de,l7b74        ; Get base address
  11913.         ld      a,(l0168)       ; Get screen columns
  11914.         dec     a
  11915.         ld      c,a
  11916.         or      a
  11917.         sbc     hl,de
  11918.         ld      a,l
  11919.         sub     (iy+0)
  11920.         jr      c,l4012
  11921.         cp      c
  11922.         jr      c,l400e
  11923.         sub     c
  11924.         inc     a
  11925.         add     a,(iy+0)
  11926.         ld      (l446c),a ;xscroll???
  11927.         ld      a,(l0168)       ; Get screen columns
  11928.         dec     a
  11929.         dec     a
  11930.         ld      (l4470),a       ; Set column to end
  11931.         jp      l3762
  11932. l400e:
  11933.         ld      (l4470),a       ; Set column
  11934.         ret
  11935. l4012:
  11936.         add     a,(iy+0)
  11937.         ld      (l446c),a ;xscroll???
  11938.         ld      (iy+4),0        ; Clear column
  11939.         jp      l3762
  11940. ;
  11941. ;
  11942. ;
  11943. l401f:
  11944.         bit     0,(iy+7)
  11945.         ret     z
  11946.         ld      hl,(curstartofpage)     ; Get start of screen
  11947.         ld      de,(l4544)      ; Get start of text
  11948.         call    l4191           ; Find min
  11949.         ex      de,hl
  11950.         ld      (curstartofpage),hl     ; Set max for start of screen
  11951.         ld      bc,1
  11952.         ld      de,(l4450)      ; Get current memory pointer
  11953.         call    cmp_hl_de               ; Compare HL:DE
  11954.         jp      z,l40da         ; Same
  11955.         jr      c,l4086         ; HL < Current_Pointer
  11956. l4041:
  11957.         ld      de,(l4450)      ; Get current memory pointer
  11958.         call    cmp_hl_de               ; Compare HL:DE
  11959.         jr      z,l4055         ; Same
  11960.         call    findprevline            ; Find previous line
  11961.         inc     bc
  11962.         ld      a,c
  11963.         or      a
  11964.         call    z,l4232         ; Poll character from input
  11965.         jr      l4041
  11966. l4055:
  11967.         ld      (curstartofpage),hl     ; Set start of screen
  11968.         ld      (iy+5),1        ; Init row
  11969.         set     0,(iy+14)
  11970.         ld      a,b
  11971.         or      a
  11972.         jr      nz,l4083        ; Test row
  11973.         ld      a,(l01ae)       ; Test insert line implemented
  11974.         or      a
  11975.         jr      z,l4083         ; Nope
  11976.         ld      a,(l0169)       ; Get screen lines
  11977.         dec     a
  11978.         cp      c
  11979.         jr      c,l4083
  11980.         dec     c
  11981.         ld      hl,256*0+1
  11982.         call    l02a2           ; Position cursor
  11983.         dec     c
  11984.         push    af
  11985.         inc     c
  11986. l407b:
  11987.         call    l0262           ; Insert line
  11988.         dec     c
  11989.         jr      nz,l407b
  11990.         pop     af
  11991.         ret     z
  11992. l4083:
  11993.         jp      l4147           ; Reset row
  11994. l4086:
  11995.         ld      de,(l4450)      ; Get current memory pointer
  11996.         call    cmp_hl_de               ; Compare HL:DE
  11997.         jr      z,l409a         ; Same
  11998.         call    findnexteol             ; Find next end of line
  11999.         inc     bc
  12000.         ld      a,c
  12001.         or      a
  12002.         call    z,l4232         ; Poll character from input
  12003.         jr      l4086
  12004. l409a:
  12005.         ld      a,b
  12006.         or      a
  12007.         jr      nz,l40de
  12008.         ld      a,(l0169)       ; Get screen lines
  12009.         dec     a
  12010.         ld      e,a
  12011.         ld      a,c
  12012.         sub     e
  12013.         ld      d,a
  12014.         inc     d
  12015.         jr      c,l40da
  12016.         dec     d
  12017.         jr      nz,l40b3
  12018.         bit     0,(iy+21)
  12019.         jp      nz,l4103
  12020. l40b3:
  12021.         inc     d
  12022.         sub     e
  12023.         jr      nc,l40de
  12024.         ld      a,(l4475)       ; Get current row
  12025.         sub     d               ; Test row
  12026.         jr      c,l40de
  12027.         jr      z,l40de
  12028.         ld      (l4475),a       ; Set row
  12029.         ld      hl,(curstartofpage)     ; Get start of screen
  12030.         ld      b,d
  12031.         push    de
  12032. l40c7:
  12033.         call    findnexteol             ; Find next end of line
  12034.         push    hl
  12035.         call    l3d0b           ; Delete current line
  12036.         pop     hl
  12037.         djnz    l40c7
  12038.         ld      (curstartofpage),hl     ; Set start of screen
  12039.         pop     de
  12040. l40d5:
  12041.         dec     e
  12042.         ld      (iy+5),e        ; Set row
  12043.         ret
  12044. l40da:
  12045.         ld      (iy+5),c        ; Set row
  12046.         ret
  12047. l40de:
  12048.         ld      hl,(curstartofpage)     ; Get start of screen
  12049.         dec     bc
  12050.         ld      a,(l0169)       ; Get screen lines
  12051.         sub     3
  12052.         ld      e,a
  12053.         ld      a,c
  12054.         sub     e
  12055.         ld      c,a
  12056.         jr      nc,l40ee
  12057.         dec     b
  12058. l40ee:
  12059.         call    findnexteol             ; Find next end of line
  12060.         dec     bc
  12061.         ld      a,c
  12062.         or      b
  12063.         jr      nz,l40ee
  12064.         ld      (curstartofpage),hl     ; Set start of screen
  12065.         call    l4147           ; Reset row
  12066.         set     0,(iy+14)
  12067.         jp      l401f
  12068. l4103:
  12069.         call    l40d5
  12070.         ld      a,(l4475)       ; Get current row
  12071.         ld      l,a
  12072.         ld      a,(l0169)       ; Get screen lines
  12073.         cp      l
  12074.         ld      a,l
  12075.         jr      z,l4117
  12076.         dec     a
  12077.         jr      z,l4117
  12078.         ld      (l4475),a       ; Set row
  12079. l4117:
  12080.         ld      hl,(curstartofpage)     ; Get start of screen
  12081.         call    findnexteol             ; Find next end of line
  12082.         ld      (curstartofpage),hl     ; Set start of screen
  12083.         call    l3d0b           ; Delete current line
  12084.         ld      a,(l0169)       ; Get screen lines
  12085.         dec     a
  12086.         jp      l3bbc
  12087. ;
  12088. ; Find delimiter
  12089. ; ENTRY Reg HL points to current text
  12090. ; EXIT  Carry set if delimiter found
  12091. ;
  12092. l412a:
  12093.         ld      de,(l7b72)      ; Get pointer to delimiters
  12094. l412e:
  12095.         ld      a,(de)          ; Test end of list
  12096.         or      a
  12097.         ret     z               ; Yeap
  12098.         cp      (hl)            ; Compare
  12099.         jr      z,l4137         ; Got it
  12100.         inc     de
  12101.         jr      l412e
  12102. l4137:
  12103.         scf
  12104.         ret
  12105. ;
  12106. ; Delete line if no ESC sequence present
  12107. ;
  12108. l4139:
  12109.         push    af
  12110.         ld      a,(l4471)       ; Get row
  12111.         cp      (iy+9)          ; Compare
  12112.         jr      nc,l4145
  12113.         ld      (l4475),a       ; Set row
  12114. l4145:
  12115.         pop     af
  12116.         ret
  12117. ;
  12118. ; Reset row
  12119. ;
  12120. l4147:
  12121.         ld      (iy+9),1        ; Init row
  12122.         ret
  12123. ;
  12124. ; Adjust pointer for inserting characters
  12125. ; ENTRY Reg BC holds number of characters to be inserted
  12126. ;
  12127. l414c:
  12128.         ex      de,hl
  12129.         bit     0,(iy+1)        ; Test start block
  12130.         jr      z,l415f         ; Nope
  12131.         ld      hl,(l4464)      ; Get start of block pointer
  12132.         call    cmp_hl_de               ; Compare HL:DE
  12133.         jr      c,l415f         ; Start_of_block < DE
  12134.         add     hl,bc           ; Add offset
  12135.         ld      (l4464),hl      ; Set start of block pointer
  12136. l415f:
  12137.         bit     1,(iy+1)        ; Test end block
  12138.         jr      z,l4171         ; Nope
  12139.         ld      hl,(l4466)      ; Get end of block pointer
  12140.         call    cmp_hl_de               ; Compare HL:DE
  12141.         jr      c,l4171         ; End_of_block < DE
  12142.         add     hl,bc           ; Add offset
  12143.         ld      (l4466),hl      ; Set end of block pointer
  12144. l4171:
  12145.         ex      de,hl
  12146.         ret
  12147. ;
  12148. ;
  12149. ;
  12150. l4173:
  12151.         push    hl
  12152.         ld      bc,-1
  12153.         call    l414c           ; Delete one character
  12154.         ex      de,hl
  12155.         ld      hl,l7b74+_LinLen-1
  12156.         or      a
  12157.         sbc     hl,de
  12158.         jr      z,l418a         ; Same
  12159.         ld      c,l
  12160.         ld      b,h
  12161.         ld      l,e
  12162.         ld      h,d
  12163.         inc     hl
  12164.         ldir                    ; Unpack
  12165. l418a:
  12166.         ld      hl,l7b74+_LinLen-1
  12167.         ld      (hl),' '        ; Clear last entry
  12168.         pop     hl
  12169.         ret
  12170. ;
  12171. ; Get minimum of two addresses
  12172. ; ENTRY Reg HL holds 1st address
  12173. ;       Reg DE holds 2nd address
  12174. ; EXIT  Regs swapped if 1st >= 2nd
  12175. ;
  12176. l4191:
  12177.         call    cmp_hl_de               ; Compare HL:DE
  12178.         ret     c               ; HL < DE
  12179.         ex      de,hl           ; Swap
  12180.         ret
  12181. ;
  12182. ;
  12183. ;
  12184. l4197:
  12185.         call    l37a4           ; Set edit cursor
  12186.         ld      a,(l0168)       ; Get screen columns
  12187.         dec     a
  12188.         sub     (iy+4)          ; Subtract from column
  12189.         ld      hl,(l4452)      ; Get current edit pointer
  12190.         ld      b,a
  12191.         set     0,(iy+16)
  12192.         call    l3c41
  12193.         res     0,(iy+16)
  12194.         ret
  12195. ;
  12196. ; Adjust for next end of line
  12197. ; ENTRY Reg HL holds current pointer
  12198. ; EXIT  Reg HL holds pointer to next line
  12199. ;       Carry set if pointer behind end address
  12200. ;
  12201. findnexteol:
  12202.         push    bc
  12203.         ex      de,hl
  12204.         ld      hl,(l4546)      ; Get end of text
  12205.         dec     hl
  12206.         or      a
  12207.         sbc     hl,de           ; Build difference
  12208.         ld      b,h
  12209.         ld      c,l
  12210.         inc     bc
  12211.         ex      de,hl
  12212.         ld      d,h
  12213.         ld      e,l
  12214.         jr      c,l41cc         ; Out of text
  12215.         ld      a,lf
  12216.         cpir                    ; Find new line
  12217.         jp      po,l41cc
  12218.         or      a
  12219.         pop     bc
  12220.         ret
  12221. l41cc:
  12222.         scf                     ; Set out of text
  12223.         ex      de,hl
  12224.         pop     bc
  12225.         ret
  12226. ;
  12227. ; Adjust for previous end of line
  12228. ; ENTRY Reg HL holds current pointer
  12229. ; EXIT  Reg HL holds pointer to previous line
  12230. ;       Carry set if pointer below start address
  12231. ;
  12232. findprevline:
  12233.         push    bc
  12234.         ld      c,l             ; Save pointer
  12235.         ld      b,h
  12236.         ld      a,lf
  12237.         call    l3bee           ; Fix to start of line
  12238.         jr      c,l41e7         ; Below
  12239. l41da:
  12240.         call    l3bee           ; Fix to start of line
  12241.         jr      z,l41e5         ; Got start
  12242.         jr      c,l41e7         ; It's below start
  12243.         cp      (hl)            ; Find line feed
  12244.         jr      nz,l41da        ; Nope
  12245.         inc     hl
  12246. l41e5:
  12247.         pop     bc
  12248.         ret
  12249. l41e7:
  12250.         ld      h,b             ; Restore pointer
  12251.         ld      l,c
  12252.         pop     bc
  12253.         ret
  12254. ;
  12255. ; Adjust pointer for inserting one character
  12256. ;
  12257. l41eb:
  12258.         push    hl
  12259.         ld      bc,1
  12260.         call    l414c           ; Adjust pointer for inserting one character
  12261.         ld      de,l7b74+_LinLen-1
  12262.         ex      de,hl
  12263.         or      a
  12264.         sbc     hl,de           ; Get difference
  12265.         dec     hl
  12266.         ld      c,l
  12267.         ld      b,h
  12268.         ld      de,l7b74+_LinLen-2
  12269.         ld      l,e
  12270.         ld      h,d
  12271.         dec     hl
  12272.         ld      a,c
  12273.         or      b               ; Test any
  12274.         jr      z,l420c         ; Nope
  12275.         push    de
  12276.         lddr                    ; move characters
  12277.         pop     hl
  12278.         ld      (hl),' '        ; Clear character
  12279. l420c:
  12280.         pop     hl
  12281.         ret
  12282. ;
  12283. ; Position cursor and give immediate string
  12284. ; ENTRY Reg H holds column
  12285. ;       Reg L holds row
  12286. ;
  12287. l420e:
  12288.         call    l02a2           ; Position cursor
  12289. l4211:
  12290.         jp      l01fa           ; Give string
  12291. ;
  12292. ; #####################################################
  12293. ; >>> Redirected console output during edit session <<<
  12294. ; #####################################################
  12295. ;
  12296. l4214:
  12297.         pop     hl
  12298.         ex      (sp),hl
  12299.         bit     0,(iy+7)
  12300.         jr      z,l4220
  12301.         push    hl
  12302. l421e   equ     $+1
  12303.         call    a_DUMMY         ; *** REDIRECTED ***
  12304. l4220:
  12305.         ld      a,(l4543)
  12306.         sub     2
  12307.         ld      (l4543),a
  12308.         ret     nz
  12309.         jr      l423e           ; Poll character from input
  12310. ;
  12311. ; Clear look ahead buffer
  12312. ;
  12313. l422b:
  12314.         ld      hl,(l445c)      ; Get input queue pointer
  12315.         ld      (l445e),hl      ; Set for output queue pointer
  12316.         ret
  12317. ;
  12318. ; Poll character from input
  12319. ;
  12320. l4232:
  12321.         push    af
  12322.         push    bc
  12323.         push    de
  12324.         push    hl
  12325.         call    l423e           ; Poll character from input
  12326.         pop     hl
  12327.         pop     de
  12328.         pop     bc
  12329.         pop     af
  12330.         ret
  12331. ;
  12332. ; Poll character from input without register preserving
  12333. ;
  12334. l423e:
  12335.         ld      hl,(l445e)      ; Get output queue pointer
  12336.         call    l4263           ; Bump it
  12337.         ld      de,(l445c)      ; Get input queue pointer
  12338.         ex      de,hl
  12339.         sbc     hl,de           ; Test room in output queue
  12340.         ex      de,hl
  12341.         ret     z               ; Nope
  12342.         push    hl
  12343.         push    ix
  12344.         push    iy
  12345.         YIELD
  12346.         if TERM
  12347.         GETKEY_ ;call   l00a0           ; Test key pressed
  12348.         else
  12349.         GET_KEY ;call   l00a0           ; Test key pressed
  12350.         endif
  12351.         pop     iy
  12352.         pop     ix
  12353.         pop     hl
  12354.          or a
  12355.         ret     z               ; No character available
  12356.         ;call   readfromkbd             ; Read character
  12357.         ld      (hl),a          ; Store it
  12358.         ld      (l445e),hl      ; Set output queue pointer
  12359.         ret
  12360. ;
  12361. ; Bump and check ahead pointer
  12362. ; ENTRY Reg HL holds current pointer
  12363. ; EXIT  Reg HL holds position within the queue
  12364. ;
  12365. l4263:
  12366.         inc     hl              ; Bump pointer
  12367.         ld      de,l7b59+_Ahead
  12368.         or      a
  12369.         ex      de,hl
  12370.         sbc     hl,de           ; Test end of queue
  12371.         ex      de,hl
  12372.         ret     nz              ; Nope
  12373.         ld      hl,l7b59        ; Set start of queue
  12374.         ret
  12375. ;
  12376. ; Get character from console or ahead buffer
  12377. ;
  12378. l4271:
  12379.         push    hl
  12380.         push    de
  12381.         ld      de,(l445c)      ; Get input queue pointer
  12382.         ld      hl,(l445e)      ; Get output queue pointer
  12383.         or      a
  12384.         sbc     hl,de           ; Test any in buffer
  12385.         ex      de,hl
  12386.         jr      z,l4289         ; Nope, buffer is empty
  12387.         call    l4263           ; Bump queue pointer
  12388.         ld      a,(hl)          ; Get character
  12389.         ld      (l445c),hl      ; Set input queue pointer
  12390.         jr      l428c
  12391. l4289:
  12392.         call    readfromkbd             ; Read character
  12393. l428c:
  12394.         pop     de
  12395.         pop     hl
  12396.         ret
  12397. ;
  12398. ; Test look ahead buffer empty - Z set says yes
  12399. ;
  12400. l428f:
  12401.         push    hl
  12402.         push    de
  12403.         ld      de,(l445c)      ; Get input queue pointer
  12404.         ld      hl,(l445e)      ; Get output queue pointer
  12405.         or      a
  12406.         sbc     hl,de
  12407.         pop     de
  12408.         pop     hl
  12409.         ret
  12410. ;
  12411. l429e:
  12412.         dw      l7bf5           ; Base of message file
  12413. l42a0:
  12414.         db      eof
  12415.        
  12416.         if 1==0
  12417. ;default key codes
  12418. l42a1::
  12419. ; Basic movement
  12420.         db      1,0dh
  12421.         db      1,1
  12422.         db      1,0ffh
  12423.         db      1,6
  12424.         db      1,0fah
  12425.         db      1,0fbh
  12426.         db      1,1fh
  12427.         db      1,1eh
  12428.         db      1,0f5h
  12429.         db      1,0f4h
  12430.         db      1,0f8h
  12431.         db      1,0f9h
  12432. ; Extended movement
  12433.         db      1,0f6h
  12434.         db      1,0f7h
  12435.         db      1,0ffh
  12436.         db      1,0ffh
  12437.         db      1,0ffh
  12438.         db      1,0ffh
  12439.         db      1,0ffh
  12440.         db      1,0ffh
  12441.         db      1,0ffh
  12442. ; Insert and delete commands
  12443.         db      1,0e0h
  12444.         db      1,0ffh
  12445.         db      1,0ffh
  12446.         db      1,0ffh
  12447.         db      1,0ffh
  12448.         db      1,0ffh
  12449.         db      1,0ffh
  12450.         db      1,0ffh
  12451. ; Block commands
  12452.         db      1,0ffh
  12453.         db      1,0ffh
  12454.         db      1,0ffh
  12455.         db      1,0ffh
  12456.         db      1,0ffh
  12457.         db      1,0ffh
  12458.         db      1,0ffh
  12459.         db      1,0ffh
  12460.         db      1,0ffh
  12461. ; More commands
  12462.         db      1,0ffh
  12463.         db      1,0ffh
  12464.         db      1,0ffh
  12465.         db      1,0ffh
  12466.         db      1,0ffh
  12467.         db      1,0ffh
  12468.         db      1,0ffh
  12469.         db      1,0ffh
  12470. ;
  12471.         db      0,0ffh
  12472.         db      1,0ffh
  12473. ;
  12474.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12475.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12476.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12477.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12478.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12479.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12480.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12481.         db      0,0,0,0,0,0
  12482.         endif
  12483. l4369::
  12484. ;
  12485. ; Basic movement
  12486. ;
  12487.         db      1,'M'-'@'
  12488.         db      1,key_left;'S'-'@'
  12489.         db      1,key_left;'H'-'@'
  12490.         db      1,key_right;'D'-'@'
  12491.         db      1,'A'-'@'
  12492.         db      1,'F'-'@'
  12493.         db      1,key_up;'E'-'@'
  12494.         db      1,key_down;'X'-'@'
  12495.         db      1,'W'-'@'
  12496.         db      1,'Z'-'@'
  12497.         db      1,key_pgup;'R'-'@' ;pgup
  12498.         db      1,key_pgdown;'C'-'@' ;pgdn
  12499. ;
  12500. ; Extended movement
  12501. ;
  12502.         db      1,key_home;2,'Q'-'@','S'-'@' ; LINE LEFT (home)
  12503.         db      1,key_end;2,'Q'-'@','D'-'@' ; LINE RIGHT (end)
  12504.         db      2,'Q'-'@','E'-'@' ; BOTTOM OF SCREEN
  12505.         db      2,'Q'-'@','X'-'@' ; TOP OF SCREEN
  12506.         db      2,'Q'-'@','R'-'@' ; BEGIN OF TEXT
  12507.         db      2,'Q'-'@','C'-'@' ; END OF TEXT
  12508.         db      2,'Q'-'@','B'-'@' ;to begin of block
  12509.         db      2,'Q'-'@','K'-'@' ;to end of block
  12510.         db      2,'Q'-'@','P'-'@' ;last cursor position
  12511. ;
  12512. ; Insert and delete commands
  12513. ;
  12514.         db      1,key_ins;'V'-'@' ;insert mode on/off
  12515.         db      1,'N'-'@' ;insert line
  12516.         db      1,'Y'-'@' ;delete line
  12517.         db      2,'Q'-'@','Y'-'@' ;delete to end of line
  12518.         db      1,'T'-'@' ;delete right word
  12519.         db      1,key_del;'G'-'@'
  12520.         db      1,key_backspace;DEL
  12521.         db      1,key_backspace;0ffh
  12522. ;
  12523. ; Block commands
  12524. ;
  12525.         db      2,'K'-'@','B'-'@'
  12526.         db      2,'K'-'@','K'-'@'
  12527.         db      2,'K'-'@','T'-'@'
  12528.         db      2,'K'-'@','H'-'@'
  12529.         db      2,'K'-'@','C'-'@'
  12530.         db      2,'K'-'@','V'-'@'
  12531.         db      2,'K'-'@','Y'-'@'
  12532.         db      2,'K'-'@','R'-'@'
  12533.         db      2,'K'-'@','W'-'@'
  12534. ;
  12535. ; More commands
  12536. ;
  12537.         db 1,key_esc;db 2,'K'-'@','D'-'@'
  12538.         db      1,'I'-'@'
  12539.         db      2,'Q'-'@','I'-'@'
  12540.         db      2,'Q'-'@','L'-'@'
  12541.         db      2,'Q'-'@','F'-'@'
  12542.         db      2,'Q'-'@','A'-'@'
  12543.         db      1,'L'-'@'
  12544.         db      1,'P'-'@'
  12545.         db      0
  12546. l43de::
  12547.         db      '<>,[].*+-/$:=(){}^#'''
  12548. l43f2::
  12549.         db      ' ',null
  12550. l43f4::
  12551. ;
  12552. ; Basic movement
  12553. ;
  12554.         dw      l38e6           ; NEW LINE
  12555.         dw      l3984           ; CURSOR LEFT
  12556.         dw      l3984           ; CURSOR LEFT
  12557.         dw      l3991           ; CURSOR RIGHT
  12558.         dw      l39ea           ; WORD LEFT
  12559.         dw      l3a0b           ; WORD RIGHT
  12560.         dw      l37d2           ; LINE UP
  12561.         dw      l37ad           ; LINE DOWN
  12562.         dw      l37e0           ; SCROLL UP
  12563.         dw      l3822           ; SCROLL DOWN
  12564.         dw      l389c           ; PAGE UP
  12565.         dw      l3872           ; PAGE DOWN
  12566. ;
  12567. ; Extended movement
  12568. ;
  12569.         dw      l3771           ; LINE LEFT (home)
  12570.         dw      l377a           ; LINE RIGHT (end)
  12571.         dw      l384d           ; BOTTOM OF SCREEN
  12572.         dw      l385f           ; TOP OF SCREEN
  12573.         dw      l38bc           ; BEGIN OF TEXT
  12574.         dw      l3768           ; END OF TEXT
  12575.         dw      l373c           ; BEGIN OF BLOCK
  12576.         dw      l3745           ; END OF BLOCK
  12577.         dw      l399a           ; LAST CURSOR POSITION
  12578. ;
  12579. ; Insert and delete commands
  12580. ;
  12581.         dw      l378f           ; TOGGLE INSERT/OVERWRITE
  12582.         dw      MMSB+l393b      ; INSERT LINE
  12583.         dw      MMSB+l3aec      ; DELETE LINE
  12584.         dw      MMSB+l3ad2      ; DELETE TO END OF LINE
  12585.         dw      MMSB+l3b42      ; DELETE RIGHT WORD
  12586.         dw      MMSB+l3b73      ; DELETE RIGHT CHARACTER
  12587.         dw      MMSB+l3b78      ; DELETE LEFT CHARACTER
  12588.         dw      MMSB+l3b78      ; DELETE LEFT CHARACTER
  12589. ;
  12590. ; Block commands
  12591. ;
  12592.         dw      l3726           ; MARK BEGIN OF BLOCK
  12593.         dw      l3702           ; MARK END OF BLOCK
  12594.         dw      l39ac           ; MARK SINGLE WORD
  12595.         dw      l36f9           ; TOGGLE BLOCK DISPLAY
  12596.         dw      MMSB+l3620      ; COPY BLOCK
  12597.         dw      MMSB+l35fb      ; MOVE BLOCK
  12598.         dw      MMSB+l36a1      ; DELETE BLOCK
  12599.         dw      MMSB+l3573      ; READ BLOCK FROM FILE
  12600.         dw      l34ed           ; WRITE BLOCK TO FILE
  12601. ;
  12602. ; More commands
  12603. ;
  12604.         dw      l2b0f           ; EXIT EDITOR
  12605.         dw      MMSB+l3a72      ; TABULATE
  12606.         dw      l379b           ; TOGGLE TABULATE
  12607.         dw      MMSB+l3d2c      ; RESTORE DELETED LINE
  12608.         dw      l31f1           ; FIND STRING
  12609.         dw      l323b           ; FIND AND REPLACE STRING
  12610.         dw      l324b           ; REPEAT LAST SEARCH
  12611.         dw      MMSB+l2f02      ; CONTROL PREFIX
  12612. l4450::
  12613.         dw      0               ; Current memory pointer
  12614. l4452:
  12615.         dw      l7b74           ; Current edit pointer
  12616. l4454:
  12617.         dw      0               ; Block pointer
  12618. l4456:
  12619.         dw      l7b74
  12620. l4458:
  12621.         dw      0               ; Edit pointer
  12622. l445a:
  12623.         dw      l7b74
  12624. l445c:
  12625.         dw      l7b59           ; Input queue pointer
  12626. l445e:
  12627.         dw      l7b59           ; Output queue pointer
  12628. l4460:
  12629.         dw      0               ; Block start pointer
  12630. l4462:
  12631.         dw      0               ; Block end pointer
  12632. l4464:
  12633.         dw      2               ; Block start pointer
  12634. l4466:
  12635.         dw      2               ; Block end pointer
  12636. l4468:
  12637.         dw      0               ; Temporry edit pointer
  12638. curstartofpage:
  12639.         dw      0               ; Start of screen
  12640. ;
  12641. ; The editor status block
  12642. ;
  12643. l446c:
  12644.         db      0               ; + 0 xscroll???
  12645.         db      0               ; + 1: Block state
  12646.                                 ; xxxxxxx1: Start set)
  12647.                                 ; xxxxxx1x: End set)
  12648.         db      1               ; + 2
  12649. l446f:
  12650.         db      1               ; + 3: Relative column
  12651. l4470:
  12652.         db      0               ; + 4: Editor column
  12653. l4471:
  12654.         db      1               ; + 5: Editor row
  12655. l4472:
  12656.         db      0               ; + 6: Insert flag (Bit 0=0)
  12657.         db      1               ; + 7: Video flag (1 is reverse)
  12658. l4474:
  12659.         db      0               ; + 8: Change flag
  12660. l4475:
  12661.         db      1               ; + 9: Editor row
  12662. l4476:
  12663.         db      0               ; +10
  12664.         db      0               ; +11
  12665. l4478:
  12666.         db      0               ; +12
  12667. l4479:
  12668.         db      0               ; +13: Auto tabulate flag
  12669.         db      1               ; +14
  12670.         db      1               ; +15
  12671.         db      0               ; +16
  12672. l447d:
  12673.         db      0               ; +17: Option flags for search/replace
  12674.                                 ; 00000001: W: Whole word search
  12675.                                 ; 00000010: N: No request
  12676.                                 ; 00000100: U: Ignore case
  12677.                                 ; 00001000: G: Global search
  12678.                                 ; 00010000: B: Backwards
  12679. l447e:
  12680.         db      0               ; +18: Find (0) or replace (-1) flag
  12681. l447f:
  12682.         db      0               ; +19: Text change flag
  12683. l4480:
  12684.         db      0               ; +20: Block marker (1: Not set)
  12685.         db      0               ; +21
  12686. l4482:
  12687.         db      3               ; +22
  12688. l4483:
  12689.         db      0,0,0
  12690. l4486:
  12691.         db      0,0
  12692. l4488:
  12693.         dw      0               ; End of search pointer
  12694. l448a:
  12695.         dw      0               ; Search loop count
  12696. l448c:
  12697.         dw      0
  12698. l448e:
  12699.         dw      0
  12700. ;
  12701. ; Search buffer
  12702. ;
  12703. l4490:
  12704.         db      1eh
  12705. l4491:
  12706.         db      0
  12707. l4492:
  12708.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12709.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12710.         db      0,0,0
  12711. ;
  12712. ; Replace buffer
  12713. ;
  12714. l44b1:
  12715.         db      1eh
  12716. l44b2:
  12717.         db      0
  12718. l44b3:
  12719.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12720.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12721.         db      0,0,0
  12722. ;
  12723. ; Option buffer
  12724. ;
  12725. l44d2:
  12726.         db      0ah
  12727.         db      0,0,0,0,0,0,0,0,0,0,0,0
  12728. ;
  12729. ; Block file name
  12730. ;
  12731. l44df:
  12732.         db      0fh
  12733.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12734. l44f1:
  12735.         db      0               ; File flag
  12736. l44f2:
  12737.         db      0               ; Rename flag (1 is rename)
  12738. l44f3:
  12739.         db      1               ; Compile flag:
  12740.                                 ; 1: Compile to memory
  12741.                                 ; 2: Compile to COM-file
  12742.                                 ; 3: Compile to CHN-file
  12743. l44f4:
  12744.         dw      l20e2           ; Start address of compiler
  12745. l44f6:
  12746.         dw      0               ; Top of available memory
  12747. l44f8:
  12748.         db      0               ; Logged disk
  12749. l44f9:
  12750.         ds      FCBlen          ; Main file
  12751. l451d:
  12752.         ds      FCBlen
  12753. l4541:
  12754.         db      0               ; Error message file flag (0 is not read)
  12755. l4542:
  12756.         db      0               ; Compile flag
  12757. l4543:
  12758.         db      0
  12759. l4544:
  12760.         dw      l7bf5           ; Start of text
  12761. l4546:
  12762.         dw      l7bf5           ; End of text
  12763. l4548:
  12764.         dw      0               ; Top of available memory
  12765. ;
  12766. ; %%%%%%%%%%%%%%%%%%%%%%
  12767. ; %%% COMPILER ENTRY %%%
  12768. ; %%%%%%%%%%%%%%%%%%%%%%
  12769. ;
  12770. COMPILE:
  12771.         ld      (l7b71),sp      ; Save stack
  12772.         ld      hl,(l4546)      ; Get end of text
  12773.         inc     hl
  12774.         ld      (MemsTop),hl    ; Save for memory top
  12775.         inc     h               ; Allow a gap of 1024 bytes
  12776.         inc     h
  12777.         inc     h
  12778.         inc     h
  12779.         ld      (COMsTop),hl    ; Save for top of .COM file
  12780.         ld      hl,(l790a)      ; Get end of code
  12781.         ld      (DataBeg),hl    ; Save for start of data
  12782.         xor     a
  12783.         ld      h,a
  12784.         ld      l,a
  12785.         ld      (l7b91),a       ; Clear ????
  12786.         ld      (l7b92),a       ; Clear ????
  12787.         ld      (l7b94),a       ; Clear ????
  12788.         ld      (l7ba2),a       ; Clear end of file
  12789.         ld      (l7ba0),a       ; Clear end on break [option U+]
  12790.         ld      (BackLevel),a   ; Clear back fix level
  12791.         ld      (IncFlg),a      ; Enable memory read
  12792.         ld      (l7b96),a       ; Clear OVERLAY number
  12793.         ld      (RRN_stat ),a   ; Clear file access
  12794.         ld      (RRN_off),hl    ; Clear record base
  12795.         ld      (l7bef),hl      ; Clear line count
  12796.         call    l718f           ; Test abort
  12797.         dec     hl
  12798.         ld      (FFCB+_rrn),hl  ; Set highest record
  12799.         ld      a,_Char+1 ;13=element of a set???
  12800.         ld      (curtype_l7b93),a       ; Set special type
  12801.         ld      a,0xff-(__Ropt+__Uopt)
  12802.         ld      (l7b9d),a       ; Set default options
  12803.         ld      a,2*DefWITH
  12804.         ld      (l7bc7),a       ; Set depth for WITH
  12805.         ld      hl,(l4544)      ; Get start of text
  12806.         ld      (l7bd7),hl      ; Init source pointer
  12807.         ld      (l7bd9),hl
  12808.         ld      ix,l79d7        ; Init start of line
  12809.         ld      (ix+0),null     ; Set line empty
  12810.         ld      hl,(l7904)      ; Get code start address
  12811.         call    ChkChn          ; Check chaining
  12812.         ld      hl,(l4548)      ; Get top of available memory
  12813.         dec     hl
  12814.         ld      (l7b77),hl      ; Save
  12815.         ld      d,h
  12816.         ld      e,l
  12817.         ld      bc,LenLab       ; Get length of internal table
  12818.         or      a
  12819.         sbc     hl,bc
  12820.         ld      (LabPtr),hl     ; Init label pointers
  12821.         ld      (PrevLabPtr),hl
  12822.         ld      (CurLab),hl
  12823.         call    ChkOvfl         ; Check enough memory
  12824.         ld      hl,l731f+LenLab-1
  12825.         lddr                    ; Unpack symbol table
  12826.         call    l45ea           ; Go compile
  12827.         ld      a,(CmpTyp)      ; Get compile flag
  12828.         dec     a               ; Test compiling to file
  12829.         jr      nz,l45e2        ; Nope
  12830.         call    FixBack         ; Fix back level
  12831.         call    writerecord_TmpBuff             ; Write record
  12832.          ld c,_close
  12833.          ld de,FFCB
  12834.          call _BDOS             ; must close output file!!!
  12835. l45e2:
  12836.         ld      (l7906),iy      ; Save new top of code
  12837.         xor     a
  12838.         jp      l72e3           ; Set special zero error
  12839. ;
  12840. ; Do the compiler task
  12841. ;
  12842. l45ea:
  12843.         call    GetLine         ; Process line
  12844.         call    FindStr         ; Find PROGRAM
  12845.         dw      l7529
  12846.         jr      nz,l460a        ; Nope
  12847.         call    l4692           ; Build dummy label
  12848.         call    l6f1b           ; Test (
  12849.         jr      nz,l4607        ; Nope
  12850. l45fc:
  12851.         call    l4692           ; Build dummy label
  12852.         call    l6f13           ; Test ,
  12853.         jr      z,l45fc         ; Yeap, get next dummy
  12854.         call    l6f6e           ; Verify )
  12855. l4607:
  12856.         call    l6f48           ; Verify ;
  12857. l460a:
  12858.         ld      a,_LD.SP
  12859.         ld      hl,0x0100;TPA
  12860.         call    StCode          ; Set LD SP,TPA
  12861.         ld      hl,l79d7        ; Get start of source line
  12862.         ld      a,(CmpTyp)      ; Get compile flag
  12863.         or      a               ; Test compile to memory
  12864.         jr      z,l4621         ; Yeap
  12865.         ld      de,l0080
  12866.         call    VarAlloc                ; Allow space for loader
  12867. l4621:
  12868.         call    StLD.HL         ; Set LD HL,L79D7
  12869.         ld      a,(l7b9d)       ; Get options
  12870.         bit     _Copt,a         ; Test $C+
  12871.         ld      d,0
  12872.         jr      z,l462e         ; Nope
  12873.         dec     d
  12874. l462e:
  12875.         push    de              ; Save flag
  12876.         ld      a,_LD.BC
  12877.         call    writebyte_a_addriy              ; Set LD BC,FLAG
  12878.         push    iy              ; Save PC
  12879.         call    writeword_hl_addriy             ; Set dummy word
  12880.         ld      hl,l0364
  12881.         call    StCALL_         ; Set CALL INIPRG
  12882.         ld      a,_LD.HL
  12883.         call    writebyte_a_addriy              ; Set LD HL,1STFREE
  12884.         push    iy              ; Save PC
  12885.         call    writeword_hl_addriy             ; Set dummy word
  12886.         ld      a,_LD.DE
  12887.         call    writebyte_a_addriy              ; Set LD DE,LASTFREE
  12888.         push    iy              ; Save PC
  12889.         call    writeword_hl_addriy             ; Set dummy word
  12890.         ld      hl,(l790a)      ; Get end of code
  12891.         call    StLD.BC         ; Set LD BC,TOPRAM
  12892.         ld      a,(CmpTyp)      ; Get compile flag
  12893.         ld      h,a
  12894.         ld      l,_LD.A
  12895.         call    writeword_hl_addriy             ; Set LD A,FLAG
  12896.         ld      hl,l04d4
  12897.         call    StCALL_         ; Set CALL RANGCHK
  12898.         call    l469e           ; Do a block
  12899.         call    l52fc
  12900.         ld      a,(ix+0)
  12901.         cp      '.'             ; Verify closing .
  12902.         call    ErrNZ
  12903.         db      _DotExp
  12904.         ld      hl,l20d4
  12905.         call    StJP_           ; Set JP HALT
  12906.         pop     hl              ; Get back PC for LASTFREE
  12907.         ld      de,(DataBeg)    ; Get start of data
  12908.         call    storeback_de_to_addrhl          ; Store back
  12909.         pop     hl              ; Get back PC for 1STFREE
  12910.         call    storeback_iy_to_addrhl          ; Store back current PC
  12911.         pop     hl              ; Get back PC for FLAG
  12912.         pop     de              ; Get FLAG
  12913.         ld      a,(l7ba0)       ; Get end on break flag [option U+]
  12914.         ld      e,a
  12915.         jp      storeback_de_to_addrhl          ; Store it back
  12916. ;
  12917. ; Build dummy label
  12918. ;
  12919. l4692:
  12920.         ld      hl,(LabPtr)     ; Get label pointer
  12921.         push    hl              ; Save it
  12922.         call    GetLabel                ; Get label
  12923.         pop     hl
  12924.         ld      (LabPtr),hl     ; Restore label pointer
  12925.         ret
  12926. ;
  12927. ; Perform a block
  12928. ;
  12929. l469e:
  12930.         ld      a,(l7bc7)       ; Get depth for WITH
  12931.         push    af
  12932.         add     a,a             ; Double it
  12933.         ld      e,a
  12934.         ld      d,0
  12935.         call    VarAlloc                ; Allocate space for it
  12936.         push    hl
  12937.         call    StJP            ; Set JP
  12938.         push    iy              ; Save PC
  12939.         push    hl
  12940.         call    writeword_hl_addriy             ; Set dummy word
  12941. l46b3:
  12942.         call    FndTabStr               ; Find statement
  12943.         db      _Byte
  12944.         dw      l7584
  12945.         call    ErrNZ           ; Must be
  12946.         db      _BEGINexp
  12947.         ld      a,(hl)          ; Get type
  12948. l46be:
  12949.         cp      _Label          ; Test LABEL
  12950.         jr      nz,l46c7        ; Nope
  12951.         call    l488e           ; Process it
  12952.         jr      l46b3
  12953. l46c7:
  12954.         cp      _Const          ; Test CONST
  12955.         jr      nz,l46d0        ; Nope
  12956.         call    l48b7           ; Process it
  12957.         jr      l46be
  12958. l46d0:
  12959.         cp      _Type           ; Test TYPE
  12960.         jr      nz,l46d9        ; Nope
  12961.         call    l4aeb           ; Process it
  12962.         jr      l46be
  12963. l46d9:
  12964.         cp      _Var            ; Test VAR
  12965.         jr      nz,l46e6        ; Nope
  12966.         call    l4b2a           ; Process it
  12967.         ld      hl,(DataBeg)    ; Get start of data
  12968.         ex      (sp),hl
  12969.         jr      l46be
  12970. l46e6:
  12971.         cp      _Overly         ; Test OVERLAY
  12972.         jp      nz,l485e
  12973.         ld      a,(CmpTyp)      ; Get compile flag
  12974.         or      a
  12975.         call    ErrZ            ; Must not be compiled to memory
  12976.         db      _OvlDirErr
  12977.         ld      hl,FFCB+Fdrv
  12978.         ld      de,l7bb2
  12979.         ld      bc,Fname
  12980.         ldir                    ; Copy name of file
  12981.         ld      hl,l7b96        ; Point to OVERLAY number
  12982.         ld      a,(hl)          ; Get current number
  12983.         inc     (hl)            ; Advance it
  12984.         ex      de,hl           ; Get pointer to extension
  12985.         ld      (hl),'0'        ; Init extension
  12986.         inc     hl
  12987.         ld      b,'0'-1         ; Init tens
  12988. l4709:
  12989.         inc     b               ; Divide by ten
  12990.         sub     10
  12991.         jr      nc,l4709
  12992.         ld      (hl),b          ; Save tens
  12993.         inc     hl
  12994.         add     a,'9'+1         ; Calculate units
  12995.         ld      (hl),a          ; Save it
  12996.         ld      hl,l1c59
  12997.         call    StCALL_         ; Set CALL OVERLAY
  12998.         ld      hl,-1
  12999.         call    writeword_hl_addriy             ; Save word
  13000.         ld      hl,l7bb2        ; Point to name
  13001.         ld      b,Fname+Fext
  13002. l4724:
  13003.         ld      a,(hl)
  13004.         call    writebyte_a_addriy              ; Store name and extension
  13005.         inc     hl
  13006.         djnz    l4724
  13007.         ld      a,(CmpTyp)      ; Get compile flag
  13008.         dec     a               ; Test compiling to file
  13009.         jr      nz,l473b        ; Nope
  13010.         call    FixBack         ; Fix back level
  13011.         xor     a
  13012.         ld      (BackLevel),a   ; Set back fix level
  13013.         call    writerecord_TmpBuff             ; Write record
  13014. l473b:
  13015.         ld      hl,(RRN_off)    ; Get record base
  13016.         push    hl
  13017.         ld      hl,(CodePC)     ; Get code pointer
  13018.         push    hl
  13019.         ld      hl,(l7bb0)      ; Get length of overlay
  13020.         push    hl
  13021.         ld      (CodePC),iy     ; Set code pointer
  13022.         ld      hl,0
  13023.         ld      (l7bb0),hl      ; Clear length of overlay
  13024.         ld      hl,-FCBlen
  13025.         add     hl,sp           ; Let some space on stack for FCB
  13026.         ld      sp,hl
  13027.         ex      de,hl
  13028.         ld      hl,FFCB
  13029.         ld      bc,FCBlen
  13030.         ldir                    ; Unpack current FCB
  13031.         ld      a,(CmpTyp)      ; Get compile flag
  13032.         dec     a               ; Test compiling to file
  13033.         jr      nz,l478c        ; Nope
  13034.         ld      hl,l7bb2
  13035.         ld      de,FFCB+Fdrv
  13036.         ld      bc,Fname+Fext
  13037.         ldir                    ; Copy overlay FCB to .COM FCB
  13038.         ex      de,hl
  13039.         ld      b,FCBlen-Fdrv-Fname-Fext
  13040. l4773:
  13041.         ld      (hl),0          ; Clear remainder of FCB
  13042.         inc     hl
  13043.         djnz    l4773
  13044.         ld      de,FFCB
  13045.         push    de
  13046.         ld      c,_delete
  13047.         call    _BDOS           ; Delete file
  13048.         pop     de
  13049.         ld      c,_make
  13050.         call    _BDOS           ; Create new one
  13051.         inc     a
  13052.         call    ErrZ            ; Must be success
  13053.         db      _NoOvl
  13054. l478c:
  13055.         xor     a
  13056.         ld      (RRN_stat ),a   ; Clear file access
  13057.         ld      (RecPtr),a      ; Clear record pointer
  13058.         ld      hl,(DataBeg)    ; Get start of data
  13059.         ld      (l7bab),hl      ; Set for overlay
  13060. l4799:
  13061.         call    FndTabStr               ; Find PROCEDURE or FUNCTION
  13062.         db      1
  13063.         dw      l75a7
  13064.         call    ErrNZ           ; Must be either
  13065.         db      _SUBexp
  13066.         ld      a,(hl)          ; Get type
  13067.         push    iy
  13068.         ld      hl,(FFCB+_rrn)  ; Get current record
  13069.         ld      (RRN_off),hl    ; Set record base
  13070.         ld      hl,(DataBeg)    ; Get start of data
  13071.         push    hl
  13072.         ld      hl,(l7bab)      ; Get address of overlay data
  13073.         push    hl
  13074.         ld      e,-1
  13075.         call    l4b3a           ; Perform PROCEDURE/FUNCTION
  13076.         ld      b,h
  13077.         ld      c,l
  13078.         pop     de              ; Get back overlay data
  13079.         ld      hl,(DataBeg)    ; Get start of data
  13080.         or      a
  13081.         sbc     hl,de           ; Test min
  13082.         add     hl,de
  13083.         jr      c,l47c6
  13084.         ex      de,hl           ; Swap addresses
  13085. l47c6:
  13086.         ld      (l7bab),hl      ; Set address of overlay data
  13087.         pop     hl
  13088.         ld      (DataBeg),hl    ; Set start of data
  13089.         pop     de
  13090.         push    bc
  13091.         push    de
  13092.         ld      a,(CmpTyp)      ; Get compile flag
  13093.         dec     a               ; Test compiling to file
  13094.         call    z,FixBack               ; Yeap, fix back level
  13095.         xor     a
  13096.         ld      (BackLevel),a   ; Reset back fix level
  13097.         pop     de
  13098.         push    de
  13099. l47dd:
  13100.          ld     a,(CmpTyp)      ; Get compile flag
  13101.          dec    a               ; Test compiling to memory
  13102.          call z,flushunfinished ;nope
  13103.         push    iy              ; Copy code pointer
  13104.         pop     hl
  13105.         or      a
  13106.         sbc     hl,de           ; Get difference
  13107.         ld      a,l
  13108.         and     RecLng-1        ; Test record boundary
  13109.         jr      z,l47ee         ; Yeap
  13110.         xor     a
  13111.         call    writebyte_a_addriy              ; Fill remainder with zeroes
  13112.         jr      l47dd
  13113. l47ee:
  13114.         add     hl,hl           ; Calculate lenght in bytes
  13115.         ld      e,h
  13116.         ld      d,0
  13117.         rl      d
  13118.         ld      hl,(l7bb0)      ; Get length of overlay
  13119.         sbc     hl,de           ; Test max
  13120.         jr      nc,l47ff
  13121.         ld      (l7bb0),de      ; Set new length
  13122. l47ff:
  13123.         pop     iy              ; Get back PC
  13124.         pop     hl
  13125.         inc     hl
  13126.         ld      (hl),e          ; Save record
  13127.         inc     hl
  13128.         ld      (hl),d
  13129.         call    FindStr         ; Find more OVERLAY
  13130.         dw      l759f
  13131.         jr      z,l4799         ; Yeap
  13132.         ld      hl,(l7bab)      ; Get address of overlay data
  13133.         ld      (DataBeg),hl    ; Set start of data
  13134.         ld      a,(CmpTyp)      ; Get compile flag
  13135.         dec     a               ; Test compiling to file
  13136.         jr      nz,l4821        ; Nope
  13137.         ld      de,FFCB
  13138.         ld      c,_close
  13139.         call    _BDOS           ; Close file
  13140. l4821:
  13141.         ld      hl,0
  13142.         add     hl,sp           ; Copy stack
  13143.         ld      de,FFCB
  13144.         ld      bc,FCBlen
  13145.         ldir                    ; Get back original .COM FCB
  13146.         ld      sp,hl
  13147.         ld      de,(l7bb0)      ; Get length of overlay
  13148.         pop     hl
  13149.         ld      (l7bb0),hl      ; Set new length
  13150.         pop     hl
  13151.         ld      (CodePC),hl     ; Set code pointer
  13152.         pop     hl
  13153.         ld      (RRN_off),hl    ; Set record base
  13154.         xor     a
  13155.         ld      (RRN_stat ),a   ; Clear file access
  13156.         ld      hl,-1
  13157.         ld      (FFCB+_rrn),hl  ; Set highest record number
  13158.         push    iy
  13159.         pop     hl
  13160.         call    ChkChn          ; Check chaining
  13161. l484e:
  13162.         ld      b,RecLng
  13163. l4850:
  13164.         xor     a
  13165.         call    writebyte_a_addriy              ; Clear record
  13166.         djnz    l4850
  13167.         dec     de
  13168.         ld      a,d             ; Test all done
  13169.         or      e
  13170.         jr      nz,l484e
  13171.         jp      l46b3
  13172. l485e:
  13173.         cp      _Begin          ; Test BEGIN
  13174.         jr      z,l486a         ; Yeap
  13175.         ld      e,0
  13176.         call    l4b3a           ; Perform PROCEDURE/FUNCTION
  13177.         jp      l46b3
  13178. l486a:
  13179.         call    l4e8a           ; Process it
  13180.         pop     de
  13181.         pop     hl
  13182.         push    de
  13183.         push    iy              ; Copy PC
  13184.         pop     de
  13185.         dec     de              ; Fix it
  13186.         dec     de
  13187.         or      a
  13188.         sbc     hl,de           ; Calculate size
  13189.         add     hl,de
  13190.         jr      z,l4880
  13191.         call    storeback_iy_to_addrhl          ; Store back PC
  13192.         jr      l4884
  13193. l4880:
  13194.         dec     hl
  13195.         call    ChkChn          ; Check chaining
  13196. l4884:
  13197.         pop     de
  13198.         pop     hl
  13199.         ld      (l7bca),hl
  13200.         pop     af
  13201.         ld      (l7bc6),a
  13202.         ret
  13203. ;
  13204. ; Process LABEL
  13205. ;
  13206. l488e:
  13207.         ld      de,256*1+0
  13208.         call    puttolabel_d_e          ; Put to table
  13209.         ld      a,(ix+0)
  13210.         call    IsItValid               ; Test valid character
  13211.         call    SampLabel               ; Build label
  13212.         ld      a,(l7b94)       ; Get ???
  13213.         call    puttolabel              ; Put to label
  13214.         ld      b,3
  13215. l48a5:
  13216.         ld      a,-1
  13217.         call    puttolabel              ; Set end
  13218.         djnz    l48a5
  13219.         call    SetLabPtr               ; Set label pointer
  13220.         call    l6f13           ; Test ,
  13221.         jr      z,l488e         ; Yeap
  13222.         jp      l6f48           ; Verify ;
  13223. ;
  13224. ; Process CONST
  13225. ;
  13226. l48b7:
  13227.         ld      hl,(LabPtr)     ; Get label pointer
  13228.         push    hl
  13229.         ld      de,256*0+0
  13230.         call    puttolabel_d_e          ; Put to table
  13231.         call    GetLabel                ; Get label
  13232.         call    l6f23           ; Test =
  13233.         jr      nz,l4901        ; Nope, must be : then
  13234.         call    GetConst                ; Get constant
  13235.         ld      a,b             ; Get type
  13236.         call    puttolabel              ; Store into table
  13237.         ld      a,b             ; Get back type
  13238.         cp      _Real           ; Test real
  13239.         jr      nz,l48e3        ; Nope
  13240.         exx
  13241.         push    hl              ; Save reals
  13242.         push    de
  13243.         push    bc
  13244.         ld      b,3             ; Set word count
  13245. l48db:
  13246.         pop     de              ; Get part of real
  13247.         call    puttolabel_d_e          ; Put to table
  13248.         djnz    l48db
  13249.         jr      l48fa
  13250. l48e3:
  13251.         cp      _String         ; Test string
  13252.         jr      nz,l48f6        ; Nope, must be integer
  13253.         ld      hl,l7a57        ; Get buffer
  13254.         ld      a,c             ; Get length
  13255.         inc     c               ; Fix it
  13256. l48ec:
  13257.         call    puttolabel              ; Put to table
  13258.         ld      a,(hl)
  13259.         inc     hl
  13260.         dec     c
  13261.         jr      nz,l48ec
  13262.         jr      l48fa
  13263. l48f6:
  13264.         ex      de,hl           ; Get integer
  13265.         call    puttolabel_d_e          ; Put to table
  13266. l48fa:
  13267.         call    SetLabPtr               ; Set label pointer
  13268.         ld      d,2
  13269.         jr      l4928
  13270. l4901:
  13271.         call    l6f40           ; Verify :
  13272.         xor     a
  13273.         call    puttolabel              ; Store zero in table
  13274.         call    puttolabel_i_y          ; Store PC to table
  13275.         ld      hl,(LabPtr)     ; Get label pointer
  13276.         push    hl
  13277.         call    puttolabel_d_e          ; Put to table
  13278.         call    SetLabPtr               ; Set label pointer
  13279.         call    l4f9b           ; Get type
  13280.         pop     hl              ; Get back label pointer
  13281.         ld      de,(l7b5a)      ; Get type table
  13282.         ld      (hl),d          ; Store into
  13283.         dec     hl
  13284.         ld      (hl),e
  13285.         call    l6f76           ; Verify =
  13286.         call    l4937           ; Assign constant
  13287.         ld      d,4
  13288. l4928:
  13289.         pop     hl              ; Get back label pointer
  13290.         ld      (hl),d          ; Put into
  13291.         call    l6f48           ; Verify ;
  13292.         call    FndTabStr               ; Find statement
  13293.         db      1
  13294.         dw      l7584
  13295.         jr      nz,l48b7        ; Nope
  13296.         ld      a,(hl)          ; Get type
  13297.         ret
  13298. ;
  13299. ; Process presetted constant
  13300. ;
  13301. l4937:
  13302.         ld      a,(l7b5c)       ; Get type
  13303.         cp      _Ptr            ; Test valid
  13304.         jr      c,l4946         ; May not be a file
  13305.         cp      _String
  13306.         jr      nc,l4946
  13307.         call    ERROR
  13308.         db      _InvFilPtr
  13309. l4946:
  13310.         cp      _Array          ; Test ARRAY constant
  13311.         jr      nz,l49a1        ; Nope
  13312.         call    l6d2a           ; Save environment
  13313.         ld      hl,(l7b60)      ; Get hi set limit
  13314.         call    l5271           ; Load name
  13315.         ld      hl,(l7b6d)      ; Get last memory address
  13316.         ld      de,(l7b6b)
  13317.         or      a
  13318.         sbc     hl,de
  13319.         inc     hl
  13320.         push    hl
  13321.         ld      hl,(l7b5e)      ; Get lo set limit
  13322.         call    l5287           ; Get name
  13323.         pop     de
  13324.         ld      a,(l7b5c)       ; Get type
  13325.         cp      _Char           ; Test character
  13326.         jr      nz,l4978
  13327.         ld      a,d             ; Test byte
  13328.         or      a
  13329.         jr      nz,l4978        ; Nope
  13330.         call    l6f1b           ; Test (
  13331.         jr      nz,l498a        ; Nope
  13332.         jr      l497b
  13333. l4978:
  13334.         call    l6f66           ; Verify (
  13335. l497b:
  13336.         push    de
  13337.         call    l4937           ; Recursive assign constant
  13338.         pop     de
  13339.         dec     de
  13340.         ld      a,d
  13341.         or      e
  13342.         jr      z,l499a
  13343.         call    l6f5e           ; Verify ,
  13344.         jr      l497b
  13345. l498a:
  13346.         push    de
  13347.         call    _GetStrC                ; Get string constant
  13348.         pop     de
  13349.         ld      a,c             ; Get length
  13350.         cp      e
  13351.         call    ErrNZ           ; Verify valid length
  13352.         db      _StrConst
  13353.         call    StConst         ; Store string
  13354.         jr      l499d
  13355. l499a:
  13356.         call    l6f6e           ; Verify )
  13357. l499d:
  13358.         call    RestEnv1                ; Get back environment
  13359.         ret
  13360. l49a1:
  13361.         cp      _Record         ; Test RECORD constant
  13362.         jr      nz,l49fa        ; Nope
  13363.         call    l6d2a           ; Save environment
  13364.         call    l6f66           ; Verify (
  13365.         ld      a,(l7b5d)
  13366.         ld      c,a
  13367.         ld      hl,(l7b62)      ; Get length of type
  13368.         push    hl
  13369.         ld      hl,0
  13370. l49b6:
  13371.         push    bc
  13372.         push    hl
  13373.         ld      b,_Ptr
  13374.         call    FndLABEL                ; Get pointer label
  13375.         call    ErrNZ           ; Should be found
  13376.         db      _Undef
  13377.         call    l5276           ; Get values and name
  13378.         pop     de
  13379.         ld      hl,(l7b58)      ; Get value
  13380.         or      a
  13381.         sbc     hl,de
  13382.         add     hl,de
  13383.         call    ErrNZ           ; Verify valid size
  13384.         db      _InvSetOrder
  13385.         ld      de,(l7b62)      ; Get length of type
  13386.         add     hl,de
  13387.         push    hl
  13388.         call    l6f40           ; Verify :
  13389.         call    l4937           ; Assign constant recursively
  13390.         pop     hl
  13391.         pop     bc
  13392.         call    l6f0f           ; Test ;
  13393.         jr      z,l49b6         ; Yeap
  13394.         call    l6f6e           ; Verify )
  13395.         pop     de
  13396.         ex      de,hl
  13397.         or      a
  13398.         sbc     hl,de
  13399. l49eb:
  13400.         ld      a,h             ; Test zero
  13401.         or      l
  13402.         jr      z,l49f6         ; Yeap
  13403.         xor     a
  13404.         call    writebyte_a_addriy              ; Fill zeroes
  13405.         dec     hl
  13406.         jr      l49eb
  13407. l49f6:
  13408.         call    RestEnv1                ; Get back environment
  13409.         ret
  13410. l49fa:
  13411.         cp      _Set            ; Test SET constant
  13412.         jr      nz,l4a7a        ; Nope
  13413.         call    l6d2a           ; Save environment
  13414.         ld      hl,(l7b62)      ; Get length of type
  13415.         ld      (l7b6f),hl
  13416.         ld      hl,(l7b5e)      ; Get lo set limit
  13417.         call    l5287           ; Get name
  13418.         call    l6f30           ; Verify [
  13419.         ld      (l7ba9),ix      ; Save line pointer
  13420.         call    l0581           ; Initialize a set on stack
  13421.         ld      ix,(l7ba9)      ; Get back line pointer
  13422.         call    l6ef7           ; Test ]
  13423.         jr      z,l4a4b         ; Yeap
  13424. l4a20:
  13425.         call    l4aca
  13426.         push    hl
  13427.         call    FindStr         ; Find ..
  13428.         dw      l7580
  13429.         jr      nz,l4a37        ; Nope
  13430.         call    l4aca
  13431.         ld      (l7ba9),ix      ; Save source pointer
  13432.         call    l059b           ; Init a contiguous set value
  13433.         jr      l4a3f
  13434. l4a37:
  13435.         pop     hl
  13436.         ld      (l7ba9),ix      ; Save source pointer
  13437.         call    l0591           ; Init one set element
  13438. l4a3f:
  13439.         ld      ix,(l7ba9)      ; Get back source pointer
  13440.         call    l6f13           ; Test ,
  13441.         jr      z,l4a20         ; Yeap
  13442.         call    l6f38           ; Verify ]
  13443. l4a4b:
  13444.         ld      hl,l7a57
  13445.         ld      bc,set.len
  13446.         ld      (l7ba9),ix      ; Save source pointer
  13447.         call    l0612           ; Assign set variable
  13448.         ld      ix,(l7ba9)      ; Get back source pointer
  13449.         ld      hl,l7a57
  13450.         ld      a,(l7b5e)       ; Get lo set limit
  13451.         rra                     ; Divide by 8
  13452.         rra
  13453.         rra
  13454.         and     set.len-1       ; Get modulo
  13455.         ld      e,a
  13456.         ld      d,0
  13457.         add     hl,de           ; Build pointer
  13458.         ld      a,(l7b6f)       ; Get length
  13459.         ld      b,a
  13460. l4a6f:
  13461.         ld      a,(hl)          ; Get bytes
  13462.         call    writebyte_a_addriy              ; Store them
  13463.         inc     hl
  13464.         djnz    l4a6f
  13465.         call    RestEnv1                ; Get back environment
  13466.         ret
  13467. l4a7a:
  13468.         cp      _String         ; Test STRING constant
  13469.         jr      nz,l4a99        ; Nope
  13470.         call    _GetStrC                ; Get string constant
  13471.         ld      a,(l7b62)       ; Get length of string
  13472.         dec     a
  13473.         sub     c
  13474.         ld      b,a
  13475.         jr      nc,l4a8d
  13476.         add     a,c
  13477.         ld      c,a             ; Set length
  13478.         ld      b,0
  13479. l4a8d:
  13480.         call    StLen           ; Put string
  13481.         inc     b
  13482. l4a91:
  13483.         dec     b
  13484.         ret     z
  13485.         xor     a
  13486.         call    writebyte_a_addriy              ; Fill zeroes
  13487.         jr      l4a91
  13488. l4a99:
  13489.         cp      _Real           ; Test REAL constant
  13490.         jr      nz,l4abc        ; Nope
  13491.         call    _GetConst               ; Get constant
  13492.         ld      a,b             ; Get type
  13493.         cp      _Real           ; Test real
  13494.         jr      z,l4aaf         ; Yeap
  13495.         cp      _Integ          ; Test integer
  13496.         call    ErrNZ           ; Should be
  13497.         db      _IntRealCexp
  13498.         call    l1008           ; Convert to real
  13499.         exx
  13500. l4aaf:
  13501.         exx
  13502.         push    bc
  13503.         push    de
  13504.         push    hl
  13505.         ld      b,Real.Len/2    ; Set word count
  13506. l4ab5:
  13507.         pop     hl
  13508.         call    writeword_hl_addriy             ; Save real number
  13509.         djnz    l4ab5
  13510.         ret
  13511. l4abc:
  13512.         call    l4aca
  13513.         ld      a,(l7b62)       ; Get length of type
  13514.         dec     a
  13515.         ld      a,l
  13516.         jp      z,writebyte_a_addriy            ; Set byte
  13517.         jp      writeword_hl_addriy             ; Or set word
  13518. ;
  13519. ;
  13520. ;
  13521. l4aca:
  13522.         call    _GetConst               ; Get constant
  13523.         ld      a,(l7b5c)       ; Get type
  13524.         cp      b               ; Verify same types
  13525.         call    ErrNZ
  13526.         db      _InvType
  13527.         ld      de,(l7b5e)      ; Get lo set limit
  13528.         call    l728d           ; Compare
  13529.         jr      c,l4ae7         ; Out of range
  13530.         ld      de,(l7b60)      ; Get hi set limit
  13531.         call    l728d           ; Compare
  13532.         ret     c
  13533.         ret     z
  13534. l4ae7:
  13535.         call    ERROR
  13536.         db      _ConstRange
  13537. ;
  13538. ; Process TYPE
  13539. ;
  13540. l4aeb:
  13541.         ld      hl,(LabPtr)     ; Get label pointer
  13542.         push    hl
  13543. l4aef:
  13544.         ld      hl,(LabPtr)     ; Get label pointer
  13545.         push    hl
  13546.         ld      de,0
  13547.         call    puttolabel_d_e          ; Put to table
  13548.         call    GetLabel                ; Get label
  13549.         ld      hl,(LabPtr)     ; Get label pointer
  13550.         push    hl
  13551.         call    puttolabel_d_e          ; Put to table
  13552.         call    SetLabPtr               ; Set label pointer
  13553.         call    l6f76           ; Verify =
  13554.         call    l4f9b           ; Get type
  13555.         pop     hl
  13556.         ld      de,(l7b5a)      ; Get type table
  13557.         ld      (hl),d          ; Store into
  13558.         dec     hl
  13559.         ld      (hl),e
  13560.         pop     hl
  13561.         ld      (hl),3
  13562.         call    l6f48           ; Verify ;
  13563.         call    FndTabStr               ; Find statement
  13564.         db      _Byte
  13565.         dw      l7584
  13566.         jr      nz,l4aef        ; Nope
  13567.         ld      a,(hl)          ; Fetch type
  13568.         pop     hl
  13569.         push    af
  13570.         call    l5295
  13571.         pop     af
  13572.         ret
  13573. ;
  13574. ; Process VAR
  13575. ;
  13576. l4b2a:
  13577.         call    l4f35
  13578.         call    l6f48           ; Verify ;
  13579.         call    FndTabStr               ; Find statement
  13580.         db      _Byte
  13581.         dw      l7584
  13582.         jr      nz,l4b2a        ; Nope
  13583.         ld      a,(hl)          ; Fetch type
  13584.         ret
  13585. ;
  13586. ; Perform PROCEDURE/FUNCTION
  13587. ;
  13588. ; Accu holds PROCEDURE or FUNCTION
  13589. ; Reg E holds overlay flag (-1)
  13590. ;
  13591. l4b3a:
  13592.         ld      b,a
  13593.         ld      c,0
  13594.         sub     _Proc           ; Get type
  13595.         ld      (l7b97),a       ; 0 is PROCEDURE
  13596.         ld      a,e             ; Get overlay
  13597.         ld      (l7b99),a       ; 0 is normal
  13598.         ld      a,(l7b9d)       ; Get options
  13599.         ld      (l7b9e),a       ; Set local options
  13600.         push    bc
  13601.         call    l6ddb
  13602.         jp      z,l4c61
  13603.         pop     de
  13604.         call    puttolabel_d_e          ; Put to table
  13605.         call    GetLabel                ; Get label
  13606.         ld      hl,(CurLab)     ; Get current label pointer
  13607.         push    hl
  13608.         ld      hl,(PrevLabPtr) ; Get previous label pointer
  13609.         ld      (CurLab),hl
  13610.         ld      hl,(LabPtr)     ; Get label pointer
  13611.         push    hl
  13612.         call    puttolabel_d_e          ; Put to table
  13613.         call    puttolabel_d_e          ; Multiple
  13614.         call    puttolabel_d_e
  13615.         call    puttolabel_d_e
  13616.         ld      de,(RRN_off)    ; Get record base
  13617.         call    puttolabel_d_e          ; Put to table
  13618.         ld      de,0
  13619.         call    puttolabel_d_e          ; Put to table
  13620.         call    l6f1b           ; Test (
  13621.         ld      b,0             ; Clear parameter count
  13622.         jr      nz,l4bda        ; Nope
  13623. l4b88:
  13624.         push    bc
  13625.         ld      hl,(LabPtr)     ; Get label pointer
  13626.         push    hl
  13627.         call    puttolabel_d_e          ; Put to table
  13628.         call    puttolabel_d_e          ; Twice
  13629.         call    FindStr         ; Find VAR
  13630.         dw      l7595
  13631.         ld      bc,0
  13632.         jr      nz,l4b9e        ; Nope
  13633.         dec     c               ; Indicate VAR
  13634. l4b9e:
  13635.         push    bc
  13636.         call    GetLabel                ; Get label
  13637.         pop     bc
  13638.         inc     b               ; Count parameters
  13639.         call    l6f13           ; Test ,
  13640.         jr      z,l4b9e         ; Yeap
  13641.         push    bc
  13642.         call    l6f0b           ; Test :
  13643.         jr      nz,l4bb8        ; Nope
  13644.         ld      a,c
  13645.         ld      (l7b8f),a       ; Save state
  13646.         call    l4f18           ; Get variable
  13647.         jr      l4bc3
  13648. l4bb8:
  13649.         inc     c               ; Verify not VAR
  13650.         call    ErrNZ
  13651.         db      _SemiExp
  13652.         ld      hl,l750b+7
  13653.         ld      (l7b5a),hl      ; Init type table
  13654. l4bc3:
  13655.         pop     bc
  13656.         pop     hl
  13657.         ld      (hl),b
  13658.         dec     hl
  13659.         ld      (hl),c
  13660.         ld      de,(l7b5a)      ; Get type table
  13661.         dec     hl
  13662.         ld      (hl),d          ; Store into
  13663.         dec     hl
  13664.         ld      (hl),e
  13665.         pop     bc
  13666.         inc     b
  13667.         call    l6f0f           ; Test ;
  13668.         jr      z,l4b88         ; Yeap
  13669.         call    l6f6e           ; Verify )
  13670. l4bda:
  13671.         push    bc
  13672.         ld      a,(l7b97)
  13673.         or      a               ; Test PROCEDURE
  13674.         jr      z,l4c07         ; Yeap
  13675.         call    l6f40           ; Verify :
  13676.         xor     a
  13677.         ld      (l7b8f),a
  13678.         call    l4f18           ; Get variable
  13679.         ld      a,(l7b5c)       ; Get type
  13680.         cp      _String         ; Test range
  13681.         jr      nc,l4bf8
  13682.         cp      _Ptr            ; Should be pointer
  13683.         call    ErrNZ
  13684.         db      _InvResult
  13685. l4bf8:
  13686.         pop     bc
  13687.         pop     hl
  13688.         push    hl
  13689.         push    bc
  13690.         ld      de,-4
  13691.         add     hl,de           ; Fix pointer
  13692.         ld      de,(l7b5a)      ; Get type table
  13693.         ld      (hl),d          ; Store into
  13694.         dec     hl
  13695.         ld      (hl),e
  13696. l4c07:
  13697.         pop     bc
  13698.         pop     de
  13699.         pop     hl
  13700.         ld      (CurLab),hl     ; Restore current label pointer
  13701.         push    de
  13702.         push    bc
  13703.         call    SetLabPtr               ; Set label pointer
  13704.         call    l6f48           ; Verify ;
  13705.         ld      a,(l7b99)
  13706.         or      a               ; Test overlay
  13707.         jr      nz,l4c44        ; Yeap
  13708.         call    FindStr         ; Find FORWARD
  13709.         dw      l7533
  13710.         jr      nz,l4c2c        ; Nope
  13711.         push    iy              ; Copy PC
  13712.         pop     de
  13713.         call    StJP_           ; Set JP <addr>
  13714.         ld      a,-1
  13715.         jr      l4c38
  13716. l4c2c:
  13717.         call    FindStr         ; Find EXTERNAL
  13718.         dw      l753a
  13719.         jr      nz,l4c44        ; Nope
  13720.         call    _GetIntC                ; Get integer constant
  13721.         ex      de,hl
  13722.         xor     a
  13723. l4c38:
  13724.         pop     bc
  13725.         pop     hl
  13726.         ld      (hl),a          ; Store values
  13727.         dec     hl
  13728.         ld      (hl),b
  13729.         dec     hl
  13730.         ld      (hl),d          ; Set address
  13731.         dec     hl
  13732.         ld      (hl),e
  13733.         jp      l6f48           ; Verify ;
  13734. l4c44:
  13735.         pop     bc
  13736.         pop     hl
  13737.         push    hl
  13738.         ld      (hl),0          ; Set values
  13739.         dec     hl
  13740.         ld      (hl),b
  13741.         dec     hl
  13742.         push    iy              ; Copy PC
  13743.         pop     de
  13744.         ld      a,(l7b99)
  13745.         or      a               ; Test overlay
  13746.         jr      z,l4c5b         ; Nope
  13747.         ex      de,hl
  13748.         ld      bc,-16
  13749.         add     hl,bc           ; Fix value
  13750.         ex      de,hl
  13751. l4c5b:
  13752.         ld      (hl),d          ; Save address
  13753.         dec     hl
  13754.         ld      (hl),e
  13755.         pop     hl
  13756.         jr      l4c76
  13757. l4c61:
  13758.         ld      a,(hl)
  13759.         or      a
  13760.         call    ErrZ            ; Verify label not found
  13761.         db      _DoubleLab
  13762.         ld      a,(l7b99)
  13763.         or      a               ; Test overlay (0 is not)
  13764.         call    ErrNZ           ; Verify not FORWARD overlay
  13765.         db      _OvlFORW
  13766.         call    SetLine         ; Set new pointer
  13767.         pop     de
  13768.         call    l6f48           ; Verify ;
  13769. l4c76:
  13770.         ex      de,hl
  13771.         ld      a,(l7b9d)       ; Get option
  13772.         ld      hl,(DataBeg)    ; Get start of data
  13773.         bit     _Aopt,a         ; Test $A+ - absolute code for recursion
  13774.         jr      z,l4c84         ; Yeap
  13775.         ld      hl,0
  13776. l4c84:
  13777.         ld      (l7b83),hl
  13778.         ld      hl,(CurLab)     ; Get current label pointer
  13779.         push    hl
  13780.         ld      hl,(LabPtr)     ; Get label pointer
  13781.         ld      (CurLab),hl     ; Into current
  13782.         push    hl
  13783.         ex      de,hl
  13784.         ld      a,(hl)
  13785.         ld      (hl),0
  13786.         dec     hl
  13787.         ld      b,(hl)
  13788.         dec     hl
  13789.         ld      d,(hl)
  13790.         dec     hl
  13791.         ld      e,(hl)
  13792.         dec     hl
  13793.         or      a
  13794.         jr      z,l4ca7
  13795.         push    hl
  13796.         ex      de,hl
  13797.         inc     hl
  13798.         call    storeback_iy_to_addrhl          ; Store back PC
  13799.         pop     hl
  13800. l4ca7:
  13801.         ld      a,(l7b97)
  13802.         or      a               ; Test PROCEDURE
  13803.         jr      z,l4cd2         ; Yeap
  13804.         ld      d,(hl)
  13805.         dec     hl
  13806.         ld      e,(hl)
  13807.         dec     hl
  13808.         push    hl
  13809.         ex      de,hl
  13810.         call    l5287           ; Get name
  13811.         ld      a,(l7b5c)       ; Get type
  13812.         ld      (l7b87),a
  13813.         ld      hl,(l7b62)      ; Get length of type
  13814.         ld      a,l
  13815.         ld      (l7b88),a       ; save lo
  13816.         ex      de,hl
  13817.         call    VarAlloc                ; Allocate space
  13818.         ld      (l7b89),hl
  13819.         ex      de,hl
  13820.         pop     hl
  13821.         ld      (hl),d
  13822.         dec     hl
  13823.         ld      (hl),e
  13824.         dec     hl
  13825.         jr      l4cd6
  13826. l4cd2:
  13827.         ld      de,-4
  13828.         add     hl,de
  13829. l4cd6:
  13830.         ld      de,-4
  13831.         add     hl,de
  13832.         push    hl
  13833.         ld      c,0
  13834.         ld      a,b
  13835.         or      a
  13836.         jr      z,l4d2b
  13837. l4ce1:
  13838.         ld      a,(hl)
  13839.         add     a,c
  13840.         ld      c,a
  13841.         push    bc
  13842.         ld      b,(hl)
  13843.         dec     hl
  13844.         ld      a,(hl)
  13845.         ld      (l7b8f),a
  13846.         dec     hl
  13847.         ld      d,(hl)          ; Get type table
  13848.         dec     hl
  13849.         ld      e,(hl)
  13850.         dec     hl
  13851.         push    hl
  13852.         ex      de,hl
  13853.         ld      (l7b5a),hl      ; Save type table
  13854.         call    l5287           ; Get name
  13855.         ld      hl,(LabPtr)     ; Get label pointer
  13856.         ex      (sp),hl
  13857.         push    bc
  13858. l4cfd:
  13859.         push    bc
  13860.         ld      de,4*256+0
  13861.         call    puttolabel_d_e          ; Put to table
  13862. l4d04:
  13863.         ld      a,(hl)
  13864.         call    puttolabel              ; Store into table
  13865.         bit     _MB,(hl)        ; Test end of table
  13866.         dec     hl
  13867.         jr      z,l4d04         ; Nope
  13868.         push    hl
  13869.         call    puttolabel              ; Store last byte into table
  13870.         call    puttolabel_d_e          ; Put to table
  13871.         call    puttolabel_d_e
  13872.         call    SetLabPtr               ; Set label pointer
  13873.         pop     hl
  13874.         pop     bc
  13875.         djnz    l4cfd
  13876.         pop     bc
  13877.         ex      (sp),hl
  13878.         xor     a
  13879.         ld      (l7b90),a
  13880.         call    l4f52
  13881.         pop     hl
  13882.         pop     bc
  13883.         djnz    l4ce1
  13884. l4d2b:
  13885.         ld      b,c
  13886.         push    bc
  13887.         ld      hl,(LabPtr)     ; Get label pointer
  13888.         push    hl
  13889.         ld      hl,(l7b83)
  13890.         push    hl
  13891.         ld      hl,(l7b89)
  13892.         push    hl
  13893.         ld      a,(l7b87)
  13894.         push    af
  13895.         ld      a,(l7b88)
  13896.         push    af
  13897.         ld      a,(l7b97)       ; Get PROCEDURE/FUNCTION flag
  13898.         push    af              ; Save it
  13899.         ld      hl,l7b94        ; Point to ???
  13900.         inc     (hl)
  13901.         call    l469e           ; Perform a block
  13902.         pop     af
  13903.         ld      (l7b97),a       ; Reset flag
  13904.         pop     af
  13905.         ld      (l7b88),a
  13906.         pop     af
  13907.         ld      (l7b87),a
  13908.         pop     hl
  13909.         ld      (l7b89),hl
  13910.         pop     hl
  13911.         ld      (l7b83),hl
  13912.         ld      (l7b85),de
  13913.         ld      a,h
  13914.         or      l
  13915.         jr      z,l4d79
  13916.         sbc     hl,de
  13917.         jr      z,l4d79
  13918.         call    StLD.BC         ; Set LD BC,val16
  13919.         ex      de,hl
  13920.         call    StLD.HL         ; Set LD HL,val16
  13921.         ld      hl,l0508        ; Set recursion routine
  13922.         call    StCALL_         ; Set CALL RECUR
  13923. l4d79:
  13924.         pop     hl
  13925.         pop     bc
  13926.         inc     b
  13927.         dec     b
  13928.         jp      z,l4df3
  13929.         call    StImm           ; Set POP IY
  13930.         db      a_L1
  13931. s_I1:
  13932.         POP     IY
  13933. a_L1    equ     $-s_I1
  13934. l4d86:
  13935.         push    bc
  13936.         inc     hl
  13937.         ld      e,(hl)
  13938.         inc     hl
  13939.         ld      d,(hl)
  13940.         add     hl,de
  13941.         push    hl
  13942.         dec     hl
  13943.         dec     hl
  13944. l4d8f:
  13945.         bit     _MB,(hl)        ; Test end of string
  13946.         dec     hl
  13947.         jr      z,l4d8f         ; Nope
  13948.         call    l5276           ; Get values and name
  13949.         ld      a,(Envir1)
  13950.         or      a
  13951.         jr      nz,l4dd4
  13952.         ld      a,(l7b5c)       ; Get type
  13953.         cp      _Set
  13954.         jr      c,l4dbd
  13955.         jr      z,l4de6
  13956.         cp      _Ptr
  13957.         jr      z,l4de3
  13958.         cp      _String
  13959.         jr      c,l4dbd
  13960.         jr      z,l4de6
  13961.         cp      _Integ
  13962.         jr      nc,l4de3
  13963.         call    StImm           ; Set POP sequence
  13964.         db      a_L2
  13965. s_I2:
  13966.         POP     HL
  13967.         POP     DE
  13968.         POP     BC
  13969. a_L2    equ     $-s_I2
  13970.         jr      l4de6
  13971. l4dbd:
  13972.         call    StPOP           ; Set POP HL
  13973.         ld      hl,(l7b58)      ; Get value
  13974.         call    StLD.DE         ; Set LD DE,val16
  13975.         ld      hl,(l7b62)      ; Get length of type
  13976.         call    StLD.BC         ; Set LD BC,val16
  13977.         call    StImm           ; Set LDIR
  13978.         db      a_L3
  13979. s_I3:
  13980.         LDIR
  13981. a_L3    equ     $-s_I3
  13982.         jr      l4de9
  13983. l4dd4:
  13984.         xor     a
  13985.         ld      (Envir1),a
  13986.         ld      a,_Ptr
  13987.         ld      (l7b5c),a       ; Set POINTER
  13988.         ld      hl,2
  13989.         ld      (l7b62),hl      ; Set length of pointer type
  13990. l4de3:
  13991.         call    StPOP           ; Set POP HL
  13992. l4de6:
  13993.         call    l661b
  13994. l4de9:
  13995.         pop     hl
  13996.         pop     bc
  13997.         djnz    l4d86
  13998.         call    StImm           ; Set PUSH IY
  13999.         db      a_L4
  14000. s_I4:
  14001.         PUSH    IY
  14002. a_L4    equ     $-s_I4
  14003. l4df3:
  14004.         call    l52fc
  14005.         ld      hl,l7b94        ; Point to ???
  14006.         dec     (hl)
  14007.         ld      a,(l7b97)
  14008.         or      a               ; Test PROCEDURE
  14009.         jr      z,l4e46         ; Yeap
  14010.         ld      hl,(l7b89)
  14011.         ld      a,(l7b87)
  14012.         cp      _String
  14013.         jr      nz,l4e24
  14014.         ld      b,a
  14015.         call    StImm           ; Set POP IY
  14016.         db      a_L5
  14017. s_I5:
  14018.         POP     IY
  14019. a_L5    equ     $-s_I5
  14020.         ld      a,_LD.HL
  14021.         call    StCode          ; Set LD HL,val16
  14022.         ld      hl,l053a
  14023.         call    StCALL_         ; move string to stack
  14024.         call    StImm
  14025.         db      a_L6
  14026. s_I6:
  14027.         PUSH    IY
  14028. a_L6    equ     $-s_I6
  14029.         jr      l4e46
  14030. l4e24:
  14031.         cp      _Real
  14032.         jr      nz,l4e35
  14033.         ld      a,_LD.HL
  14034.         call    StCode          ; Set LD HL,val16
  14035.         ld      hl,l052c
  14036.         call    StCALL_         ; Set load real
  14037.         jr      l4e46
  14038. l4e35:
  14039.         ld      a,_LD_a_HL
  14040.         call    StCode          ; Set LD HL,(adr16)
  14041.         ld      a,(l7b88)
  14042.         dec     a
  14043.         jr      nz,l4e46
  14044.         call    StImm           ; Set LD H,0
  14045.         db      a_L7
  14046. s_I7:
  14047.         LD      H,0
  14048. a_L7    equ     $-s_I7
  14049. l4e46:
  14050.         ld      hl,(l7b83)
  14051.         ld      a,h
  14052.         or      l
  14053.         jr      z,l4e74
  14054.         ld      de,(l7b85)
  14055.         sbc     hl,de
  14056.         jr      z,l4e74
  14057.         ld      a,(l7b97)
  14058.         or      a               ; Test PROCEDURE
  14059.         jr      z,l4e65         ; Yeap
  14060.         ld      a,(l7b87)
  14061.         cp      _String
  14062.         ld      a,_EXX
  14063.         call    nz,writebyte_a_addriy   ; Set EXX
  14064. l4e65:
  14065.         call    StLD.BC         ; Set LD BC,val16
  14066.         ex      de,hl
  14067.         call    StLD.DE         ; Set LD DE,val16
  14068.         ld      hl,l0522
  14069.         call    StJP_           ; Set end of recursive routine
  14070.         jr      l4e79
  14071. l4e74:
  14072.         call    StImm           ; Set RET
  14073.         db      a_L8
  14074. s_I8:
  14075.         RET
  14076. a_L8    equ     $-s_I8
  14077. l4e79:
  14078.         call    l6f48           ; Verify ;
  14079.         pop     de
  14080.         pop     hl
  14081.         ld      (LabPtr),hl     ; Set label pointers
  14082.         ld      (PrevLabPtr),hl
  14083.         pop     hl
  14084.         ld      (CurLab),hl     ; Restore current label pointer
  14085.         ex      de,hl
  14086.         ret
  14087. ;
  14088. ; Process BEGIN
  14089. ;
  14090. l4e8a:
  14091.         ld      hl,(LabPtr)     ; Get label pointer
  14092. l4e8d:
  14093.         ld      de,(CurLab)     ; Get current label pointer
  14094.         or      a
  14095.         sbc     hl,de
  14096.         add     hl,de
  14097.         ret     z               ; End on level 0
  14098.         inc     hl
  14099.         ld      e,(hl)
  14100.         inc     hl
  14101.         ld      d,(hl)
  14102.         add     hl,de
  14103.         ld      a,(hl)
  14104.         cp      6 ;_TxtF???
  14105.         jr      z,l4ea4
  14106.         cp      5 ;_RecF???
  14107.         jr      nz,l4e8d
  14108. l4ea4:
  14109.         push    hl
  14110.         dec     hl
  14111.         dec     hl
  14112. l4ea7:
  14113.         bit     _MB,(hl)        ; Find end of string
  14114.         dec     hl
  14115.         jr      z,l4ea7
  14116.         ld      a,(hl)          ; Get type
  14117.         or      a
  14118.         call    ErrNZ           ; Maybe undefined FORWARD
  14119.         db      _UndefFORW
  14120.         pop     hl
  14121.         jr      l4e8d
  14122. ;
  14123. ;
  14124. ;
  14125. l4eb5:
  14126.         ld      hl,(LabPtr)     ; Get label pointer
  14127.         push    hl
  14128.         ld      b,0
  14129. l4ebb:
  14130.         push    bc
  14131.         ld      d,_Ptr  ; Set type
  14132.         ld      a,(l7b91)       ; Get ???
  14133.         ld      e,a
  14134.         call    puttolabel_d_e          ; Put to table
  14135.         call    GetLabel                ; Get label
  14136.         call    puttolabel              ; Store into table
  14137.         call    puttolabel_d_e          ; Put to table
  14138.         call    puttolabel_d_e          ; Twice
  14139.         call    SetLabPtr               ; Set label pointer
  14140.         pop     bc
  14141.         inc     b
  14142.         call    l6f13           ; Test ,
  14143.         jr      z,l4ebb         ; Yeap
  14144.         pop     hl
  14145.         ret
  14146. ;
  14147. ;
  14148. ;
  14149. l4edd:
  14150.         ld      hl,(LabPtr)     ; Get label pointer
  14151.         push    hl
  14152.         call    l4f9b           ; Get type
  14153.         pop     hl
  14154.         call    l5295
  14155.         call    FindStr         ; Test ABSOLUTE
  14156.         dw      l7562
  14157.         ld      a,0
  14158.         jr      nz,l4f14        ; Nope
  14159.         ld      a,(l7b91)       ; Get ???
  14160.         or      a
  14161.         call    ErrNZ
  14162.         db      _InvalABS
  14163.         ld      bc,256*_Ptr+0
  14164.         call    FndLABEL                ; Find label
  14165.         jr      nz,l4f0c        ; Nope
  14166.         ld      a,(hl)
  14167.         ld      (l7b8f),a
  14168.         dec     hl
  14169.         ld      d,(hl)
  14170.         dec     hl
  14171.         ld      e,(hl)
  14172.         ex      de,hl
  14173.         jr      l4f0f
  14174. l4f0c:
  14175.         call    _GetIntC                ; Get integer constant
  14176. l4f0f:
  14177.         ld      (l7b7f),hl      ; Store value
  14178.         ld      a,-1
  14179. l4f14:
  14180.         ld      (l7b90),a
  14181.         ret
  14182. ;
  14183. ; Process variable on PROCEDURE and FUNCTION
  14184. ;
  14185. l4f18:
  14186.         call    l4fc8           ; Get simple type
  14187.         call    ErrNZ           ; Verify ok
  14188.         db      _TypeExp
  14189.         xor     a
  14190.         ld      (l7b90),a
  14191.         ld      a,(l7b8f)
  14192.         or      a
  14193.         ret     nz
  14194.         ld      a,(l7b5c)       ; Get type
  14195.         cp      _RecF
  14196.         ret     c
  14197.         cp      _String
  14198.         ret     nc
  14199.         call    ERROR           ; Files must be VAR
  14200.         db      _VarFile
  14201. ;
  14202. ;
  14203. ;
  14204. l4f35:
  14205.         call    l4eb5
  14206.         push    hl
  14207.         push    bc
  14208.         call    l6f40           ; Verify :
  14209.         xor     a
  14210.         ld      (l7b8f),a
  14211.         call    l4edd
  14212.         pop     bc
  14213.         ld      a,(l7b90)
  14214.         or      a
  14215.         jr      z,l4f51
  14216.         ld      a,b
  14217.         dec     a
  14218.         call    ErrNZ           ; Invalid ABSOLUTE
  14219.         db      _InvalABS
  14220. l4f51:
  14221.         pop     hl
  14222. l4f52:
  14223.         push    bc
  14224.         push    hl
  14225.         ld      a,(l7b8f)
  14226.         ld      hl,2
  14227.         or      a
  14228.         jr      nz,l4f60
  14229.         ld      hl,(l7b62)      ; Get length of type
  14230. l4f60:
  14231.         ex      de,hl
  14232.         ld      a,(l7b91)       ; Get ???
  14233.         or      a
  14234.         jr      nz,l4f72
  14235.         ld      a,(l7b90)
  14236.         or      a
  14237.         jr      nz,l4f72
  14238.         call    VarAlloc                ; Allocate space
  14239.         jr      l4f7b
  14240. l4f72:
  14241.         ld      hl,(l7b7f)
  14242.         push    hl
  14243.         add     hl,de
  14244.         ld      (l7b7f),hl
  14245.         pop     hl
  14246. l4f7b:
  14247.         ex      de,hl
  14248.         pop     hl
  14249.         dec     hl
  14250. l4f7e:
  14251.         dec     hl
  14252.         bit     _MB,(hl)
  14253.         jr      z,l4f7e
  14254.         dec     hl
  14255.         ld      a,(l7b8f)
  14256.         ld      (hl),a
  14257.         dec     hl
  14258.         ld      (hl),d
  14259.         dec     hl
  14260.         ld      (hl),e
  14261.         dec     hl
  14262.         ld      de,(l7b5a)      ; Get type table
  14263.         ld      (hl),d          ; Store into
  14264.         dec     hl
  14265.         ld      (hl),e
  14266.         dec     hl
  14267.         dec     hl
  14268.         dec     hl
  14269.         pop     bc
  14270.         djnz    l4f52
  14271.         ret
  14272. ;
  14273. ; Get a TYPE
  14274. ;
  14275. l4f9b:
  14276.         call    l4fc8           ; Test simple type
  14277.         ret     z
  14278.         call    FindStr         ; Skip possible PACKED
  14279.         dw      l7542
  14280.         call    l4fdb           ; Check ARRAY
  14281.         ret     z
  14282.         call    l5039           ; Check RECORD
  14283.         ret     z
  14284.         call    l5106           ; Check SET
  14285.         ret     z
  14286.         call    l5140           ; Check ^
  14287.         ret     z
  14288.         call    l516b           ; Check FILE
  14289.         ret     z
  14290.         call    l51a5           ; Check STRING
  14291.         ret     z
  14292.         call    l51c5           ; Test SCALAR ()
  14293.         ret     z
  14294.         call    l5210           ; Test RANGE ..
  14295.         ret     z
  14296.         call    ERROR           ; Type declaration expected
  14297.         db      _TypeExp
  14298. ;
  14299. ; Get SIMPLE TYPE
  14300. ; EXIT  Zero set if found
  14301. ;
  14302. l4fc8:
  14303.         ld      bc,256*3+0
  14304.         call    FndLABEL                ; Get from table
  14305.         ret     nz              ; Not found
  14306.         ld      d,(hl)          ; Fetch type table
  14307.         dec     hl
  14308.         ld      e,(hl)
  14309.         ex      de,hl
  14310.         ld      (l7b5a),hl      ; Save type
  14311.         call    l5287           ; Get name
  14312.         xor     a               ; Set success
  14313.         ret
  14314. ;
  14315. ; Look for ARRAY
  14316. ;
  14317. l4fdb:
  14318.         call    FindStr         ; Test ARRAY
  14319.         dw      l7548
  14320.         ret     nz              ; Nope
  14321.         call    l6f30           ; Verify [
  14322.         ld      b,0
  14323. l4fe6:
  14324.         push    bc
  14325.         call    l523b
  14326.         pop     bc
  14327.         ld      hl,(l7b5a)      ; Get type table
  14328.         push    hl
  14329.         ld      hl,(l7b60)      ; Get hi limit
  14330.         ld      de,(l7b5e)      ; Get lo limit
  14331.         or      a
  14332.         sbc     hl,de
  14333.         inc     hl
  14334.         ld      a,h
  14335.         or      l
  14336.         call    ErrZ            ; Verify not same
  14337.         db      _MemOvfl
  14338.         push    hl
  14339.         inc     b
  14340.         call    l6f13           ; Test ,
  14341.         jr      z,l4fe6         ; Yeap
  14342.         push    bc
  14343.         call    l6f38           ; Verify ]
  14344.         call    l6f88
  14345.         call    l4f9b           ; Get type
  14346.         pop     bc
  14347. l5012:
  14348.         ld      hl,(l7b5a)      ; Get type table
  14349.         ld      (l7b5e),hl      ; Set as lo limit
  14350.         ld      hl,(l7b62)      ; Get length of type
  14351.         pop     de
  14352.         push    bc
  14353.         call    l729a           ; Multiply numbers
  14354.         call    ErrCY           ; Check compiler overflow
  14355.         db      _MemOvfl
  14356.         pop     bc
  14357.         ld      (l7b62),hl      ; Set length of type
  14358.         pop     hl
  14359.         ld      (l7b60),hl      ; Set hi limit
  14360.         ld      a,_Array
  14361.         ld      (l7b5c),a       ; Set ARRAY
  14362.         push    bc
  14363.         call    l5254           ; Put to table
  14364.         pop     bc
  14365.         djnz    l5012
  14366.         ret
  14367. ;
  14368. ; Look for RECORD
  14369. ;
  14370. l5039:
  14371.         call    FindStr         ; Test RECORD
  14372.         dw      l7554
  14373.         ret     nz              ; Nope
  14374.         ld      a,(l7b9a)
  14375.         push    af
  14376.         ld      a,(l7b91)       ; Get ???
  14377.         push    af
  14378.         ld      hl,l7b92        ; Point to ???
  14379.         inc     (hl)
  14380.         ld      a,(hl)
  14381.         ld      (l7b91),a       ; Set ???
  14382.         ld      hl,(l7b7f)
  14383.         push    hl
  14384.         ld      hl,(l7b81)
  14385.         push    hl
  14386.         ld      hl,l0000
  14387.         ld      (l7b7f),hl
  14388.         ld      (l7b81),hl
  14389.         xor     a
  14390.         ld      (l7b9a),a
  14391.         call    l508b
  14392.         ld      hl,(l7b81)
  14393.         ld      (l7b62),hl      ; Set length of type
  14394.         pop     hl
  14395.         ld      (l7b81),hl
  14396.         pop     hl
  14397.         ld      (l7b7f),hl
  14398.         ld      a,(l7b91)       ; Get ???
  14399.         ld      (l7b5d),a
  14400.         pop     af
  14401.         ld      (l7b91),a       ; Set ???
  14402.         pop     af
  14403.         ld      (l7b9a),a
  14404.         ld      a,_Record
  14405.         ld      (l7b5c),a       ; Set RECORD
  14406.         jp      l5254
  14407. ;
  14408. ;
  14409. ;
  14410. l508b:
  14411.         call    l50f9
  14412.         ret     z
  14413.         call    FindStr         ; Test CASE
  14414.         dw      l75da
  14415.         jr      z,l50b0         ; Yeap
  14416.         call    l4f35
  14417.         ld      hl,(l7b7f)
  14418.         ld      de,(l7b81)
  14419.         or      a
  14420.         sbc     hl,de
  14421.         jr      c,l50a9
  14422.         add     hl,de
  14423.         ld      (l7b81),hl
  14424. l50a9:
  14425.         call    l6f0f           ; Test ;
  14426.         jr      z,l508b         ; Yeap
  14427.         jr      l50e8
  14428. l50b0:
  14429.         call    l4fc8
  14430.         call    nz,l4f35
  14431.         call    l6f88
  14432. l50b9:
  14433.         call    l50f9
  14434.         ret     z
  14435.         ld      hl,(l7b7f)
  14436.         push    hl
  14437. l50c1:
  14438.         call    _GetConst               ; Get constant
  14439.         call    l6f13           ; Test ,
  14440.         jr      z,l50c1         ; Yeap
  14441.         call    l6f40           ; Verify :
  14442.         call    l6f66           ; Verify (
  14443.         ld      a,(l7b9a)
  14444.         push    af
  14445.         ld      a,0ffh
  14446.         ld      (l7b9a),a
  14447.         call    l508b
  14448.         pop     af
  14449.         ld      (l7b9a),a
  14450.         pop     hl
  14451.         ld      (l7b7f),hl
  14452.         call    l6f0f           ; Test ;
  14453.         jr      z,l50b9         ; Yeap
  14454. l50e8:
  14455.         ld      a,(l7b9a)
  14456.         or      a
  14457.         jp      nz,l6f6e        ; Verify )
  14458.         call    FindStr         ; Find END
  14459.         dw      l7530
  14460.         ret     z               ; Yeap
  14461.         call    ERROR
  14462.         db      _End
  14463. l50f9:
  14464.         ld      a,(l7b9a)
  14465.         or      a
  14466.         jp      nz,l6f1f
  14467.         call    FindStr         ; Find END
  14468.         dw      l7530
  14469.         ret
  14470. ;
  14471. ; Check SET
  14472. ;
  14473. l5106:
  14474.         call    FindStr         ; Test SET
  14475.         dw      l7551
  14476.         ret     nz              ; Nope
  14477.         call    l6f88
  14478.         call    l523b
  14479.         ld      hl,(l7b60)      ; Get hi set limit
  14480.         ld      de,(l7b5e)      ; Get lo set limit
  14481.         ld      a,h
  14482.         or      d
  14483.         call    ErrNZ
  14484.         db      _IllSetRange
  14485.         srl     l
  14486.         srl     l
  14487.         srl     l
  14488.         srl     e
  14489.         srl     e
  14490.         srl     e
  14491.         ld      a,l
  14492.         inc     a
  14493.         sub     e
  14494.         ld      l,a
  14495.         ld      (l7b62),hl      ; Set length of type
  14496.         ld      hl,(l7b5a)      ; Get type table
  14497.         ld      (l7b5e),hl      ; Set lo set limit
  14498.         ld      a,_Set
  14499.         ld      (l7b5c),a       ; Set SET
  14500.         jp      l5254
  14501. ;
  14502. ; Check ^
  14503. ;
  14504. l5140:
  14505.         call    l6f27
  14506.         ret     nz
  14507.         ld      de,l0000
  14508.         call    puttolabel_d_e          ; Put to table
  14509.         ld      hl,(LabPtr)     ; Get label pointer
  14510.         push    hl
  14511.         call    l6dba
  14512.         call    SetLabPtr               ; Set label pointer
  14513.         pop     hl
  14514.         ld      (l7b5e),hl      ; Set lo set limit
  14515.         ld      a,_Ptr
  14516.         ld      (l7b5c),a       ; Set POINTER
  14517.         ld      a,0ffh
  14518.         ld      (l7b5d),a
  14519.         ld      hl,l0002
  14520.         ld      (l7b62),hl      ; Set length of type
  14521.         jp      l5254
  14522. ;
  14523. ; Check FILE
  14524. ;
  14525. l516b:
  14526.         call    FindStr         ; Find FILE
  14527.         dw      l754d
  14528.         ret     nz              ; Nope
  14529.         call    FindStr         ; Find OF
  14530.         dw      l7560
  14531.         jr      nz,l5197        ; Nope
  14532.         call    l4f9b           ; Get type
  14533.         ld      a,(l7b5c)       ; Get type
  14534.         cp      _RecF
  14535.         jr      c,l518a
  14536.         cp      _String
  14537.         jr      nc,l518a
  14538.         call    ERROR
  14539.         db      _FileF
  14540. l518a:
  14541.         ld      hl,(l7b5a)      ; Get type table
  14542.         ld      (l7b5e),hl      ; Set lo set limit
  14543.         ld      a,_RecF
  14544.         ld      hl,l00b0
  14545.         jr      l519c
  14546. l5197:
  14547.         ld      a,_UntF
  14548.         ld      hl,l0030
  14549. l519c:
  14550.         ld      (l7b5c),a       ; Set type
  14551.         ld      (l7b62),hl      ; Set length of type
  14552.         jp      l5254
  14553. ;
  14554. ; Check STRING
  14555. ;
  14556. l51a5:
  14557.         call    FindStr         ; Find STRING
  14558.         dw      l755a
  14559.         ret     nz              ; Nope
  14560.         call    l6f30           ; Verify [
  14561.         call    _GetIntC                ; Get integer constant
  14562.         inc     h
  14563.         dec     h
  14564.         call    ErrNZ
  14565.         db      _IllStrgLen
  14566.         inc     l
  14567.         dec     l
  14568.         call    ErrZ
  14569.         db      _IllStrgLen
  14570.         call    l6f38           ; Verify ]
  14571.         inc     hl
  14572.         ld      a,_String
  14573.         jr      l519c
  14574. ;
  14575. ; Test SCALAR ()
  14576. ;
  14577. l51c5:
  14578.         call    l6f1b           ; Test (
  14579.         ret     nz              ; Nope
  14580.         ld      hl,lffff
  14581. l51cc:
  14582.         push    hl
  14583.         ld      de,2*256+0 ;l0200
  14584.         call    puttolabel_d_e          ; Put to table
  14585.         call    GetLabel                ; Get label
  14586.         ld      a,(curtype_l7b93)       ; Get type
  14587.         call    puttolabel
  14588.         pop     de
  14589.         inc     de
  14590.         push    de
  14591.         call    puttolabel_d_e          ; Put to table
  14592.         call    SetLabPtr               ; Set label pointer
  14593.         pop     hl
  14594.         call    l6f13           ; Test ,
  14595.         jr      z,l51cc         ; Yeap
  14596.         call    l6f6e           ; Verify )
  14597.         push    hl
  14598.         ld      hl,curtype_l7b93        ; Point to type
  14599.         ld      a,(hl)
  14600.         inc     (hl)
  14601.         pop     hl
  14602.         ld      de,l0000
  14603. l51f8:
  14604.         ld      (l7b5c),a       ; Set type
  14605.         ld      (l7b5e),de      ; Set lo set limit
  14606.         ld      (l7b60),hl      ; Set hi set limit
  14607.         ld      a,d
  14608.         or      h
  14609.         ld      hl,l0001
  14610.         jr      z,l520a
  14611.         inc     hl
  14612. l520a:
  14613.         ld      (l7b62),hl      ; Set length of type
  14614.         jp      l5254
  14615. ;
  14616. ; Test RANGE ..
  14617. ;
  14618. l5210:
  14619.         call    GetConst                ; Get constant
  14620.         ret     nz
  14621.         ld      a,b
  14622.         push    af
  14623.         cp      0ah ;_Integ
  14624.         call    ErrCY
  14625.         db      _IllSkalar
  14626.         push    hl
  14627.         call    FindStr         ; Find ..
  14628.         dw      l7580
  14629.         call    ErrNZ
  14630.         db      _TwoDots
  14631.         call    _GetConst               ; Get constant
  14632.         pop     de
  14633.         pop     af
  14634.         push    af
  14635.         cp      b
  14636.         call    ErrNZ
  14637.         db      _InvType
  14638.         call    l728d           ; Compare
  14639.         call    ErrCY           ; Verify upper > lower
  14640.         db      _IllLimit
  14641.         pop     af
  14642.         jr      l51f8
  14643. ;
  14644. ;
  14645. ;
  14646. l523b:
  14647.         call    l5210
  14648.         ret     z
  14649.         call    l51c5
  14650.         ret     z
  14651.         call    l4fc8
  14652.         call    ErrNZ
  14653.         db      _SimTyp
  14654.         ld      a,(l7b5c)       ; Get type
  14655.         cp      _Integ
  14656.         ret     nc
  14657.         call    ERROR
  14658.         db      _SimTyp
  14659. l5254:
  14660.         ld      de,8*256+0 ;l0800
  14661.         call    puttolabel_d_e          ; Put to table
  14662.         ld      hl,(LabPtr)     ; Get label pointer
  14663.         ld      (l7b5a),hl      ; Save into type table
  14664.         ld      hl,l7b5c        ; Point to type
  14665.         ld      b,8
  14666. l5265:
  14667.         ld      a,(hl)
  14668.         call    puttolabel
  14669.         inc     hl
  14670.         djnz    l5265
  14671.         call    SetLabPtr               ; Set label pointer
  14672.         xor     a
  14673.         ret
  14674. ;
  14675. ;
  14676. ;
  14677. l5271:
  14678.         ld      de,l7b69
  14679.         jr      l528a
  14680. ;
  14681. ; Get values and name
  14682. ;
  14683. l5276:
  14684.         ld      a,(hl)
  14685.         dec     hl
  14686.         ld      (Envir1),a
  14687.         ld      d,(hl)
  14688.         dec     hl
  14689.         ld      e,(hl)
  14690.         dec     hl
  14691.         ld      (l7b58),de      ; Set value
  14692.         ld      d,(hl)
  14693.         dec     hl
  14694.         ld      e,(hl)
  14695.         ex      de,hl
  14696. ;
  14697. ; Get name
  14698. ;
  14699. l5287:
  14700.         ld      de,l7b5c        ; Point to type
  14701. l528a:
  14702.         push    bc
  14703.         ld      b,8
  14704. l528d:
  14705.         ld      a,(hl)
  14706.         ld      (de),a
  14707.         dec     hl
  14708.         inc     de
  14709.         djnz    l528d
  14710.         pop     bc
  14711.         ret
  14712. ;
  14713. ;
  14714. ;
  14715. l5295:
  14716.         ld      (l7b79),hl
  14717.         ld      hl,(LabPtr)     ; Get label pointer
  14718. l529b:
  14719.         ld      bc,(l7b79)
  14720.         or      a
  14721.         sbc     hl,bc
  14722.         add     hl,bc
  14723.         ret     z
  14724.         inc     hl
  14725.         ld      c,(hl)
  14726.         inc     hl
  14727.         ld      b,(hl)
  14728.         add     hl,bc
  14729.         ld      a,(hl)
  14730.         cp      8 ;???
  14731.         jr      nz,l529b
  14732.         ld      (hl),0
  14733.         push    hl
  14734.         dec     hl
  14735.         dec     hl
  14736.         ld      a,(hl)
  14737.         cp      4 ;???
  14738.         jr      nz,l52f8
  14739.         dec     hl
  14740.         ld      a,(hl)
  14741.         or      a
  14742.         jr      z,l52f8
  14743.         ld      (hl),0
  14744.         dec     hl
  14745.         push    hl
  14746.         ld      e,(hl)
  14747.         dec     hl
  14748.         ld      d,(hl)
  14749.         ld      hl,(LabPtr)     ; Get label pointer
  14750. l52c7:
  14751.         ld      bc,(l7b77)      ; Get top of available memory
  14752.         or      a
  14753.         sbc     hl,bc
  14754.         add     hl,bc
  14755.         call    ErrZ
  14756.         db      _InkPointer
  14757.         inc     hl
  14758.         ld      c,(hl)
  14759.         inc     hl
  14760.         ld      b,(hl)
  14761.         add     hl,bc
  14762.         ld      a,(hl)
  14763.         cp      3 ;???
  14764.         jr      nz,l52c7
  14765.         push    hl
  14766.         push    de
  14767.         dec     hl
  14768.         dec     hl
  14769. l52e1:
  14770.         ld      a,(de)
  14771.         cp      (hl)
  14772.         jr      z,l52e9
  14773.         pop     de
  14774.         pop     hl
  14775.         jr      l52c7
  14776. l52e9:
  14777.         bit     7,(hl)
  14778.         dec     hl
  14779.         dec     de
  14780.         jr      z,l52e1
  14781.         pop     bc
  14782.         pop     bc
  14783.         ld      b,(hl)
  14784.         dec     hl
  14785.         ld      c,(hl)
  14786.         pop     hl
  14787.         ld      (hl),c
  14788.         dec     hl
  14789.         ld      (hl),b
  14790. l52f8:
  14791.         pop     hl
  14792.         jp      l529b
  14793. ;
  14794. ;
  14795. ;
  14796. l52fc:
  14797.         xor     a
  14798.         ld      (l7b95),a
  14799.         ld      (l7bc9),a
  14800.         call    l5377
  14801.         ld      (l7ba4),iy
  14802.         call    StJP_
  14803.         ld      hl,(LabPtr)     ; Get label pointer
  14804. l5310:
  14805.         ld      de,(PrevLabPtr) ; Get previous label pointer
  14806.         or      a
  14807.         sbc     hl,de
  14808.         add     hl,de
  14809.         jr      nc,l5363
  14810.         inc     hl
  14811.         ld      c,(hl)
  14812.         inc     hl
  14813.         ld      b,(hl)
  14814.         inc     hl
  14815.         ld      a,(hl)
  14816.         inc     hl
  14817.         ld      e,(hl)
  14818.         inc     hl
  14819.         ld      d,(hl)
  14820.         push    hl
  14821.         push    bc
  14822.         ld      b,a
  14823.         ld      a,d
  14824.         or      e
  14825.         jr      z,l533a
  14826.         ex      de,hl
  14827.         dec     hl
  14828.         ld      a,(hl)
  14829.         ld      c,a
  14830.         inc     a
  14831.         call    ErrZ
  14832.         db      _UnkLabel
  14833.         dec     hl
  14834.         ld      d,(hl)
  14835.         dec     hl
  14836.         ld      e,(hl)
  14837.         jr      l5340
  14838. l533a:
  14839.         ld      de,(l7ba4)
  14840.         ld      c,0
  14841. l5340:
  14842.         pop     hl
  14843.         ld      a,b
  14844.         sub     c
  14845.         jr      nz,l534a
  14846.         call    storeback_de_to_addrhl
  14847.         jr      l5360
  14848. l534a:
  14849.         call    ErrCY
  14850.         db      _IllGOTO
  14851.         push    de
  14852.         push    af
  14853.         call    storeback_iy_to_addrhl          ; Store back PC
  14854.         pop     af
  14855.         ld      b,a
  14856. l5355:
  14857.         call    StPOP           ; Set POP HL
  14858.         djnz    l5355
  14859.         ld      a,_JP
  14860.         pop     hl
  14861.         call    StCode
  14862. l5360:
  14863.         pop     hl
  14864.         jr      l5310
  14865. l5363:
  14866.         ld      hl,(l7ba4)
  14867.         inc     hl
  14868.         push    iy
  14869.         pop     de
  14870.         dec     de
  14871.         dec     de
  14872.         or      a
  14873.         sbc     hl,de
  14874.         add     hl,de
  14875.         jp      nz,storeback_iy_to_addrhl       ; Store back PC
  14876.         dec     hl
  14877.         jp      ChkChn          ; Check chaining
  14878. ;
  14879. ; Statement BEGIN
  14880. ;
  14881. l5377:
  14882.         call    l5385           ; Process a statement
  14883.         call    FindStr         ; Find END
  14884.         dw      l7530
  14885.         ret     z
  14886.         call    l6f50
  14887.         jr      l5377
  14888. ;
  14889. ; Process a statement
  14890. ;
  14891. l5385:
  14892.         ld      a,0ffh
  14893.         ld      (l7b98),a
  14894.         ld      a,(l7b9d)       ; Get options
  14895.         ld      (l7b9e),a       ; Set local options
  14896.         bit     _Uopt,a         ; Test $U+
  14897.         jr      z,l539c         ; Nope
  14898.         ld      a,RST
  14899.         ld      (l7ba0),a       ; Set end on break flag [option U+]
  14900.         call    writebyte_a_addriy              ; Insert RST
  14901. l539c:
  14902.         call    FndTabStr               ; Find statement
  14903.         db      2
  14904.         dw      l75bb
  14905.         jr      z,l53cb         ; Yeap
  14906.         call    l67b2
  14907.         jp      z,l57ea
  14908.         ld      bc,256*5+0
  14909.         call    FndLABEL
  14910.         jp      z,l573d
  14911.         ld      bc,256*1+0
  14912.         call    FndLABEL
  14913.         jr      z,l53d0
  14914.         ld      bc,256*6+0
  14915.         call    FndLABEL
  14916.         jp      z,l591f
  14917.         call    FndTabStr               ; Find procedure
  14918.         db      2
  14919.         dw      l7638
  14920.         ret     nz              ; Nope
  14921. l53cb:
  14922.         ld      e,(hl)          ; Fetch address
  14923.         inc     hl
  14924.         ld      d,(hl)
  14925.         ex      de,hl
  14926.         jp      (hl)            ; Go
  14927. l53d0:
  14928.         call    l6f40           ; Verify :
  14929.         ld      a,(l7b94)       ; Get ???
  14930.         cp      (hl)
  14931.         call    ErrNZ
  14932.         db      _IllLabel
  14933.         dec     hl
  14934.         ld      a,(hl)
  14935.         inc     a
  14936.         call    ErrNZ
  14937.         db      _DoubleLab
  14938.         ld      a,(l7b95)
  14939.         ld      (hl),a
  14940.         push    iy
  14941.         pop     de
  14942.         dec     hl
  14943.         ld      (hl),d
  14944.         dec     hl
  14945.         ld      (hl),e
  14946.         jr      l5385
  14947. ;
  14948. ; Statement IF
  14949. ;
  14950. l53ef:
  14951.         call    l5eb0
  14952.         call    StImm           ; Set BIT 0,L ! JP Z,addr
  14953.         db      a_L9
  14954. s_I9:
  14955.         BIT     _LB,L
  14956.         db      _JPZ
  14957. a_L9    equ     $-s_I9
  14958.         push    iy
  14959.         call    writeword_hl_addriy
  14960.         call    FindStr         ; Find THEN
  14961.         dw      l756a
  14962.         call    ErrNZ
  14963.         db      _StrIdx
  14964.         call    l5385           ; Process a statement
  14965.         call    FindStr         ; Find ELSE
  14966.         dw      l756e
  14967.         jr      nz,l5420        ; Nope
  14968.         call    StJP            ; Set JP
  14969.         pop     hl
  14970.         push    iy
  14971.         call    writeword_hl_addriy
  14972.         call    storeback_iy_to_addrhl          ; Store back PC
  14973.         call    l5385           ; Process a statement
  14974. l5420:
  14975.         pop     hl
  14976.         jp      storeback_iy_to_addrhl          ; Store back PC
  14977. ;
  14978. ; Statement WHILE
  14979. ;
  14980. l5424:
  14981.         push    iy
  14982.         call    l5eb0
  14983.         call    FindStr         ; Find DO
  14984.         dw      l7572
  14985.         call    ErrNZ
  14986.         db      _NoDO
  14987.         call    StImm           ; Set BIT 0,L ! JP Z,addr
  14988.         db      a_L10
  14989. s_I10:
  14990.         BIT     _LB,L
  14991.         db      _JPZ
  14992. a_L10   equ     $-s_I10
  14993.         push    iy
  14994.         call    writeword_hl_addriy
  14995.         call    l5385           ; Process a statement
  14996.         pop     de
  14997.         pop     hl
  14998.         ld      a,_JP
  14999.         call    StCode
  15000.         ex      de,hl
  15001.         jp      storeback_iy_to_addrhl          ; Store back PC
  15002. ;
  15003. ; Statement REPEAT
  15004. ;
  15005. l544c:
  15006.         push    iy
  15007. l544e:
  15008.         call    l5385           ; Process a statement
  15009.         call    FindStr         ; Find UNTIL
  15010.         dw      l7574
  15011.         jr      z,l545d         ; Yeap
  15012.         call    l6f50
  15013.         jr      l544e
  15014. l545d:
  15015.         call    l5eb0
  15016.         call    StImm
  15017.         db      a_L11
  15018. s_I11:
  15019.         BIT     _LB,L
  15020.         db      _JPZ
  15021. a_L11   equ     $-s_I11
  15022.         pop     hl
  15023.         jp      writeword_hl_addriy
  15024. ;
  15025. ; Statement FOR
  15026. ;
  15027. l546b:
  15028.         ld      bc,256*4+0
  15029.         call    FndLABEL
  15030.         call    ErrNZ
  15031.         db      _Undef
  15032.         call    l5276
  15033.         ld      a,(Envir1)
  15034.         or      a
  15035.         jr      nz,l5485
  15036.         ld      a,(l7b5c)       ; Get type
  15037.         cp      _Integ
  15038.         jr      nc,l5489
  15039. l5485:
  15040.         call    ERROR
  15041.         db      _SimTyp
  15042. l5489:
  15043.         call    l6d2a           ; Save environment
  15044.         ld      a,(l7b5c)       ; Get type
  15045.         push    af
  15046.         call    l6f7e
  15047.         call    l5ee8
  15048.         call    StPUSH          ; Set PUSH HL
  15049.         pop     af
  15050.         push    af
  15051.         cp      b
  15052.         call    ErrNZ
  15053.         db      _InvType
  15054.         call    FndTabStr               ; Find TO or DOWNTO
  15055.         db      1
  15056.         dw      l75f5
  15057.         call    ErrNZ
  15058.         db      _NoDOWN_TO
  15059.         ld      e,(hl)          ; Get instruction
  15060.         push    de
  15061.         call    l5ee8
  15062.         pop     de
  15063.         pop     af
  15064.         push    de
  15065.         cp      b
  15066.         call    ErrNZ
  15067.         db      _InvType
  15068.         call    FindStr         ; Find DO
  15069.         dw      l7572
  15070.         call    ErrNZ
  15071.         db      _NoDO
  15072.         call    StImm           ; Set POP DE
  15073.         db      a_L12
  15074. s_I12:
  15075.         POP     DE
  15076. a_L12   equ     $-s_I12
  15077.         pop     de
  15078.         call    l6d63
  15079.         push    de
  15080.         ld      a,e
  15081.         ld      hl,l0666        ; Set up FOR .. TO loop
  15082.         cp      '#'
  15083.         jr      z,l54d5
  15084.         ld      hl,l0676        ; Set up FOR .. DOWNTO loop
  15085. l54d5:
  15086.         call    StCALL_         ; Set CALL <loop>
  15087.         push    iy
  15088.          ;jr $
  15089.         call    StImm           ; Set code sequence
  15090.         db      a_L13
  15091. s_I13:
  15092.         LD      A,D
  15093.         OR      E
  15094.         JP      Z,$-$ ;for future patching???
  15095.         PUSH    DE
  15096. a_L13   equ     $-s_I13
  15097.         call    l661b
  15098.         ld      hl,l7b95
  15099.         inc     (hl)
  15100.         call    l5385           ; Process a statement
  15101.         ld      hl,l7b95
  15102.         dec     (hl)
  15103.         pop     hl
  15104.         pop     de
  15105.         call    RestEnv1                ; Get back environment
  15106.         push    hl
  15107.         ld      hl,(l7b58)      ; Get value
  15108.         ld      a,_LD_a_HL
  15109.         call    StCode
  15110.         ld      a,(l7b62)       ; Get length of type
  15111.         dec     a
  15112.         jr      nz,l550c
  15113.         call    StImm           ; Set LD H,0
  15114.         db      a_L14
  15115. s_I14:
  15116.         LD      H,0
  15117. a_L14   equ     $-s_I14
  15118. l550c:
  15119.         ld      a,e             ; Get byte
  15120.         call    writebyte_a_addriy              ; Store it
  15121.         call    StImm           ; Set code sequence
  15122.         db      a_L15
  15123. s_I15:
  15124.         POP     DE
  15125.         DEC     DE
  15126.         db      _JP
  15127. a_L15   equ     $-s_I15
  15128.         pop     hl
  15129.         call    writeword_hl_addriy
  15130.         inc     hl
  15131.         inc     hl
  15132.         inc     hl
  15133.         jp      storeback_iy_to_addrhl          ; Store back PC
  15134. ;
  15135. ; Statement CASE
  15136. ;
  15137. l5521:
  15138.         call    l5ebb
  15139.         ld      (l7b9c),a
  15140.         xor     a
  15141.         ld      (l7b9b),a
  15142.         call    l6f88
  15143.         ld      b,0
  15144.         push    bc
  15145. l5531:
  15146.         ld      b,1
  15147. l5533:
  15148.         push    bc
  15149.         ld      hl,l7b9b
  15150.         bit     7,(hl)
  15151.         jr      z,l5549
  15152.         call    StImm           ; Set ADD HL,DE
  15153.         db      a_L16
  15154. s_I16:
  15155.         ADD     HL,DE
  15156. a_L16   equ     $-s_I16
  15157.         bit     4,(hl)
  15158.         jr      z,l5549
  15159.         call    StImm           ; Set ADD HL,BC
  15160.         db      a_L17
  15161. s_I17:
  15162.         ADD     HL,BC
  15163. a_L17   equ     $-s_I17
  15164. l5549:
  15165.         call    _GetConst               ; Get constant
  15166.         ld      a,(l7b9c)
  15167.         cp      b
  15168.         call    ErrNZ
  15169.         db      _IllCASE
  15170.         call    StLD.DE         ; Set LD DE,val16
  15171.         push    hl
  15172.         call    FindStr         ; Find ..
  15173.         dw      l7580
  15174.         pop     hl
  15175.         jr      nz,l5582        ; Nope
  15176.         push    hl
  15177.         call    _GetConst               ; Get constant
  15178.         ld      a,(l7b9c)
  15179.         cp      b
  15180.         call    ErrNZ
  15181.         db      _IllCASE
  15182.         pop     de
  15183.         or      a
  15184.         sbc     hl,de
  15185.         inc     hl
  15186.         call    StLD.BC
  15187.         call    StImm           ; Set sequence
  15188.         db      a_L18
  15189. s_I18:
  15190.         OR      A
  15191.         SBC     HL,DE
  15192.         OR      A
  15193.         SBC     HL,BC
  15194. a_L18   equ     $-s_I18
  15195.         ld      a,0dah
  15196.         jr      l558b
  15197. l5582:
  15198.         call    StImm           ; Set sequence
  15199.         db      a_L19
  15200. s_I19:
  15201.         OR      A
  15202.         SBC     HL,DE
  15203. a_L19   equ     $-s_I19
  15204.         ld      a,0cah
  15205. l558b:
  15206.         ld      (l7b9b),a
  15207.         call    l6f0b           ; Test :
  15208.         pop     bc
  15209.         jr      z,l55a5
  15210.         ld      a,(l7b9b)       ; Get byte
  15211.         call    writebyte_a_addriy              ; Store it
  15212.         push    iy
  15213.         call    writeword_hl_addriy
  15214.         call    l6f5e           ; Verify ,
  15215.         inc     b
  15216.         jr      l5533
  15217. l55a5:
  15218.         push    iy
  15219.         pop     de
  15220.         inc     de
  15221.         inc     de
  15222.         inc     de
  15223. l55ab:
  15224.         dec     b
  15225.         jr      z,l55b4
  15226.         pop     hl
  15227.         call    storeback_de_to_addrhl
  15228.         jr      l55ab
  15229. l55b4:
  15230.         ld      a,(l7b9b)       ; Get byte
  15231.         res     3,a             ; Fix it
  15232.         call    writebyte_a_addriy              ; Store
  15233.         pop     bc
  15234.         push    iy
  15235.         inc     b
  15236.         push    bc
  15237.         call    writeword_hl_addriy
  15238.         ld      a,(l7b9b)
  15239.         push    af
  15240.         ld      a,(l7b9c)
  15241.         push    af
  15242.         call    l5385           ; Process a statement
  15243.         pop     af
  15244.         ld      (l7b9c),a
  15245.         pop     af
  15246.         ld      (l7b9b),a
  15247.         call    l6f0f           ; Test ;
  15248.         ld      e,1
  15249.         jr      z,l55df         ; Yeap
  15250.         dec     e
  15251. l55df:
  15252.         push    de
  15253.         call    FindStr         ; Find END
  15254.         dw      l7530
  15255.         pop     de
  15256.         jr      z,l561e
  15257.         call    StJP            ; Set JP
  15258.         pop     bc
  15259.         pop     hl
  15260.         push    iy
  15261.         push    bc
  15262.         push    de
  15263.         call    writeword_hl_addriy
  15264.         call    storeback_iy_to_addrhl          ; Store back PC
  15265.         call    FindStr         ; Find ELSE
  15266.         dw      l756e
  15267.         pop     de
  15268.         jr      z,l560f         ; Yeap
  15269.         dec     e
  15270.         jp      z,l5531
  15271.         ld      a,(l7b98)
  15272.         or      a
  15273.         call    ErrZ
  15274.         db      _End
  15275.         call    ERROR
  15276.         db      _Undef
  15277. l560f:
  15278.         call    l5385           ; Process a statement
  15279.         call    FindStr         ; Find END
  15280.         dw      l7530
  15281.         jr      z,l561e         ; Yeap
  15282.         call    l6f50
  15283.         jr      l560f
  15284. l561e:
  15285.         pop     bc
  15286. l561f:
  15287.         pop     hl
  15288.         call    storeback_iy_to_addrhl          ; Store back PC
  15289.         djnz    l561f
  15290.         ret
  15291. ;
  15292. ; Statement GOTO
  15293. ;
  15294. l5626:
  15295.         ld      bc,256*1+0
  15296.         call    FndLABEL
  15297.         call    ErrNZ
  15298.         db      _UnkLabel
  15299.         ld      a,(l7b94)
  15300.         cp      (hl)
  15301.         call    ErrNZ
  15302.         db      _IllLabel
  15303.         ex      de,hl
  15304. l5639:
  15305.         call    puttolabel_d_e          ; Put to table
  15306.         ld      a,(l7b95)
  15307.         call    puttolabel
  15308.         call    StJP            ; Set JP
  15309.         push    iy
  15310.         pop     de
  15311.         call    puttolabel_d_e          ; Put to table
  15312.         jp      writeword_hl_addriy
  15313. ;
  15314. ; Statement WITH
  15315. ;
  15316. l564e:
  15317.         ld      a,(l7bc9)
  15318.         push    af
  15319. l5652:
  15320.         ld      a,(l7bc6)
  15321.         ld      hl,l7bc9
  15322.         cp      (hl)
  15323.         call    ErrZ
  15324.         db      _TooManyWITH
  15325.         call    l677f
  15326.         ld      a,(l7b5c)       ; Get type
  15327.         cp      _Record
  15328.         call    ErrNZ
  15329.         db      _RecVarExp
  15330.         ld      hl,l7bc9
  15331.         ld      e,(hl)
  15332.         ld      d,0
  15333.         inc     (hl)
  15334.         ld      hl,l7bcc
  15335.         add     hl,de
  15336.         ld      a,(l7b5d)
  15337.         ld      (hl),a
  15338.         ld      hl,(l7bca)
  15339.         add     hl,de
  15340.         add     hl,de
  15341.         ld      a,_LDHL_a
  15342.         call    StCode
  15343.         call    l6f13           ; Test ,
  15344.         jr      z,l5652         ; Yeap
  15345.         call    FindStr         ; Find DO
  15346.         dw      l7572
  15347.         call    ErrNZ
  15348.         db      _NoDO
  15349.         call    l5385           ; Process a statement
  15350.         pop     af
  15351.         ld      (l7bc9),a
  15352.         ret
  15353. ;
  15354. ; Statement INLINE
  15355. ;
  15356. l5698:
  15357.         call    l6f66           ; Verify (
  15358. l569b:
  15359.         ld      a,'>'
  15360.         call    l6f29
  15361.         ld      a,2
  15362.         jr      z,l56ae
  15363.         ld      a,'<'
  15364.         call    l6f29
  15365.         ld      a,1
  15366.         jr      z,l56ae
  15367.         xor     a
  15368. l56ae:
  15369.         ld      (l7ba6),a
  15370.         xor     a
  15371.         ld      h,a
  15372.         ld      l,a
  15373.         ld      b,a
  15374. l56b5:
  15375.         push    bc
  15376.         push    hl
  15377.         call    GetConst                ; Get constant
  15378.         jr      nz,l56c5
  15379.         ld      a,b
  15380.         cp      0ah
  15381.         jr      z,l5702
  15382.         call    ERROR
  15383.         db      _IntConst
  15384. l56c5:
  15385.         ld      hl,l7ba6
  15386.         ld      a,(hl)
  15387.         or      a
  15388.         jr      nz,l56ce
  15389.         ld      (hl),2
  15390. l56ce:
  15391.         ld      a,'*'
  15392.         call    l6f29
  15393.         jr      nz,l56da
  15394.         push    iy
  15395.         pop     hl
  15396.         jr      l5702
  15397. l56da:
  15398.         ld      bc,256*4+0
  15399.         call    FndLABEL
  15400.         jr      nz,l56ea
  15401.         call    l5276
  15402.         ld      hl,(l7b58)      ; Get value
  15403.         jr      l5702
  15404. l56ea:
  15405.         ld      bc,256*5+0
  15406.         call    FndLABEL
  15407.         jr      z,l56fc
  15408.         ld      bc,256*6+0
  15409.         call    FndLABEL
  15410.         call    ErrNZ
  15411.         db      _IllINLINE
  15412. l56fc:
  15413.         dec     hl
  15414.         dec     hl
  15415.         ld      d,(hl)
  15416.         dec     hl
  15417.         ld      e,(hl)
  15418.         ex      de,hl
  15419. l5702:
  15420.         pop     de
  15421.         pop     bc
  15422.         dec     b
  15423.         jr      nz,l570a
  15424.         call    NegateInt
  15425. l570a:
  15426.         add     hl,de
  15427.         ld      b,0
  15428.         ld      a,'+'
  15429.         call    l6f29
  15430.         jr      z,l56b5
  15431.         inc     b
  15432.         ld      a,'-'
  15433.         call    l6f29
  15434.         jr      z,l56b5
  15435.         ld      a,(l7ba6)
  15436.         cp      1
  15437.         jr      z,l5729
  15438.         jr      nc,l572f
  15439.         inc     h
  15440.         dec     h
  15441.         jr      nz,l572f
  15442. l5729:
  15443.         ld      a,l             ; Get byte
  15444.         call    writebyte_a_addriy              ; Store it
  15445.         jr      l5732
  15446. l572f:
  15447.         call    writeword_hl_addriy
  15448. l5732:
  15449.         ld      a,'/'
  15450.         call    l6f29
  15451.         jp      z,l569b
  15452.         jp      l6f6e           ; Verify )
  15453. l573d:
  15454.         dec     hl
  15455.         ld      b,(hl)
  15456.         dec     hl
  15457.         ld      d,(hl)
  15458.         dec     hl
  15459.         ld      e,(hl)
  15460.         dec     hl
  15461.         push    de
  15462.         ld      d,(hl)
  15463.         dec     hl
  15464.         ld      e,(hl)
  15465.         dec     hl
  15466.         push    de
  15467.         dec     hl
  15468.         dec     hl
  15469.         ld      d,(hl)
  15470.         dec     hl
  15471.         ld      e,(hl)
  15472.         dec     hl
  15473.         push    de
  15474.         ld      d,(hl)
  15475.         dec     hl
  15476.         ld      e,(hl)
  15477.         dec     hl
  15478.         push    de
  15479.         inc     b
  15480.         dec     b
  15481.         jp      z,l57d6
  15482.         call    l6f66           ; Verify (
  15483. l575e:
  15484.         push    bc
  15485.         ld      b,(hl)
  15486.         dec     hl
  15487.         ld      a,(hl)
  15488.         dec     hl
  15489.         ld      (Envir1),a
  15490.         ld      d,(hl)
  15491.         dec     hl
  15492.         ld      e,(hl)
  15493.         dec     hl
  15494.         ld      c,b
  15495. l576b:
  15496.         bit     7,(hl)
  15497.         dec     hl
  15498.         jr      z,l576b
  15499.         djnz    l576b
  15500.         ld      b,c
  15501.         push    hl
  15502.         ex      de,hl
  15503.         call    l5287           ; Get name
  15504. l5778:
  15505.         push    bc
  15506.         ld      a,(Envir1)
  15507.         or      a
  15508.         jr      nz,l57a9
  15509.         ld      a,(l7b5c)       ; Get type
  15510.         cp      _Set
  15511.         jr      c,l57a1
  15512.         call    l5e84
  15513.         call    l5864
  15514.         ld      a,(l7b5c)       ; Get type
  15515.         cp      _Ptr
  15516.         jr      z,l57bd
  15517.         cp      _Real
  15518.         jr      c,l57c0
  15519.         jr      nz,l57bd
  15520.         call    StImm           ; Set sequence
  15521.         db      a_L20
  15522. s_I20:
  15523.         PUSH    BC
  15524.         PUSH    DE
  15525. a_L20   equ     $-s_I20
  15526.         jr      l57bd
  15527. l57a1:
  15528.         call    l6d2a           ; Save environment
  15529.         call    l6749
  15530.         jr      l57af
  15531. l57a9:
  15532.         call    l6d2a           ; Save environment
  15533.         call    l677f
  15534. l57af:
  15535.         call    CpyEnv2
  15536.         ld      a,(l7b69)
  15537.         cp      0
  15538.         call    nz,l58c5
  15539.         call    RestEnv1                ; Get back environment
  15540. l57bd:
  15541.         call    StPUSH          ; Set PUSH HL
  15542. l57c0:
  15543.         pop     bc
  15544.         dec     b
  15545.         jr      z,l57c9
  15546.         call    l6f5e           ; Verify ,
  15547.         jr      l5778
  15548. l57c9:
  15549.         pop     hl
  15550.         pop     bc
  15551.         dec     b
  15552.         jr      z,l57d3
  15553.         call    l6f5e           ; Verify ,
  15554.         jr      l575e
  15555. l57d3:
  15556.         call    l6f6e           ; Verify )
  15557. l57d6:
  15558.         pop     de
  15559.         pop     hl
  15560.         ld      a,d
  15561.         or      e
  15562.         jr      z,l57e3
  15563.         call    StLD.HL         ; Set LD HL,val16
  15564.         ex      de,hl
  15565.         call    StLD.DE         ; Set LD DE,val16
  15566. l57e3:
  15567.         pop     de
  15568.         pop     hl
  15569.         ld      a,_CALL
  15570.         jp      StCode
  15571. l57ea:
  15572.         ld      a,(l7b5c)       ; Get type
  15573.         cp      0
  15574.         jr      z,l57f9
  15575.         cp      _RecF
  15576.         jr      c,l57fd
  15577.         cp      _String
  15578.         jr      nc,l57fd
  15579. l57f9:
  15580.         call    ERROR
  15581.         db      _IllAss
  15582. l57fd:
  15583.         ld      a,(l7bbd)
  15584.         bit     1,a
  15585.         jr      nz,l5812
  15586.         bit     0,a
  15587.         jr      z,l580a
  15588.         ld      a,0ffh
  15589. l580a:
  15590.         ld      hl,(l7bbe)
  15591.         ld      (l7b58),hl      ; Set value
  15592.         jr      l581a
  15593. l5812:
  15594.         call    l678b
  15595.         call    StPUSH          ; Set PUSH HL
  15596.         ld      a,1
  15597. l581a:
  15598.         ld      (Envir1),a
  15599.         call    l6f7e
  15600.         ld      a,(l7b5c)       ; Get type
  15601.         cp      _Set
  15602.         jp      nc,l593a
  15603.         call    l6d2a           ; Save environment
  15604.         call    l6749
  15605.         call    RestEnv2
  15606.         call    l58c5
  15607.         ld      a,(Envir2)
  15608.         dec     a
  15609.         jr      z,l5852
  15610.         inc     a
  15611.         jr      z,l5845
  15612.         call    StImm           ; Set LD DE,(adr)
  15613.         db      a_L21
  15614. s_I21:
  15615.         dw      _LD_a_DE
  15616. a_L21   equ     $-s_I21
  15617.         jr      l584a
  15618. l5845:
  15619.         call    StImm
  15620.         db      a_L22
  15621. s_I22:
  15622.         db      _LD.DE          ; Set LD DE,adr
  15623. a_L22   equ     $-s_I22
  15624. l584a:
  15625.         ld      hl,(l7b65)
  15626.         call    writeword_hl_addriy
  15627.         jr      l5857
  15628. l5852:
  15629.         call    StImm           ; Set POP DE
  15630.         db      a_L23
  15631. s_I23:
  15632.         pop     de
  15633. a_L23   equ     $-s_I23
  15634. l5857:
  15635.         ld      hl,(l7b6f)
  15636.         call    StLD.BC
  15637.         call    StImm           ; Set LDIR
  15638.         db      a_L24
  15639. s_I24:
  15640.         LDIR
  15641. a_L24   equ     $-s_I24
  15642.         ret
  15643. l5864:
  15644.         ld      a,(l7b5c)       ; Get type
  15645.         cp      _Real
  15646.         jr      nz,l5877
  15647.         ld      a,b
  15648.         cp      _Integ
  15649.         jr      nz,l589d
  15650.         ld      b,9
  15651.         ld      hl,l1008
  15652.         jr      l589a
  15653. l5877:
  15654.         cp      _String
  15655.         jr      nz,l588c
  15656.         ld      a,b
  15657.         cp      _Char
  15658.         jr      nz,l589d
  15659.         ld      b,8
  15660.         call    StImm           ; Set sequence
  15661.         db      a_L25
  15662. s_I25:
  15663.         LD      H,L
  15664.         LD      L,1
  15665.         PUSH    HL
  15666. a_L25   equ     $-s_I25
  15667.         jr      l589d
  15668. l588c:
  15669.         cp      _Char
  15670.         jr      nz,l589d
  15671.         ld      a,b
  15672.         cp      _String
  15673.         jr      nz,l589d
  15674.         ld      b,0ch
  15675.         ld      hl,l0996        ; Set check assignment
  15676. l589a:
  15677.         call    StCALL_         ; Set CALL <check>
  15678. l589d:
  15679.         ld      a,(l7b5c)       ; Get type
  15680.         cp      b
  15681.         jr      nz,l58c1
  15682.         cp      3
  15683.         jr      nz,l58b1
  15684.         ld      a,c
  15685.         or      a
  15686.         ret     z
  15687.         ld      hl,(l7b5e)      ; Get lo set limit
  15688.         cp      (hl)
  15689.         ret     z
  15690.         jr      l58c1
  15691. l58b1:
  15692.         cp      4
  15693.         ret     nz
  15694.         ld      hl,(l7b8b)
  15695.         ld      a,h
  15696.         or      l
  15697.         ret     z
  15698.         ld      de,(l7b5e)      ; Get lo set limit
  15699.         sbc     hl,de
  15700.         ret     z
  15701. l58c1:
  15702.         call    ERROR
  15703.         db      _InvType
  15704. l58c5:
  15705.         ld      a,(l7b5c)       ; Get type
  15706.         cp      0
  15707.         jr      z,l591b
  15708.         ld      c,0bfh
  15709.         cp      _Integ
  15710.         jr      nc,l5906
  15711.         ld      c,83h
  15712.         cp      _String
  15713.         jr      nz,l58e3
  15714.         ld      a,(l7b9e)       ; Get local options
  15715.         bit     _Vopt,a         ; Test $V+
  15716.         jr      nz,l5906        ; Yeap
  15717.         ld      c,80h
  15718.         jr      l5906
  15719. l58e3:
  15720.         cp      _TxtF
  15721.         jr      nc,l5906
  15722.         ld      c,0b3h
  15723.         cp      _Set
  15724.         jr      nc,l5906
  15725.         ld      c,0c3h
  15726.         cp      _Record
  15727.         jr      nc,l5906
  15728.         ld      hl,(l7b60)      ; Get hi set limit
  15729.         ld      a,h
  15730.         or      l
  15731.         ld      c,0bfh
  15732.         jr      nz,l5906
  15733.         ld      hl,(l7b6d)      ; Get last memory address
  15734.         ld      a,(hl)
  15735.         cp      0ah
  15736.         jr      nz,l591b
  15737.         ld      c,0b3h
  15738. l5906:
  15739.         ld      hl,l7b5c        ; Point to type
  15740.         ld      de,l7b69
  15741.         ld      b,8
  15742. l590e:
  15743.         rl      c
  15744.         jr      nc,l5916
  15745.         ld      a,(de)
  15746.         cp      (hl)
  15747.         jr      nz,l591b
  15748. l5916:
  15749.         inc     hl
  15750.         inc     de
  15751.         djnz    l590e
  15752.         ret
  15753. l591b:
  15754.         call    ERROR
  15755.         db      _InvType
  15756. l591f:
  15757.         ld      de,lfffc
  15758.         add     hl,de
  15759.         ld      d,(hl)
  15760.         dec     hl
  15761.         ld      e,(hl)
  15762.         dec     hl
  15763.         push    de
  15764.         ld      d,(hl)
  15765.         dec     hl
  15766.         ld      e,(hl)
  15767.         ld      (l7b58),de      ; Set value
  15768.         pop     hl
  15769.         call    l5287           ; Get name
  15770.         xor     a
  15771.         ld      (Envir1),a
  15772.         call    l6f7e
  15773. l593a:
  15774.         call    l5e84
  15775.         call    l5864
  15776.         jp      l661b
  15777. ;
  15778. ; Procedure ASSIGN(FileVar,String)
  15779. ;
  15780. l5943:
  15781.         call    l5a0c
  15782.         ld      hl,l1370
  15783.         cp      6
  15784.         jr      nz,l5955
  15785.         ld      hl,l136f
  15786.         call    l5955
  15787.         jr      l5989
  15788. l5955:
  15789.         push    hl
  15790.         call    StPUSH          ; Set PUSH HL
  15791.         call    l6f5e           ; Verify ,
  15792.         call    l5ed0
  15793.         pop     hl
  15794. l5960:
  15795.         call    l6f6e           ; Verify )
  15796.         jp      StCALL_         ; Set CALL <...>
  15797. ;
  15798. ; Procedure RENAME(FileVar,String)
  15799. ;
  15800. l5966:
  15801.         call    l5a0c
  15802.         ld      hl,l1ba5
  15803.         call    l5955
  15804.         jr      l5989
  15805. ;
  15806. ; Procedure ERASE(FileVar)
  15807. ;
  15808. l5971:
  15809.         call    l5a0c
  15810.         ld      hl,l1b93
  15811.         jr      l5960
  15812. ;
  15813. ; Procedure CHAIN(FileVar)
  15814. ;
  15815. l5979:
  15816.         ld      hl,l1beb
  15817.         jr      l5981
  15818. ;
  15819. ; Procedure EXECUTE(FileVar)
  15820. ;
  15821. l597e:
  15822.         ld      hl,l1bea
  15823. l5981:
  15824.         push    hl
  15825.         call    l5a0c
  15826. l5985:
  15827.         pop     hl
  15828. l5986:
  15829.         call    l5960
  15830. l5989:
  15831.         jp      l5abe
  15832. ;
  15833. ; Procedure SEEK(FileVar,Integer)
  15834. ;
  15835. l598c:
  15836.         call    l5a0c
  15837.         cp      6
  15838.         call    ErrZ
  15839.         db      _IllTxtFile
  15840.         ld      hl,l19d5
  15841.         cp      5
  15842.         jr      z,l599f
  15843.         ld      hl,l1b6f
  15844. l599f:
  15845.         push    hl
  15846.         call    StPUSH          ; Set PUSH HL
  15847.         call    l6f5e           ; Verify ,
  15848.         call    l5e97
  15849.         jr      l5985
  15850. ;
  15851. ; Procedure FLUSH(FileVar)
  15852. ;
  15853. l59ab:
  15854.         call    l5a0c
  15855.         cp      5
  15856.         call    ErrNZ
  15857.         db      _IllFileType
  15858.         ld      hl,l19a5
  15859.         jr      l5986
  15860. ;
  15861. ; Procedure RESET(FileVar,String)
  15862. ;
  15863. l59b9:
  15864.         ld      hl,l59fa
  15865.         jr      l59c1
  15866. ;
  15867. ; Procedure REWRITE(FileVar,String)
  15868. ;
  15869. l59be:
  15870.         ld      hl,l5a00
  15871. l59c1:
  15872.         push    hl
  15873.         call    l5a0c
  15874.         ld      a,(l7b5c)       ; Get type
  15875.         cp      _RecF
  15876.         jr      nz,l59d8
  15877.         ld      hl,(l7b5e)      ; Get lo set limit
  15878.         call    l5271           ; Load name
  15879.         ld      hl,(l7b6f)
  15880.         call    StLD.DE         ; Set LD DE,val16
  15881. l59d8:
  15882.         pop     hl
  15883.         jr      l59e1
  15884. ;
  15885. ; Procedure CLOSE(FileVar)
  15886. ;
  15887. l59db:
  15888.         call    l5a0c
  15889.         ld      hl,l5a06
  15890. l59e1:
  15891.         call    l6f6e           ; Verify )
  15892.         call    l59e9
  15893.         jr      l5989
  15894. l59e9:
  15895.         ld      a,(l7b5c)       ; Get type
  15896.         sub     _RecF
  15897.         add     a,a
  15898.         ld      e,a
  15899.         ld      d,0
  15900.         add     hl,de
  15901.         ld      e,(hl)
  15902.         inc     hl
  15903.         ld      d,(hl)
  15904.         ex      de,hl
  15905.         jp      StCALL_         ; Set CALL <...>
  15906. l59fa: ;reset procedures
  15907.         dw      l1811           ; Record file
  15908.         dw      l13ff           ; Text file
  15909.         dw      l1a70           ; Untyped file
  15910. l5a00: ;rewrite procedures
  15911.         dw      l1810
  15912.         dw      l13fe
  15913.         dw      l1a6f
  15914. l5a06: ;close procedures
  15915.         dw      l187a
  15916.         dw      l1469
  15917.         dw      l1ab0
  15918. l5a0c:
  15919.         call    l6f66           ; Verify (
  15920.         call    l5a17
  15921.         ret     z
  15922.         call    ERROR
  15923.         db      _FileVarExp
  15924. l5a17:
  15925.         call    l67b2
  15926.         scf
  15927.         ret     nz
  15928.         ld      a,(l7b5c)       ; Get type
  15929.         cp      _RecF
  15930.         jr      c,l5a2f
  15931.         cp      _String
  15932.         jr      nc,l5a2f
  15933.         call    l678b
  15934.         xor     a
  15935.         ld      a,(l7b5c)       ; Get back type
  15936.         ret
  15937. l5a2f:
  15938.         xor     a
  15939.         dec     a
  15940.         ret
  15941. ;
  15942. ; Procedure READLN(FileVar,Variables)
  15943. ;
  15944. l5a32:
  15945.         db      skip
  15946. ;
  15947. ; Procedure READ(FileVar,Variables)
  15948. ;
  15949. l5a33:
  15950.         xor     a
  15951.         ld      (l7ba3),a
  15952.         call    l6f1b           ; Test (
  15953.         jr      z,l5a41         ; Yeap
  15954.         call    l5aca
  15955.         jr      l5ab4
  15956. l5a41:
  15957.         call    l5a17 ;get type???
  15958.         jr      c,l5a63
  15959.         jr      nz,l5a5b
  15960.         cp      5 ;_RecF???
  15961.         jp      z,l5bd8
  15962.         cp      6 ;_TxtF???
  15963.         call    ErrNZ
  15964.         db      _NoUntypeFile
  15965.         ld      hl,l14a9
  15966.         call    StCALL_         ; Set CALL FILECHECK
  15967.         jr      l5aac
  15968. l5a5b:
  15969.         call    l678b
  15970.         call    l5aca
  15971.         jr      l5a69
  15972. l5a63:
  15973.         call    l5aca
  15974. l5a66:
  15975.         call    l677f
  15976. l5a69:
  15977.         ld      a,(l7b5c)       ; Get type
  15978.         cp      _String
  15979.         jr      c,l5a78
  15980.         cp      _Bool
  15981.         jr      z,l5a78
  15982.         cp      _Char+1
  15983.         jr      c,l5a7c
  15984. l5a78:
  15985.         call    ERROR
  15986.         db      _InvIO
  15987. l5a7c:
  15988.         cp      _String
  15989.         jr      nz,l5a8f
  15990.         ld      a,(l7b62)       ; Get length of type
  15991.         dec     a
  15992.         ld      h,a
  15993.         ld      l,6
  15994.         call    writeword_hl_addriy
  15995.         ld      hl,l168e
  15996.         jr      l5aa9
  15997. l5a8f:
  15998.         ld      hl,l1672
  15999.         cp      _Real
  16000.         jr      z,l5aa9
  16001.         ld      hl,l1644
  16002.         cp      _Char
  16003.         jr      z,l5aa9
  16004.         ld      hl,l164e
  16005.         ld      a,(l7b62)       ; Get length of type
  16006.         dec     a
  16007.         jr      nz,l5aa9
  16008.         ld      hl,l164d
  16009. l5aa9:
  16010.         call    StCALL_         ; Set CALL <read>
  16011. l5aac:
  16012.         call    l6f13           ; Test ,
  16013.         jr      z,l5a66         ; Yeap
  16014.         call    l6f6e           ; Verify )
  16015. l5ab4:
  16016.         ld      hl,l16ab
  16017. l5ab7:
  16018.         ld      a,(l7ba3)
  16019.         or      a
  16020.         call    nz,StCALL_      ; Set CALL NEWLINE
  16021. l5abe:
  16022.         ld      a,(l7b9e)       ; Get local options
  16023.         bit     _Iopt,a         ; Test $I+
  16024.         ret     z               ; Nope
  16025.         ld      hl,l201b
  16026.         jp      StCALL_         ; Set CALL CHECKIO
  16027. l5aca:
  16028.         ld      hl,l149b
  16029.         ld      a,(l7b9e)       ; Get local options
  16030.         bit     _Bopt,a         ; Test $B+
  16031.         jr      z,l5ae4         ; Nope
  16032.         ld      hl,l14cc
  16033.         ld      a,(l7ba3)
  16034.         or      a
  16035.         jr      z,l5ae4
  16036.         ld      hl,l14cb
  16037.         xor     a
  16038.         ld      (l7ba3),a
  16039. l5ae4:
  16040.         jp      StCALL_         ; Set CALL <read>
  16041. ;
  16042. ; Procedure WRITELN(FileVar,Variables)
  16043. ;
  16044. l5ae7:
  16045.         db      skip
  16046. ;
  16047. ; Procedure WRITE(FileVar,Variables)
  16048. ;
  16049. l5ae8:
  16050.         xor     a
  16051.         ld      (l7ba3),a
  16052.         call    l6f1b           ; Test (
  16053.         jr      z,l5afa         ; Yeap
  16054.         ld      hl,l149b
  16055.         call    StCALL_         ; Set CALL STDIO
  16056.         jp      l5bd2
  16057. l5afa:
  16058.         call    l5a17
  16059.         jr      c,l5b20
  16060.         jr      nz,l5b15
  16061.         cp      5
  16062.         jp      z,l5bdd
  16063.         cp      6
  16064.         call    ErrNZ
  16065.         db      _NoUntypeFile
  16066.         ld      hl,l14ba
  16067.         call    StCALL_         ; Set CALL CHECKWRFILE
  16068.         jp      l5bc9
  16069. l5b15:
  16070.         call    l620f
  16071.         ld      hl,l149b
  16072.         call    StCALL_         ; Set CALL STDIO
  16073.         jr      l5b4f
  16074. l5b20:
  16075.         ld      hl,l149b
  16076.         call    StCALL_         ; Set CALL STDIO
  16077. l5b26:
  16078.         call    GetLabType
  16079.         jr      nz,l5b4c
  16080.         ld      a,b
  16081.         cp      8 ;_String???
  16082.         jr      nz,l5b47
  16083.         ld      a,(ix+0)
  16084.         cp      ','
  16085.         jr      z,l5b3b
  16086.         cp      ')'
  16087.         jr      nz,l5b47
  16088. l5b3b:
  16089.         ld      hl,l17ba
  16090.         call    StCALL_         ; Set CALL IMSTRG
  16091.         call    StLen
  16092.         jp      l5bc9
  16093. l5b47:
  16094.         call    l6201
  16095.         jr      l5b4f
  16096. l5b4c:
  16097.         call    l5ee8
  16098. l5b4f:
  16099.         ld      a,b
  16100.         cp      8 ;0..7: _Array,_Record,_Set,_Ptr,_RecF,_TxtF,_UntF
  16101.         jr      c,l5b58 ;not a scalar type???
  16102.         cp      0dh ;element of a set???
  16103.         jr      c,l5b5c ;8..12: (_String excluded above),_Real,_Integ,_Bool,_Char
  16104. l5b58:
  16105.         call    ERROR
  16106.         db      _InvIO
  16107. l5b5c:
  16108.         cp      0ch ;_Char???
  16109.         jr      nz,l5b6a
  16110.         call    l6f0b           ; Test :
  16111.         jr      nz,l5ba6
  16112.         call    l5edd
  16113.         jr      l5b72
  16114. l5b6a:
  16115.         call    l6148
  16116.         call    l6f0b           ; Test :
  16117.         jr      nz,l5b8b
  16118. l5b72:
  16119.         push    bc
  16120.         call    l5e97
  16121.         pop     bc
  16122.         ld      a,b
  16123.         cp      9 ;_Real???
  16124.         jr      nz,l5ba6
  16125.         call    l6f0b           ; Test :
  16126.         jr      nz,l5b9d
  16127.         push    bc
  16128.         call    StPUSH          ; Set PUSH HL
  16129.         call    l5e97
  16130.         pop     bc
  16131.         jr      l5ba6
  16132. l5b8b:
  16133.         ld      hl,l0000
  16134.         ld      a,b
  16135.         cp      9 ;_Real???
  16136.         jr      nz,l5b95
  16137.         ld      l,12h
  16138. l5b95:
  16139.         call    StLD.HL         ; Set LD HL,val16
  16140.         ld      a,b
  16141.         cp      9 ;_Real???
  16142.         jr      nz,l5ba6
  16143. l5b9d:
  16144.         call    StPUSH          ; Set PUSH HL
  16145.         ld      hl,lffff
  16146.         call    StLD.HL         ; Set LD HL,val16
  16147. l5ba6:
  16148.         ld      a,b
  16149.         ld      hl,l17aa
  16150.         cp      8 ;_String???
  16151.         jr      z,l5bc6
  16152.         ld      hl,l1779
  16153.         cp      9 ;_Real???
  16154.         jr      z,l5bc6
  16155.         ld      hl,l1726
  16156.         cp      0ah ;_Integ???
  16157.         jr      z,l5bc6
  16158.         ld      hl,l178b
  16159.         cp      0bh ;_Bool???
  16160.         jr      z,l5bc6
  16161.         ld      hl,l1722
  16162. l5bc6:
  16163.         call    StCALL_         ; Set CALL <wrtype>
  16164. l5bc9:
  16165.         call    l6f13           ; Test ,
  16166.         jp      z,l5b26         ; Yeap
  16167.         call    l6f6e           ; Verify )
  16168. l5bd2:
  16169.         ld      hl,l17cd
  16170.         jp      l5ab7
  16171. l5bd8:
  16172.         ld      hl,l18b6
  16173.         jr      l5be0
  16174. l5bdd:
  16175.         ld      hl,l18dc
  16176. l5be0:
  16177.         ld      (l7ba7),hl
  16178.         ld      a,(l7ba3)
  16179.         or      a
  16180.         call    ErrNZ
  16181.         db      _MustTextFile
  16182.         ld      hl,l18a4
  16183.         call    StCALL_         ; Set CALL PREPRECWR
  16184.         ld      hl,(l7b5e)      ; Get lo set limit
  16185.         call    l5271           ; Load name
  16186. l5bf7:
  16187.         call    l6f13           ; Test ,
  16188.         jr      nz,l5c10        ; Nope
  16189.         call    SavEnv2
  16190.         call    l677f
  16191.         call    RestEnv2
  16192.         call    l58c5
  16193.         ld      hl,(l7ba7)
  16194.         call    StCALL_         ; Set CALL <write>
  16195.         jr      l5bf7
  16196. l5c10:
  16197.         call    l6f6e           ; Verify )
  16198.         jp      l5abe
  16199. ;
  16200. ; Procedure BLOCKREAD(FileVar,Variable,Integer[,Integer])
  16201. ;
  16202. l5c16:
  16203.         ld      hl,l1af1
  16204.         ld      de,l1abe
  16205.         jr      l5c24
  16206. ;
  16207. ; Procedure BLOCKWRITE(FileVar,Variable,Integer[,Integer])
  16208. ;
  16209. l5c1e:
  16210.         ld      hl,l1aed
  16211.         ld      de,l1aba
  16212. l5c24:
  16213.         push    hl
  16214.         push    de
  16215.         call    l5a0c
  16216.         cp      7
  16217.         call    ErrNZ
  16218.         db      _UntFileExp
  16219.         call    StPUSH          ; Set PUSH HL
  16220.         call    l6f5e           ; Verify ,
  16221.         call    l677f
  16222.         call    StPUSH          ; Set PUSH HL
  16223.         call    l6f5e           ; Verify ,
  16224.         call    l5e97
  16225.         call    l6f13           ; Test ,
  16226.         pop     de
  16227.         pop     hl
  16228.         jr      z,l5c4b         ; Yeap
  16229.         push    de
  16230.         jr      l5c63
  16231. l5c4b:
  16232.         push    hl
  16233.         call    StPUSH          ; Set PUSH HL
  16234.         call    l677f
  16235.         ld      a,(l7b5c)       ; Get type
  16236.         cp      _Integ
  16237.         jr      nz,l5c5f
  16238.         ld      a,(l7b62)       ; Get length of type
  16239.         dec     a
  16240.         jr      nz,l5c63
  16241. l5c5f:
  16242.         call    ERROR
  16243.         db      _IntVarExp
  16244. l5c63:
  16245.         jp      l5985
  16246. ;
  16247. ; Procedure DELETE(String,Integer,Integer)
  16248. ;
  16249. l5c66:
  16250.         call    l6f66           ; Verify (
  16251.         call    l5cad
  16252.         call    StPUSH          ; Set PUSH HL
  16253.         call    l6f5e           ; Verify ,
  16254.         call    l5e97
  16255.         call    StPUSH          ; Set PUSH HL
  16256.         call    l6f5e           ; Verify ,
  16257.         call    l5e97
  16258.         ld      hl,l08f3        ; Set DELETE
  16259. l5c81:
  16260.         call    l6f6e           ; Verify )
  16261.         jp      StCALL_         ; Set CALL <string_procedure>
  16262. ;
  16263. ; Procedure INSERT(String,String,Integer)
  16264. ;
  16265. l5c87:
  16266.         call    l6f66           ; Verify (
  16267.         call    l5ed0
  16268.         call    l6f5e           ; Verify ,
  16269.         call    l5cad
  16270.         call    StPUSH          ; Set PUSH HL
  16271.         ld      a,(l7b62)       ; Get length of type
  16272.         dec     a
  16273.         ld      h,a
  16274.         ld      l,6
  16275.         push    hl
  16276.         call    l6f5e           ; Verify ,
  16277.         call    l5e97
  16278.         pop     hl
  16279.         call    writeword_hl_addriy
  16280.         ld      hl,l0920
  16281.         jr      l5c81           ; Set INSERT
  16282. l5cad:
  16283.         call    l677f
  16284.         ld      a,(l7b5c)       ; Get type
  16285.         cp      _String
  16286.         ret     z
  16287.         call    ERROR
  16288.         db      _StrgVarExp
  16289. ;
  16290. ; Procedure STR(Num,String)
  16291. ;
  16292. l5cba:
  16293.         call    l6f66           ; Verify (
  16294.         call    l5ea2
  16295.         call    l6148
  16296.         call    l6f0b           ; Test :
  16297.         jr      nz,l5ce4
  16298.         push    bc
  16299.         call    l5e97
  16300.         call    StPUSH          ; Set PUSH HL
  16301.         pop     bc
  16302.         ld      a,b
  16303.         cp      0ah
  16304.         jr      z,l5d02
  16305.         call    l6f0b           ; Test :
  16306.         jr      nz,l5cf9
  16307.         push    bc
  16308.         call    l5e97
  16309.         call    StPUSH          ; Set PUSH HL
  16310.         pop     bc
  16311.         jr      l5d02
  16312. l5ce4:
  16313.         ld      hl,l0000
  16314.         ld      a,b
  16315.         cp      0ah
  16316.         jr      z,l5cee
  16317.         ld      l,12h
  16318. l5cee:
  16319.         call    StLD.HL         ; Set LD HL,val16
  16320.         call    StPUSH          ; Set PUSH HL
  16321.         ld      a,b
  16322.         cp      0ah
  16323.         jr      z,l5d02
  16324. l5cf9:
  16325.         ld      hl,lffff
  16326.         call    StLD.HL         ; Set LD HL,val16
  16327.         call    StPUSH          ; Set PUSH HL
  16328. l5d02:
  16329.         call    l6f5e           ; Verify ,
  16330.         push    bc
  16331.         call    l5cad
  16332.         ld      a,(l7b62)       ; Get length of type
  16333.         dec     a
  16334.         ld      h,a
  16335.         ld      l,6
  16336.         call    writeword_hl_addriy
  16337.         pop     bc
  16338.         ld      hl,l1ebe
  16339.         ld      a,b
  16340.         cp      0ah
  16341.         jr      z,l5d1f
  16342.         ld      hl,l1ebd
  16343. l5d1f:
  16344.         jp      l5c81
  16345. ;
  16346. ; Procedure VAL(String,Integer,Integer)
  16347. ;
  16348. l5d22:
  16349.         call    l6f66           ; Verify (
  16350.         call    l5ed0
  16351.         call    l6f5e           ; Verify ,
  16352.         call    l677f
  16353.         ld      a,(l7b5c)       ; Get type
  16354.         cp      _Real
  16355.         jr      z,l5d45
  16356.         cp      _Integ
  16357.         jr      nz,l5d41
  16358.         ld      a,(l7b62)       ; Get length of type
  16359.         dec     a
  16360.         ld      a,0ah
  16361.         jr      nz,l5d45
  16362. l5d41:
  16363.         call    ERROR
  16364.         db      _NumVarExp
  16365. l5d45:
  16366.         push    af
  16367.         call    StPUSH          ; Set PUSH HL
  16368.         call    l6f5e           ; Verify ,
  16369.         call    l677f
  16370.         ld      a,(l7b5c)       ; Get type
  16371.         cp      _Integ
  16372.         jr      nz,l5d5c
  16373.         ld      a,(l7b62)       ; Get length of type
  16374.         dec     a
  16375.         jr      nz,l5d60
  16376. l5d5c:
  16377.         call    ERROR
  16378.         db      _IntVarExp
  16379. l5d60:
  16380.         pop     af
  16381.         ld      hl,l1ef4
  16382.         cp      0ah
  16383.         jr      z,l5d1f
  16384.         ld      hl,l1ef3
  16385.         jr      l5d1f
  16386. ;
  16387. ; Procedure GOTOXY(Integer,Integer)
  16388. ;
  16389. l5d6d:
  16390.         call    l6f66           ; Verify (
  16391.         call    l5e97
  16392.         ld      hl,l1fdb
  16393. l5d76:
  16394.         push    hl
  16395.         call    StPUSH          ; Set PUSH HL
  16396.         call    l6f5e           ; Verify ,
  16397.         call    l5e97
  16398.         pop     hl
  16399.         jr      l5db1
  16400. ;
  16401. ; Procedure RANDOMIZE
  16402. ;
  16403. l5d83:
  16404.         ld      hl,l1f48
  16405.         jp      StCALL_         ; Set CALL RANDOMIZE
  16406. ;
  16407. ; Procedure DELAY(Integer)
  16408. ;
  16409. l5d89:
  16410.         call    l6f66           ; Verify (
  16411.         call    l5e97
  16412.         ld      hl,l021d
  16413.         jr      l5db1           ; Set call to delay
  16414. ;
  16415. ; Procedure GETMEM(Variable,Integer)
  16416. ;
  16417. l5d94:
  16418.         call    l5de3
  16419.         call    l6f5e           ; Verify ,
  16420.         call    l5e97
  16421.         jr      l5dae
  16422. ;
  16423. ; Procedure NEW(Variable)
  16424. ;
  16425. l5d9f:
  16426.         call    l5de3
  16427.         ld      hl,(l7b5e)      ; Get lo set limit
  16428.         call    l5271           ; Load name
  16429.         ld      hl,(l7b6f)
  16430.         call    StLD.HL         ; Set LD HL,val16
  16431. l5dae:
  16432.         ld      hl,l1ce5
  16433. l5db1:
  16434.         jp      l5960
  16435. ;
  16436. ; Procedure FREEMEM(Variable,Integer)
  16437. ;
  16438. l5db4:
  16439.         call    l5de3
  16440.         call    l6f5e           ; Verify ,
  16441.         call    l5e97
  16442.         jr      l5dce
  16443. ;
  16444. ; Procedure DISPOSE(Variable)
  16445. ;
  16446. l5dbf:
  16447.         call    l5de3
  16448.         ld      hl,(l7b5e)      ; Get lo set limit
  16449.         call    l5271           ; Load name
  16450.         ld      hl,(l7b6f)
  16451.         call    StLD.HL         ; Set LD HL,val16
  16452. l5dce:
  16453.         ld      hl,l1d7a
  16454.         jp      l5960
  16455. ;
  16456. ; Procedure MARK(Variable)
  16457. ;
  16458. l5dd4:
  16459.         ld      hl,l1ea3
  16460.         jr      l5ddc
  16461. ;
  16462. ; Procedure RELEASE(Variable)
  16463. ;
  16464. l5dd9:
  16465.         ld      hl,l1eab
  16466. l5ddc:
  16467.         push    hl
  16468.         call    l5de9
  16469.         pop     hl
  16470.         jr      l5db1
  16471. l5de3:
  16472.         call    l5de9
  16473.         jp      StPUSH          ; Set PUSH HL
  16474. l5de9:
  16475.         call    l6f66           ; Verify (
  16476.         call    l677f
  16477.         ld      a,(l7b5c)       ; Get type
  16478.         cp      _Ptr
  16479.         ret     z
  16480.         call    ERROR
  16481.         db      _PtrVarExp
  16482. ;
  16483. ; Procedure OVRDRIVE(Integer)
  16484. ;
  16485. l5df9:
  16486.         call    l6f66           ; Verify (
  16487.         call    l5e97
  16488.         ld      hl,l1cdb
  16489.         jp      l5960
  16490. ;
  16491. ; Procedure MOVE(Integer,Integer,Integer)
  16492. ;
  16493. l5e05:
  16494.         call    l6f66           ; Verify (
  16495.         call    l677f
  16496.         call    StPUSH          ; Set PUSH HL
  16497.         call    l6f5e           ; Verify ,
  16498.         call    l677f
  16499.         ld      hl,l1f64
  16500.         jp      l5d76
  16501. ;
  16502. ; Procedure FILLCHAR(Integer,Integer,Byte)
  16503. ;
  16504. l5e1a:
  16505.         call    l6f66           ; Verify (
  16506.         call    l677f
  16507.         call    StPUSH          ; Set PUSH HL
  16508.         call    l6f5e           ; Verify ,
  16509.         call    l5e97
  16510.         call    StPUSH          ; Set PUSH HL
  16511.         call    l6f5e           ; Verify ,
  16512.         call    l5ebb
  16513.         ld      hl,l1f4e
  16514.         jp      l5db1
  16515. ;
  16516. ; Procedure CRTINIT
  16517. ;
  16518. l5e38:
  16519.         ld      hl,l030a
  16520.         jr      l5e45           ; Set call to lead in
  16521. ;
  16522. ; Procedure CRTEXIT
  16523. ;
  16524. l5e3d:
  16525.         ld      hl,l0310
  16526.         jr      l5e45           ; Set call to lead out
  16527. ;
  16528. ; Procedure CLRSCR
  16529. ;
  16530. l5e42:
  16531.         ld      hl,l023e        ; Set call to clear screen
  16532. l5e45:
  16533.         jp      StCALL_         ; Set CALL <crt_procedure>
  16534. ;
  16535. ; Procedure CLREOL
  16536. ;
  16537. l5e48:
  16538.         ld      hl,l0299        ; Set call to clear to end of line
  16539.         jr      l5e45
  16540. ;
  16541. ; Procedure NORMVIDEO or HIGHVIDEO
  16542. ;
  16543. l5e4d:
  16544.         ld      hl,setnormvideo ; Set call to normal video
  16545.         jr      l5e45
  16546. ;
  16547. ; Procedure LOWVIDEO
  16548. ;
  16549. l5e52:
  16550.         ld      hl,setlowvideo  ; Set call to low video
  16551.         jr      l5e45
  16552. ;
  16553. ; Procedure INSLINE
  16554. ;
  16555. l5e57:
  16556.         ld      hl,l0262        ; Set call to insert line
  16557.         jr      l5e45
  16558. ;
  16559. ; Procedure DELLINE
  16560. ;
  16561. l5e5c:
  16562.         ld      hl,l0259        ; Set call to delete line
  16563.         jr      l5e45
  16564. ;
  16565. ; Procedure EXIT
  16566. ;
  16567. l5e61:
  16568.         ld      de,OS           ; Set call to exit
  16569.         jp      l5639
  16570. ;
  16571. ; Procedure HALT
  16572. ;
  16573. l5e67:
  16574.         ld      hl,l20d4
  16575.         jp      StJP_           ; Set call to HALT program
  16576. ;
  16577. ; Procedure PORT(Integer,Integer)
  16578. ;
  16579. l5e6d:
  16580.         call    l5e8e
  16581.         call    StImm           ; Set sequence
  16582.         db      a_L26
  16583. s_I26:
  16584.         POP     BC
  16585.         OUT     (C),L
  16586. a_L26   equ     $-s_I26
  16587.         ret
  16588. ;
  16589. ; Procedure STACKPTR
  16590. ;
  16591. l5e78:
  16592.         call    l6f7e
  16593.         call    l5e97
  16594.         call    StImm   ; Set LD SP,HL
  16595.         db      a_L27
  16596. s_I27:
  16597.         LD      SP,HL
  16598. a_L27   equ     $-s_I27
  16599.         ret
  16600.  
  16601. l5e84:
  16602.         call    l6d2a           ; Save environment
  16603.         call    l5ee8
  16604.         call    RestEnv1                ; Get back environment
  16605.         ret
  16606. l5e8e:
  16607.         call    l65d5
  16608.         call    l6f7e
  16609.         call    StPUSH          ; Set PUSH HL
  16610. l5e97:
  16611.         call    l5ee8
  16612.         ld      a,b
  16613.         cp      0ah
  16614.         ret     z
  16615.         call    ERROR
  16616.         db      _IntExpr
  16617. l5ea2:
  16618.         call    l5ee8
  16619.         ld      a,b
  16620.         cp      0ah
  16621.         ret     z
  16622.         cp      9
  16623.         ret     z
  16624.         call    ERROR
  16625.         db      _NumExprExp
  16626. l5eb0:
  16627.         call    l5ee8
  16628.         ld      a,b
  16629.         cp      0bh
  16630.         ret     z
  16631.         call    ERROR
  16632.         db      _BoolExp
  16633. l5ebb:
  16634.         call    l5ee8
  16635. l5ebe:
  16636.         ld      a,b
  16637.         cp      0ah
  16638.         ret     nc
  16639.         cp      8
  16640.         call    ErrNZ
  16641.         db      _SimpExpr
  16642.         ld      b,0ch
  16643.         ld      hl,l0996
  16644.         jp      StCALL_         ; Set CALL CHECKASSIGNMENT
  16645. l5ed0:
  16646.         call    l5ee8
  16647.         ld      a,b
  16648.         cp      8
  16649.         ret     z
  16650.         cp      0ch
  16651.         call    ErrNZ
  16652.         db      _StrgExpExp
  16653. l5edd:
  16654.         ld      b,8
  16655.         call    StImm           ; Set sequence
  16656.         db      a_L28
  16657. s_I28:
  16658.         LD      H,L
  16659.         LD      L,1
  16660.         PUSH    HL
  16661. a_L28   equ     $-s_I28
  16662.         ret
  16663. l5ee8:
  16664.         call    l5f98
  16665. l5eeb:
  16666.         push    bc
  16667.         call    FndTabStr               ; Find relation
  16668.         db      1
  16669.         dw      l7625
  16670.         pop     bc
  16671.         ret     nz              ; Nope
  16672.         ld      a,(hl)          ; Get code
  16673.         inc     a               ; Test IN
  16674.         jr      z,l5f34         ; Yeap
  16675.         dec     a
  16676.         push    af
  16677.         push    bc
  16678.         call    l6148
  16679.         ld      hl,(l7b8b)
  16680.         push    hl
  16681.         call    l5f98
  16682.         pop     hl
  16683.         ld      (l7b8d),hl
  16684.         pop     de
  16685.         call    l6160
  16686.         pop     af
  16687.         ld      e,a
  16688.         ld      d,0
  16689.         ld      hl,l5f68
  16690.         add     hl,de
  16691.         ld      a,b
  16692.         cp      3
  16693.         jr      z,l5f28
  16694.         inc     hl
  16695.         inc     hl
  16696.         cp      9
  16697.         jr      z,l5f28
  16698.         inc     hl
  16699.         inc     hl
  16700.         cp      8
  16701.         jr      z,l5f28
  16702.         inc     hl
  16703.         inc     hl
  16704. l5f28:
  16705.         ld      e,(hl)
  16706.         inc     hl
  16707.         ld      d,(hl)
  16708.         ld      a,d
  16709.         or      e
  16710.         call    ErrZ
  16711.         db      _IllOps
  16712.         ex      de,hl
  16713.         jr      l5f62
  16714. l5f34:
  16715.         ld      a,b
  16716.         cp      0ah
  16717.         jr      nc,l5f47
  16718.         cp      8
  16719.         call    ErrNZ
  16720.         db      _IllOps
  16721.         ld      hl,l0996
  16722.         call    StCALL_         ; Set CALL CHECKASSIGNMENT
  16723.         ld      b,0ch
  16724. l5f47:
  16725.         push    bc
  16726.         call    StPUSH          ; Set PUSH HL
  16727.         call    l5f98
  16728.         pop     de
  16729.         ld      a,b
  16730.         cp      3
  16731.         call    ErrNZ
  16732.         db      _IllOps
  16733.         ld      a,c
  16734.         or      a
  16735.         jr      z,l5f5f
  16736.         cp      d
  16737.         call    ErrNZ
  16738.         db      _InvType
  16739. l5f5f:
  16740.         ld      hl,l134f
  16741. l5f62:
  16742.         call    StCALL_         ; Set CALL <set>
  16743.         ld      b,0bh
  16744.         ret
  16745. l5f68:
  16746.         dw      l12e1
  16747.         dw      l0688           ; Real =
  16748.         dw      l068d           ; String =
  16749.         dw      l067f           ; Integer =
  16750.         dw      l12dd
  16751.         dw      l069b           ; Real <>
  16752.         dw      l06a0           ; String <>
  16753.         dw      l0692           ; Integer <>
  16754.         dw      l1300
  16755.         dw      l06ae           ; Real >=
  16756.         dw      l06b3           ; String >=
  16757.         dw      l06a5           ; Integer >=
  16758.         dw      l12fc
  16759.         dw      l06c2           ; Real <=
  16760.         dw      l06c7           ; String <=
  16761.         dw      l06b8           ; Integer <=
  16762.         dw      l0000
  16763.         dw      l06d6           ; Real >
  16764.         dw      l06db           ; String >
  16765.         dw      l06cc           ; Integer >
  16766.         dw      l0000
  16767.         dw      l06e9           ; Real <
  16768.         dw      l06ee           ; String <
  16769.         dw      l06e0           ; Integer <
  16770. l5f98:
  16771.         call    l6054
  16772. l5f9b:
  16773.         push    bc
  16774.         call    FndTabStr               ; Find operator
  16775.         db      1
  16776.         dw      l7619
  16777.         pop     bc
  16778.         ret     nz              ; Nope
  16779.         ld      a,b
  16780.         cp      4
  16781.         call    ErrZ
  16782.         db      _IllOps
  16783.         ld      a,(hl)          ; Get operator
  16784.         push    af
  16785.         push    bc
  16786.         call    l6148
  16787.         call    l6054
  16788.         pop     de
  16789.         pop     af              ; Get back operator
  16790.         push    af
  16791.         or      a               ; Test +
  16792.         jr      nz,l5fc9        ; Nope
  16793.         ld      a,b
  16794.         cp      0ch
  16795.         jr      nz,l5fc9
  16796.         call    StImm           ; Set sequence
  16797.         db      a_L29
  16798. s_I29:
  16799.         LD      H,L
  16800.         LD      L,1
  16801.         PUSH    HL
  16802. a_L29   equ     $-s_I29
  16803.         ld      b,8
  16804. l5fc9:
  16805.         call    l6160
  16806.         pop     af              ; Get back operator
  16807.         cp      2               ; Test -
  16808.         jr      nc,l601b        ; Nope, OR or XOR
  16809.         push    af
  16810.         ld      a,b
  16811.         ld      hl,l1318
  16812.         ld      de,l1326
  16813.         cp      3
  16814.         jr      z,l6006
  16815.         ld      hl,l09e9        ; Set add reals
  16816.         ld      de,l09f2        ; Set subtract reals
  16817.         cp      9
  16818.         jr      z,l6006
  16819.         cp      8
  16820.         jr      z,l6010
  16821.         cp      0ah
  16822.         call    ErrNZ
  16823.         db      _IllOps
  16824.         pop     af
  16825.         dec     a
  16826.         jr      z,l5ffc
  16827.         call    StImm           ; Set ADD HL,DE
  16828.         db      a_L30
  16829. s_I30:
  16830.         ADD     HL,DE
  16831. a_L30   equ     $-s_I30
  16832.         jr      l5f9b
  16833. l5ffc:
  16834.         call    StImm           ; Set sequence
  16835.         db      a_L31
  16836. s_I31:
  16837.         EX      DE,HL
  16838.         OR      A
  16839.         SBC     HL,DE
  16840. a_L31   equ     $-s_I31
  16841.         jr      l5f9b
  16842. l6006:
  16843.         pop     af
  16844.         dec     a
  16845.         jr      nz,l600b
  16846.         ex      de,hl
  16847. l600b:
  16848.         call    StCALL_         ; Set CALL <string>
  16849.         jr      l5f9b
  16850. l6010:
  16851.         pop     af
  16852.         dec     a
  16853.         call    ErrZ
  16854.         db      _IllOps
  16855.         ld      hl,l083d
  16856.         jr      l600b           ; Set add two strings
  16857. l601b:
  16858.         ld      a,b
  16859.         jr      nz,l6039        ; Must be XOR
  16860.         cp      0bh
  16861.         jr      z,l602f
  16862.         cp      0ah
  16863.         call    ErrNZ
  16864.         db      _IllOps
  16865.         call    StImm           ; Set OR
  16866.         db      a_L32
  16867. s_I32:
  16868.         LD      A,H
  16869.         OR      D
  16870.         LD      H,A
  16871. a_L32   equ     $-s_I32
  16872. l602f:
  16873.         call    StImm           ; Set OR
  16874.         db      a_L33
  16875. s_I33:
  16876.         LD      A,L
  16877.         OR      E
  16878.         LD      L,A
  16879. a_L33   equ     $-s_I33
  16880.         jp      l5f9b
  16881. l6039:
  16882.         cp      0bh
  16883.         jr      z,l604a
  16884.         cp      0ah
  16885.         call    ErrNZ
  16886.         db      _IllOps
  16887.         call    StImm           ; Set XOR
  16888.         db      a_L34
  16889. s_I34:
  16890.         LD      A,H
  16891.         XOR     D
  16892.         LD      H,A
  16893. a_L34   equ     $-s_I34
  16894. l604a:
  16895.         call    StImm           ; Set XOR
  16896.         db      a_L35
  16897. s_I35:
  16898.         LD      A,L
  16899.         XOR     E
  16900.         LD      L,A
  16901. a_L35   equ     $-s_I35
  16902.         jp      l5f9b
  16903. l6054:
  16904.         call    l60e9
  16905. l6057:
  16906.         push    bc
  16907.         call    FndTabStr               ; Find operator
  16908.         db      1
  16909.         dw      l7600
  16910.         pop     bc
  16911.         ret     nz              ; Nope
  16912.         ld      a,b
  16913.         cp      4
  16914.         call    ErrZ
  16915.         db      _IllOps
  16916.         ld      a,(hl)          ; Get operator
  16917.         push    af
  16918.         push    bc
  16919.         call    l6148
  16920.         call    l60e9
  16921.         pop     de
  16922.         pop     af              ; Get back operator
  16923.         push    af
  16924.         dec     a               ; Test /
  16925.         jr      nz,l6083        ; Nope
  16926.         ld      a,b
  16927.         cp      0ah
  16928.         jr      nz,l6083
  16929.         ld      hl,l1008
  16930.         call    StCALL_         ; Set CALL INT_TO_FLP
  16931.         ld      b,9
  16932. l6083:
  16933.         call    l6160
  16934.         pop     af              ; Get back operator
  16935.         ld      e,a
  16936.         ld      a,b
  16937.         inc     e               ; Test *
  16938.         dec     e
  16939.         jr      nz,l60a9        ; Nope
  16940.         ld      hl,l1333
  16941.         cp      3
  16942.         jr      z,l60a4
  16943.         ld      hl,l06f5        ; Set integer multiply
  16944.         cp      0ah
  16945.         jr      z,l60a4
  16946.         ld      hl,l09fa        ; Set real multiply
  16947. l609e:
  16948.         cp      9
  16949.         call    ErrNZ
  16950.         db      _IllOps
  16951. l60a4:
  16952.         call    StCALL_         ; Set CALL <real>
  16953.         jr      l6057
  16954. l60a9:
  16955.         ld      hl,l09ff        ; Set real division
  16956.         dec     e               ; Test /
  16957.         jr      z,l609e         ; Yeap
  16958.         dec     e               ; Test AND
  16959.         jr      nz,l60cc        ; Nope
  16960.         cp      0bh
  16961.         jr      z,l60c3
  16962.         cp      0ah
  16963.         call    ErrNZ
  16964.         db      _IllOps
  16965.         call    StImm           ; Set AND
  16966.         db      a_L36
  16967. s_I36:
  16968.         LD      A,H
  16969.         AND     D
  16970.         LD      H,A
  16971. a_L36   equ     $-s_I36
  16972. l60c3:
  16973.         call    StImm           ; Set AND
  16974.         db      a_L37
  16975. s_I37:
  16976.         LD      A,L
  16977.         AND     E
  16978.         LD      L,A
  16979. a_L37   equ     $-s_I37
  16980.         jr      l6057
  16981. l60cc:
  16982.         cp      0ah
  16983.         call    ErrNZ
  16984.         db      _IllOps
  16985.         ld      hl,l070f        ; Set integer DIV
  16986.         dec     e               ; Test DIV
  16987.         jr      z,l60a4         ; Yeap
  16988.         ld      hl,l0745        ; Set integer MOD
  16989.         dec     e               ; Test MOD
  16990.         jr      z,l60a4
  16991.         ld      hl,l074e        ; Set SHL
  16992.         dec     e               ; Test SHL
  16993.         jr      z,l60a4
  16994.         ld      hl,l0756        ; Set SHR
  16995.         jr      l60a4
  16996. l60e9:
  16997.         call    FindStr         ; Find NOT
  16998.         dw      l7579
  16999.         jr      nz,l6112        ; Nope
  17000.         call    l6112
  17001.         ld      a,b
  17002.         cp      0ah
  17003.         jr      z,l6107
  17004.         cp      0bh
  17005.         call    ErrNZ
  17006.         db      _IllOps
  17007.         call    StImm           ; Set sequence
  17008.         db      a_L38
  17009. s_I38:
  17010.         LD      A,L
  17011.         XOR     1
  17012.         LD      L,A
  17013. a_L38   equ     $-s_I38
  17014.         ret
  17015. l6107:
  17016.         call    StImm           ; Set sequence
  17017.         db      a_L39
  17018. s_I39:
  17019.         LD      A,L
  17020.         CPL
  17021.         LD      L,A
  17022.         LD      A,H
  17023.         CPL
  17024.         LD      H,A
  17025. a_L39   equ     $-s_I39
  17026.         ret
  17027. l6112:
  17028.         ld      a,(l7ba1)
  17029.         push    af
  17030.         call    GetSign
  17031.         ld      a,e
  17032.         ld      (l7ba1),a
  17033.         call    l621d
  17034.         ld      a,(l7ba1)
  17035.         ld      e,a
  17036.         call    ChkNumSign
  17037.         jr      z,l6143
  17038.         ld      a,b
  17039.         cp      0ah
  17040.         jr      nz,l613b
  17041.         call    StImm           ; Set sequence
  17042.         db      a_L40
  17043. s_I40:
  17044.         LD      A,L
  17045.         CPL
  17046.         LD      L,A
  17047.         LD      A,H
  17048.         CPL
  17049.         LD      H,A
  17050.         INC     HL
  17051. a_L40   equ     $-s_I40
  17052.         jr      l6143
  17053. l613b:
  17054.         call    StImm           ; Set sequence
  17055.         db      a_L41
  17056. s_I41:
  17057.         LD      A,B
  17058.         XOR     80H
  17059.         LD      B,A
  17060. a_L41   equ     $-s_I41
  17061. l6143:
  17062.         pop     af
  17063.         ld      (l7ba1),a
  17064.         ret
  17065. l6148:
  17066.         ld      a,b
  17067.         cp      0ah
  17068.         jr      nc,l615d
  17069.         cp      4
  17070.         jr      z,l615d
  17071.         cp      8
  17072.         ret     z
  17073.         cp      3
  17074.         ret     z
  17075.         call    StImm           ; Set sequence
  17076.         db      a_L42
  17077. s_I42:
  17078.         PUSH    BC
  17079.         PUSH    DE
  17080. a_L42   equ     $-s_I42
  17081. l615d:
  17082.         jp      StPUSH          ; Set PUSH HL
  17083. l6160:
  17084.         ld      a,d
  17085.         cp      9
  17086.         jr      nz,l6174
  17087.         ld      a,b
  17088.         cp      0ah
  17089.         jr      nz,l6187
  17090.         ld      hl,l1008
  17091.         call    StCALL_         ; Set CALL INT_TO_FLP
  17092.         ld      b,9
  17093.         jr      l6187
  17094. l6174:
  17095.         cp      8
  17096.         jr      nz,l6187
  17097.         ld      a,b
  17098.         cp      0ch
  17099.         jr      nz,l6187
  17100.         call    StImm           ; Set sequence
  17101.         db      a_L43
  17102. s_I43:
  17103.         LD      H,L
  17104.         LD      L,1
  17105.         PUSH    HL
  17106. a_L43   equ     $-s_I43
  17107.         ld      b,8
  17108. l6187:
  17109.         ld      a,b
  17110.         cp      9
  17111.         jr      nz,l6193
  17112.         call    StImm           ; Set EXX
  17113.         db      a_L44
  17114. s_I44:
  17115.         EXX
  17116. a_L44   equ     $-s_I44
  17117.         jr      l61a4
  17118. l6193:
  17119.         cp      8
  17120.         jr      nz,l61a4
  17121.         ld      a,d
  17122.         cp      0ch
  17123.         jr      nz,l61a4
  17124.         ld      hl,l09a2
  17125.         call    StCALL_         ; Set CALL CHR_TO_STRG
  17126.         ld      d,8
  17127. l61a4:
  17128.         ld      a,d
  17129.         cp      0ah
  17130.         jr      z,l61bc
  17131.         jr      nc,l61ce
  17132.         cp      4
  17133.         jr      z,l61ce
  17134.         cp      9
  17135.         jr      c,l61d3
  17136.         call    StImm           ; Set sequence
  17137.         db      a_L45
  17138. s_I45:
  17139.         POP     HL
  17140.         POP     DE
  17141.         POP     BC
  17142. a_L45   equ     $-s_I45
  17143.         jr      l61d3
  17144. l61bc:
  17145.         ld      a,b
  17146.         cp      9
  17147.         jr      nz,l61ce
  17148.         call    StPOP           ; Set POP HL
  17149.         ld      hl,l1008
  17150.         call    StCALL_         ; Set CALL INT_TO_FLP
  17151.         ld      d,9
  17152.         jr      l61d3
  17153. l61ce:
  17154.         call    StImm           ; Set POP DE
  17155.         db      a_L46
  17156. s_I46:
  17157.         POP     DE
  17158. a_L46   equ     $-s_I46
  17159. l61d3:
  17160.         ld      a,b
  17161.         cp      d
  17162.         call    ErrNZ
  17163.         db      _InvType
  17164.         cp      3
  17165.         jr      nz,l61ea
  17166.         ld      a,e
  17167.         cp      c
  17168.         ret     z
  17169.         or      a
  17170.         ret     z
  17171.         ld      a,c
  17172.         ld      c,e
  17173.         or      a
  17174.         ret     z
  17175.         call    ERROR
  17176.         db      _InvType
  17177. l61ea:
  17178.         cp      4
  17179.         ret     nz
  17180.         ld      hl,(l7b8b)
  17181.         ld      a,h
  17182.         or      l
  17183.         ret     z
  17184.         ld      de,(l7b8d)
  17185.         ld      a,d
  17186.         or      e
  17187.         ret     z
  17188.         sbc     hl,de
  17189.         ret     z
  17190.         call    ERROR
  17191.         db      _InvType
  17192. l6201:
  17193.         ld      de,l5eeb
  17194.         push    de
  17195.         ld      de,l5f9b
  17196.         push    de
  17197.         ld      de,l6057
  17198.         push    de
  17199.         jr      l622d
  17200. l620f:
  17201.         ld      de,l5eeb
  17202.         push    de
  17203.         ld      de,l5f9b
  17204.         push    de
  17205.         ld      de,l6057
  17206.         push    de
  17207.         jr      l6276
  17208. l621d:
  17209.         call    GetLabType
  17210.         jr      nz,l6257
  17211.         ld      a,(l7ba1)
  17212.         ld      e,a
  17213.         call    NegateNum
  17214.         xor     a
  17215.         ld      (l7ba1),a
  17216. l622d:
  17217.         ld      a,b
  17218.         cp      9
  17219.         jr      nz,l6249
  17220.         exx
  17221.         push    bc
  17222.         push    de
  17223.         push    hl
  17224.         ld      bc,256*3+031h
  17225. l6239:
  17226.         ld      a,c
  17227.         sub     10h
  17228.         ld      c,a             ; Get byte
  17229.         call    writebyte_a_addriy              ; Store it
  17230.         pop     hl
  17231.         call    writeword_hl_addriy
  17232.         djnz    l6239
  17233.         ld      b,9
  17234.         ret
  17235. l6249:
  17236.         cp      8
  17237.         jp      nz,StLD.HL      ; Set LD HL,val16
  17238.         ld      hl,l054d
  17239.         call    StCALL_         ; move immediate string to stack
  17240.         jp      StLen
  17241. l6257:
  17242.         ld      bc,256*6+0
  17243.         call    FndLABEL
  17244.         jr      nz,l6271
  17245.         call    l573d
  17246.         ex      de,hl
  17247.         call    l5287           ; Get name
  17248.         ld      hl,(l7b5e)      ; Get lo set limit
  17249.         ld      (l7b8b),hl
  17250.         ld      a,(l7b5c)       ; Get type
  17251.         ld      b,a
  17252.         ret
  17253. l6271:
  17254.         call    l67b2
  17255.         jr      nz,l62d2
  17256. l6276:
  17257.         ld      a,(l7b5c)       ; Get type
  17258.         cp      _String
  17259.         jr      nc,l6285
  17260.         cp      _Set
  17261.         jr      z,l6285
  17262.         cp      _Ptr
  17263.         jr      nz,l629d
  17264. l6285:
  17265.         call    l66da
  17266.         ld      hl,(l7b5e)      ; Get lo set limit
  17267.         ld      (l7b8b),hl
  17268.         ld      a,(l7b5c)       ; Get type
  17269.         ld      b,a
  17270.         cp      _Set
  17271.         ret     nz
  17272.         call    l5287           ; Get name
  17273.         ld      a,(l7b5c)       ; Get type
  17274.         ld      c,a
  17275.         ret
  17276. l629d:
  17277.         cp      _Array
  17278.         call    ErrNZ
  17279.         db      _NoStruktVar
  17280.         call    l678b
  17281.         ld      hl,(l7b5e)      ; Get lo set limit
  17282.         ld      a,(hl)
  17283.         cp      0ch
  17284.         call    ErrNZ
  17285.         db      _NoStruktVar
  17286.         ld      hl,(l7b60)      ; Get hi set limit
  17287.         ld      a,(hl)
  17288.         cp      0ah
  17289.         call    ErrNZ
  17290.         db      _NoStruktVar
  17291.         ld      hl,(l7b62)      ; Get length of type
  17292.         ld      a,h
  17293.         or      a
  17294.         call    ErrNZ
  17295.         db      _NoStruktVar
  17296.         ld      h,l
  17297.         ld      l,6
  17298.         call    writeword_hl_addriy
  17299.         ld      hl,l0638
  17300.         call    StCALL_         ; Set set to stack
  17301.         ld      b,8
  17302.         ret
  17303. l62d2:
  17304.         call    l6ee0
  17305.         jr      nz,l631c
  17306.         ld      hl,l0581
  17307.         call    StCALL_         ; Initialize a set on stack
  17308.         call    l6ef7           ; Test ]
  17309.         ld      bc,3*256+0 ;l0300
  17310.         ret     z               ; Yeap
  17311. l62e4:
  17312.         push    bc
  17313.         call    l5ebb
  17314.         ld      a,b
  17315.         pop     bc
  17316.         inc     c
  17317.         dec     c
  17318.         jr      nz,l62ef
  17319.         ld      c,a
  17320. l62ef:
  17321.         cp      c
  17322.         call    ErrNZ
  17323.         db      _InvType
  17324.         push    bc
  17325.         call    FindStr         ; Find ..
  17326.         dw      l7580
  17327.         ld      hl,l0591
  17328.         jr      nz,l6310        ; Nope, init one set element
  17329.         call    StPUSH          ; Set PUSH HL
  17330.         call    l5ebb
  17331.         ld      a,b
  17332.         pop     bc
  17333.         push    bc
  17334.         cp      c
  17335.         call    ErrNZ
  17336.         db      _InvType
  17337.         ld      hl,l059b        ; Init a contiguous set value
  17338. l6310:
  17339.         call    StCALL_         ; Set CALL <set>
  17340.         pop     bc
  17341.         call    l6f13           ; Test ,
  17342.         jr      z,l62e4         ; Yeap
  17343.         jp      l6f38           ; Verify ]
  17344. l631c:
  17345.         call    l6f1b           ; Test (
  17346.         jr      nz,l6327        ; Nope
  17347.         call    l5ee8
  17348.         jp      l6f6e           ; Verify )
  17349. l6327:
  17350.         call    FndTabStr               ; Find function
  17351.         db      2
  17352.         dw      l77b1
  17353.         jr      nz,l6335        ; Nope
  17354.         ld      e,(hl)
  17355.         inc     hl
  17356.         ld      d,(hl)
  17357.         ex      de,hl
  17358.         xor     a
  17359.         jp      (hl)
  17360. l6335:
  17361.         call    FindStr         ; Find NIL
  17362.         dw      l757c
  17363.         jr      nz,l6345        ; Nope
  17364.         ld      hl,l0000
  17365.         call    StLD.HL         ; Set LD HL,val16
  17366.         jp      l642e
  17367. l6345:
  17368.          ;jr $
  17369.         ld      bc,256*3+0
  17370.         call    FndLABEL ; Find label with type in reg B
  17371.         call    ErrNZ
  17372.         db      _Undef ;TODO fix bb:=(Txt in [Txt]);
  17373.         ld      d,(hl)
  17374.         dec     hl
  17375.         ld      e,(hl)
  17376.         ld      a,(de)
  17377.         cp      0ah
  17378.         call    ErrCY
  17379.         db      _SimTyp
  17380.         push    af
  17381.         call    l65ef
  17382.         pop     af
  17383.         ld      b,a
  17384.         ret
  17385. ;
  17386. ; Function SQR(Num)
  17387. ;
  17388. l6360:
  17389.         call    l65e7
  17390.         ld      hl,l06f3        ; Set integer SQR
  17391.         ld      a,b
  17392.         cp      0ah
  17393.         jr      z,l636e
  17394.         ld      hl,l09f7        ; Set real SQR
  17395. l636e:
  17396.         jp      StCALL_         ; Set CALL <real>
  17397. ;
  17398. ; Function ABS(Num)
  17399. ;
  17400. l6371:
  17401.         call    l65e7
  17402.         ld      a,b
  17403.         cp      0ah
  17404.         jr      z,l6380
  17405.         call    StImm           ; Set RES 7,B
  17406.         db      a_L47
  17407. s_I47:
  17408.         RES     7,B
  17409. a_L47   equ     $-s_I47
  17410.         ret
  17411. l6380:
  17412.         ld      hl,l0780        ; Set integer ABS
  17413.         jr      l63cf
  17414. ;
  17415. ; Function SQRT(Num)
  17416. ;
  17417. l6385:
  17418.         ld      hl,l0c46
  17419.         jr      l63ab
  17420. ;
  17421. ; Function SIN(Num)
  17422. ;
  17423. l638a:
  17424.         ld      hl,l0c87
  17425.         jr      l63ab
  17426. ;
  17427. ; Function COS(Num)
  17428. ;
  17429. l638f:
  17430.         ld      hl,l0c7f
  17431.         jr      l63ab
  17432. ;
  17433. ; Function ARCTAN(Num)
  17434. ;
  17435. l6394:
  17436.         ld      hl,l0e46
  17437.         jr      l63ab
  17438. ;
  17439. ; Function LN(Num)
  17440. ;
  17441. l6399:
  17442.         ld      hl,l0d2b
  17443.         jr      l63ab
  17444. ;
  17445. ; Function EXP(Num)
  17446. ;
  17447. l639e:
  17448.         ld      hl,l0db6
  17449.         jr      l63ab
  17450. ;
  17451. ; Function INT(Num)
  17452. ;
  17453. l63a3:
  17454.         ld      hl,l0bfd
  17455.         jr      l63ab
  17456. ;
  17457. ; Function FRAC(Num)
  17458. ;
  17459. l63a8:
  17460.         ld      hl,l0c34
  17461. l63ab:
  17462.         push    hl
  17463.         call    l65e7
  17464.         ld      hl,l1008
  17465.         ld      a,b
  17466.         cp      0ah
  17467.         call    z,StCALL_               ; Set CALL INT_TO_FLP
  17468.         pop     hl
  17469.         ld      b,9
  17470.         jp      StCALL_         ; Set CALL <real>
  17471. ;
  17472. ; Function TRUNC(Num)
  17473. ;
  17474. l63be:
  17475.         ld      hl,l0fde
  17476.         jr      l63c6
  17477. ;
  17478. ; Function ROUND(Num)
  17479. ;
  17480. l63c3:
  17481.         ld      hl,l0fd0
  17482. l63c6:
  17483.         push    hl
  17484.         call    l65e7
  17485.         pop     hl
  17486.         ld      a,b
  17487.         cp      0ah
  17488.         ret     z
  17489. l63cf:
  17490.         ld      b,0ah
  17491.         jp      StCALL_         ; Set CALL <real>
  17492. ;
  17493. ; Function SUCC(Num)
  17494. ;
  17495. l63d4:
  17496.         ld      a,_INC.HL       ; INC HL
  17497.         db      skip.3
  17498. ;
  17499. ; Function PRED(Num)
  17500. ;
  17501. l63d7:
  17502.         ld      a,_DEC.HL       ; DEC HL
  17503.         push    af
  17504.         call    l65ef
  17505.         pop     af              ; Get byte back
  17506.         jp      writebyte_a_addriy              ; Store it
  17507. ;
  17508. ; Function LO(Integer)
  17509. ;
  17510. l63e1:
  17511.         call    l65de
  17512.         call    StImm           ; Set LD H,0
  17513.         db      a_L48
  17514. s_I48:
  17515.         LD      H,0
  17516. a_L48   equ     $-s_I48
  17517.         ret
  17518. ;
  17519. ; Function HI(Integer)
  17520. ;
  17521. l63eb:
  17522.         call    l65de
  17523.         call    StImm           ; Set sequence
  17524.         db      a_L49
  17525. s_I49:
  17526.         LD      L,H
  17527.         LD      H,0
  17528. a_L49   equ     $-s_I49
  17529.         ret
  17530. ;
  17531. ; Function SWAP(Num)
  17532. ;
  17533. l63f6:
  17534.         call    l65de
  17535.         call    StImm           ; Set sequence
  17536.         db      a_L50
  17537. s_I50:
  17538.         LD      A,L
  17539.         LD      L,H
  17540.         LD      H,A
  17541. a_L50   equ     $-s_I50
  17542.         ret
  17543. ;
  17544. ; Function ODD(Num)
  17545. ;
  17546. l6401:
  17547.         call    l65de
  17548.         ld      hl,l078b        ; Set function ODD
  17549. l6407:
  17550.         ld      b,0bh
  17551. l6409:
  17552.         jp      StCALL_         ; Set CALL ODD
  17553. ;
  17554. ; Function KEYPRESSED
  17555. ;
  17556. l640c:
  17557.         ld      hl,l00a0
  17558.         jr      l6407
  17559. ;
  17560. ; Function ORD(Var)
  17561. ;
  17562. l6411:
  17563.         call    l6f66           ; Verify (
  17564.         call    l5ee8
  17565.         call    l6f6e           ; Verify )
  17566.         ld      a,b
  17567.         cp      4
  17568.         jr      z,l6422
  17569.         call    l5ebe
  17570. l6422:
  17571.         ld      b,0ah
  17572.         ret
  17573. ;
  17574. ; Function CHR(Num)
  17575. ;
  17576. l6425:
  17577.         call    l65de
  17578.         ld      b,0ch
  17579.         ret
  17580. ;
  17581. ; Function PTR(Integer)
  17582. ;
  17583. l642b:
  17584.         call    l65de
  17585. l642e:
  17586.         ld      hl,l0000
  17587.         ld      (l7b8b),hl
  17588.         ld      b,4
  17589.         ret
  17590. ;
  17591. ; Function UPCASE(Char)
  17592. ;
  17593. l6437:
  17594.         call    l65ef
  17595.         ld      b,0ch
  17596.         ld      hl,l1fe4
  17597.         jr      l6409
  17598. ;
  17599. ; Function LENGTH(String)
  17600. ;
  17601. l6441:
  17602.         call    l6f66           ; Verify (
  17603.         ld      hl,l08a3        ; Set LENGTH
  17604. l6447:
  17605.         push    hl
  17606.         call    l5ed0
  17607.         call    l6f6e           ; Verify )
  17608.         pop     hl
  17609.         jp      l63cf
  17610. ;
  17611. ; Function POS(String,String)
  17612. ;
  17613. l6452:
  17614.         call    l6f66           ; Verify (
  17615.         call    l5ed0
  17616.         call    l6f5e           ; Verify ,
  17617.         ld      hl,l08b2
  17618.         jr      l6447           ; Set POS
  17619. ;
  17620. ; Function COPY(String,Integer,Integer)
  17621. ;
  17622. l6460:
  17623.         call    l6f66           ; Verify (
  17624.         call    l5ed0
  17625.         call    l6f5e           ; Verify ,
  17626.         call    l5e97
  17627.         call    l6f5e           ; Verify ,
  17628.         call    StPUSH          ; Set PUSH HL
  17629.         call    l5e97
  17630.         call    l6f6e           ; Verify )
  17631.         ld      hl,l086b
  17632.         call    StCALL_         ; Set CALL COPY
  17633. l647e:
  17634.         ld      b,8
  17635.         ret
  17636. ;
  17637. ; Function CONCAT(String,String,...)
  17638. ;
  17639. l6481:
  17640.         call    l6f66           ; Verify (
  17641.         call    l5ed0
  17642. l6487:
  17643.         call    l6f13           ; Test ,
  17644.         jr      nz,l6497        ; Nope
  17645.         call    l5ed0
  17646.         ld      hl,l083d
  17647.         call    StCALL_         ; Set add two strings
  17648.         jr      l6487
  17649. l6497:
  17650.         call    l6f6e           ; Verify )
  17651.         jr      l647e
  17652. ;
  17653. ; Function PARAMCOUNT
  17654. ;
  17655. l649c:
  17656.         ld      hl,l1f9b
  17657.         jr      l64bf
  17658. ;
  17659. ; Function PARAMSTR(Integer)
  17660. ;
  17661. l64a1:
  17662.         call    l65de
  17663.         ld      hl,l1f7d
  17664.         ld      b,8
  17665.         jp      StCALL_         ; Set CALL PARAMSTR
  17666. ;
  17667. ; Function RANDOM(Integer)
  17668. ;
  17669. l64ac:
  17670.         call    l6f1b           ; Test (
  17671.         ld      hl,l0fb4
  17672.         ld      b,9
  17673.         jr      nz,l64c1        ; Nope
  17674.         call    l5e97
  17675.         call    l6f6e           ; Verify )
  17676.         ld      hl,l073b        ; Set integer random
  17677. l64bf:
  17678.         ld      b,0ah
  17679. l64c1:
  17680.         jp      StCALL_         ; Set CALL RANDOM
  17681. ;
  17682. ; Function IORESULT
  17683. ;
  17684. l64c4:
  17685.         ld      hl,l1ff1
  17686.         jr      l64bf
  17687. ;
  17688. ; Function EOF(FileVar)
  17689. ;
  17690. l64c9:
  17691.         call    l65f7
  17692.         ld      hl,l6615
  17693.         call    l59e9
  17694. l64d2:
  17695.         ld      b,0bh
  17696.         ret
  17697. ;
  17698. ; Function SEEKEOF(FileVar)
  17699. ;
  17700. l64d5:
  17701.         ld      hl,l17e1
  17702.         jr      l64e2
  17703. ;
  17704. ; Function SEEKEOLN(FileVar)
  17705. ;
  17706. l64da:
  17707.         ld      hl,l17d7
  17708.         jr      l64e2
  17709. ;
  17710. ; Function EOLN(TextFileVar)
  17711. ;
  17712. l64df:
  17713.         ld      hl,l17dc
  17714. l64e2:
  17715.         push    hl
  17716.         call    l65f7
  17717.         cp      6
  17718.         call    ErrNZ
  17719.         db      _MustTextFile
  17720.         pop     hl
  17721.         call    StCALL_         ; Set CALL <eoln>
  17722.         jr      l64d2
  17723. ;
  17724. ; Function FILEPOS(FileVar)
  17725. ;
  17726. l64f2:
  17727.         ld      hl,l1a55
  17728.         ld      de,l1a55
  17729.         jr      l6500
  17730. ;
  17731. ; Function FILESIZE(FileVar)
  17732. ;
  17733. l64fa:
  17734.         ld      hl,l1a5d
  17735.         ld      de,l1a5d
  17736. l6500:
  17737.         push    hl
  17738.         push    de
  17739.         call    l65f7
  17740.         pop     de
  17741.         pop     hl
  17742.         cp      6
  17743.         call    ErrZ
  17744.         db      _IllTxtFile
  17745.         cp      5
  17746.         jr      z,l64bf
  17747.         ex      de,hl
  17748.         jr      l64bf
  17749. ;
  17750. ; Function MEMAVAIL
  17751. ;
  17752. l6514:
  17753.         ld      hl,l1e3d
  17754.         jr      l64bf
  17755. ;
  17756. ; Function MAXAVAIL
  17757. ;
  17758. l6519:
  17759.         ld      hl,l1e44
  17760.         jr      l64bf
  17761. ;
  17762. ; Procedure BIOS(Integer,Integer)
  17763. ; Function BIOSHL(Integer,Integer)
  17764. ;
  17765. l651e:
  17766.         db      skip
  17767. ;
  17768. ; Function BIOS(Integer,Integer)
  17769. ;
  17770. l651f:
  17771.         xor     a
  17772.         push    af
  17773.         call    l6f66           ; Verify (
  17774.         call    l5e97
  17775.         call    StPUSH          ; Set PUSH HL
  17776.         call    l6f13           ; Test ,
  17777.         jr      nz,l6538        ; Nope
  17778.         call    l5e97
  17779.         call    StImm           ; Set sequence
  17780.         db      a_L51
  17781. s_I51:
  17782.         LD      B,H
  17783.         LD      C,L
  17784. a_L51   equ     $-s_I51
  17785. l6538:
  17786.         call    StImm           ; Set POP DE
  17787.         db      a_L52
  17788. s_I52:
  17789.         POP     DE
  17790. a_L52   equ     $-s_I52
  17791.         ld      hl,l1fea
  17792. l6540:
  17793.         call    l6f6e           ; Verify )
  17794.         call    StCALL_         ; Set CALL BIOS
  17795.         pop     af
  17796.         ld      b,0ah
  17797.         or      a
  17798.         ret     nz
  17799.         call    StImm           ; Set sequence
  17800.         db      a_L53
  17801. s_I53:
  17802.         LD      L,A
  17803.         LD      H,0
  17804. a_L53   equ     $-s_I53
  17805.         ret
  17806. ;
  17807. ; Procedure BDOS(Integer,Integer)
  17808. ; Function BDOSHL(Integer,Integer)
  17809. ;
  17810. l6553:
  17811.         db      skip
  17812. ;
  17813. ; Function BDOS(Integer,Integer)
  17814. ;
  17815. l6554:
  17816.         xor     a
  17817.         push    af
  17818.         call    l6f66           ; Verify (
  17819.         call    l5e97
  17820.         call    StPUSH          ; Set PUSH HL
  17821.         call    l6f13           ; Test ,
  17822.         jr      nz,l656c        ; Nope
  17823.         call    l5e97
  17824.         call    StImm           ; Set EX DE,HL
  17825.         db      a_L54
  17826. s_I54:
  17827.         EX      DE,HL
  17828. a_L54   equ     $-s_I54
  17829. l656c:
  17830.         call    StImm           ; Set POP BC
  17831.         db      a_L55
  17832. s_I55:
  17833.         POP     BC
  17834. a_L55   equ     $-s_I55
  17835.         ld      hl,BDOS
  17836.         jr      l6540
  17837. ;
  17838. ; Function ADDR(Var)
  17839. ;
  17840. l6576:
  17841.         call    l6f66           ; Verify (
  17842.         ld      bc,256*5+0
  17843.         call    FndLABEL
  17844.         jr      z,l6589
  17845.         ld      bc,256*6+0
  17846.         call    FndLABEL
  17847.         jr      nz,l6594
  17848. l6589:
  17849.         dec     hl
  17850.         dec     hl
  17851.         ld      d,(hl)
  17852.         dec     hl
  17853.         ld      e,(hl)
  17854.         ex      de,hl
  17855. l658f:
  17856.         call    StLD.HL         ; Set LD HL,val16
  17857.         jr      l6597
  17858. l6594:
  17859.         call    l677f
  17860. l6597:
  17861.         call    l6f6e           ; Verify )
  17862.         ld      b,0ah
  17863.         ret
  17864. ;
  17865. ; Function SIZEOF(Var)
  17866. ;
  17867. l659d:
  17868.         call    l6f66           ; Verify (
  17869.         ld      bc,256*3+0
  17870.         call    FndLABEL
  17871.         jr      nz,l65b1
  17872.         ld      d,(hl)
  17873.         dec     hl
  17874.         ld      e,(hl)
  17875.         ex      de,hl
  17876.         call    l5287           ; Get name
  17877.         jr      l65ba
  17878. l65b1:
  17879.         push    iy
  17880.         call    l677f
  17881.         pop     hl
  17882.         call    ChkChn          ; Check chaining
  17883. l65ba:
  17884.         ld      hl,(l7b62)      ; Get length of type
  17885.         jr      l658f
  17886. ;
  17887. ; Function PORT(Integer)
  17888. ;
  17889. l65bf:
  17890.         call    l65d5
  17891.         call    StImm           ; Set sequence
  17892.         db      a_L56
  17893. s_I56:
  17894.         LD      C,L
  17895.         IN      L,(C)
  17896. a_L56   equ     $-s_I56
  17897.         ret
  17898. ;
  17899. ; Function STACKPTR
  17900. ;
  17901. l65ca:
  17902.         call    StImm           ; Set sequence
  17903.         db      a_L57
  17904. s_I57:
  17905.         LD      HL,0
  17906.         ADD     HL,SP
  17907. a_L57   equ     $-s_I57
  17908.         ld      b,0ah
  17909.         ret
  17910. l65d5:
  17911.         call    l6f30           ; Verify [
  17912.         call    l5e97
  17913.         jp      l6f38           ; Verify ]
  17914. l65de:
  17915.         call    l6f66           ; Verify (
  17916.         call    l5e97
  17917. l65e4:
  17918.         jp      l6f6e           ; Verify )
  17919. l65e7:
  17920.         call    l6f66           ; Verify (
  17921.         call    l5ea2
  17922.         jr      l65e4
  17923. l65ef:
  17924.         call    l6f66           ; Verify (
  17925.         call    l5ebb
  17926.         jr      l65e4
  17927. l65f7:
  17928.         call    l6f1b           ; Test (
  17929.         jr      z,l6608         ; Yeap
  17930.         ld      hl,l00c2
  17931.         call    StLD.HL         ; Set LD HL,val16
  17932.         ld      a,_TxtF
  17933.         ld      (l7b5c),a       ; Set TEXT
  17934.         ret
  17935. l6608:
  17936.         call    l5a17
  17937.         call    ErrNZ
  17938.         db      _FileVarExp
  17939.         push    af
  17940.         call    l6f6e           ; Verify )
  17941.         pop     af
  17942.         ret
  17943. l6615: ;eof procedures
  17944.         dw      l1a49           ; Record file
  17945.         dw      l17e6           ; Text file
  17946.         dw      l1a49           ; Untyped file
  17947.         ;ld     c,c
  17948.         ;ld     a,(de)
  17949.         ;and    17h
  17950.         ;ld     c,c
  17951.         ;ld     a,(de)
  17952. ;
  17953. ;
  17954. ;
  17955. l661b:
  17956.         ld      a,(Envir1)
  17957.         ld      c,a
  17958.         ld      hl,(l7b58)      ; Get value
  17959.         ld      a,(l7b5c)       ; Get type
  17960.         cp      _Set
  17961.         jr      nz,l6634
  17962.         call    l6734
  17963.         ld      hl,l0623
  17964.         ld      de,l0612
  17965.         jr      l6648           ; Assign set variable
  17966. l6634:
  17967.         cp      _String
  17968.         jr      nz,l665e
  17969.         ld      a,(l7b62)       ; Get length of type
  17970.         dec     a
  17971.         ld      h,a
  17972.         ld      l,6
  17973.         call    writeword_hl_addriy
  17974.         ld      hl,l0601        ; Assign string from stack
  17975.         ld      de,l05e2        ; Assign string from stack
  17976. l6648:
  17977.         dec     c
  17978.         jr      z,l665b
  17979.         ex      de,hl
  17980. l664c:
  17981.         ld      a,_LD.HL
  17982.         inc     c
  17983.         jr      z,l6653
  17984.         ld      a,_LD_a_HL
  17985. l6653:
  17986.         push    hl
  17987.         ld      hl,(l7b58)      ; Get value
  17988.         call    StCode
  17989.         pop     hl
  17990. l665b:
  17991.         jp      StCALL_         ; Set CALL <call>
  17992. l665e:
  17993.         cp      _Real
  17994.         jr      nz,l6672
  17995.         call    StImm           ; Set EXX
  17996.         db      a_L58
  17997. s_I58:
  17998.         EXX
  17999. a_L58   equ     $-s_I58
  18000.         ld      hl,l05d1        ; Save real number
  18001.         dec     c
  18002.         jr      nz,l664c
  18003.         call    StPOP           ; Set POP HL
  18004.         jr      l665b
  18005. l6672:
  18006.         cp      _Ptr
  18007.         jr      z,l669d
  18008.         ld      a,(l7b9e)       ; Get local options
  18009.         bit     _Ropt,a         ; Test $R+
  18010.         jr      z,l669d         ; Nope
  18011.         ld      hl,(l7b5e)      ; Get lo set limit
  18012.         ld      de,(l7b60)      ; Get hi set limit
  18013.         inc     de
  18014.         or      a
  18015.         sbc     hl,de
  18016.         add     hl,de
  18017.         jr      z,l669d
  18018.         dec     de
  18019.         call    StLD.DE         ; Set LD DE,val16
  18020.         ex      de,hl
  18021.         or      a
  18022.         sbc     hl,de
  18023.         inc     hl
  18024.         call    StLD.BC
  18025.         ld      hl,l0656
  18026.         call    StCALL_         ; Index check on compiler directive {$R+}
  18027. l669d:
  18028.         dec     c
  18029.         jr      nz,l66b7
  18030.         call    StImm           ; Set sequence
  18031.         db      a_L59
  18032. s_I59:
  18033.         EX      DE,HL
  18034.         POP     HL
  18035. a_L59   equ     $-s_I59
  18036. l66a6:
  18037.         call    StImm           ; Set LD (HL),E
  18038.         db      a_L60
  18039. s_I60:
  18040.         LD      (HL),E
  18041. a_L60   equ     $-s_I60
  18042.         ld      a,(l7b62)       ; Get length of type
  18043.         dec     a
  18044.         ret     z
  18045.         call    StImm           ; Set sequence
  18046.         db      a_L61
  18047. s_I61:
  18048.         INC     HL
  18049.         LD      (HL),D
  18050. a_L61   equ     $-s_I61
  18051.         ret
  18052. l66b7:
  18053.         ld      hl,(l7b58)      ; Get value
  18054.         inc     c
  18055.         jr      nz,l66cf
  18056.         ld      a,(l7b62)       ; Get length of type
  18057.         dec     a
  18058.         ld      a,_LDHL_a
  18059.         jr      nz,l66cc
  18060.         call    StImm           ; Set LD A,L
  18061.         db      a_L62
  18062. s_I62:
  18063.         LD      A,L
  18064. a_L62   equ     $-s_I62
  18065.         ld      a,_LDA_a
  18066. l66cc:
  18067.         jp      StCode
  18068. l66cf:
  18069.         call    StImm           ; Set sequence
  18070.         db      a_L63
  18071. s_I63:
  18072.         EX      DE,HL
  18073.         db      _LD_a_HL
  18074. a_L63   equ     $-s_I63
  18075.         call    writeword_hl_addriy
  18076.         jr      l66a6
  18077. l66da:
  18078.         ld      a,(l7b5c)       ; Get type
  18079.         cp      _Integ
  18080.         jr      nc,l6701
  18081.         cp      _Ptr
  18082.         jr      z,l6701
  18083.         push    af
  18084.         call    l678b
  18085.         pop     af
  18086.         ld      hl,l052c        ; Set load real
  18087.         cp      _Real
  18088.         jr      z,l66fe
  18089.         ld      hl,l053a        ; move string to stack
  18090.         cp      _String
  18091.         jr      z,l66fe
  18092.         call    l6734
  18093.         ld      hl,l055d        ; Push set onto stack
  18094. l66fe:
  18095.         jp      StCALL_         ; Set CALL <set>
  18096. l6701:
  18097.         ld      a,(l7bbd)
  18098.         or      a
  18099.         jr      nz,l671b
  18100.         ld      a,_LD_a_HL
  18101.         ld      hl,(l7bbe)
  18102.         call    StCode
  18103.         ld      a,(l7b62)       ; Get length of type
  18104.         dec     a
  18105.         ret     nz
  18106. l6714:
  18107.         call    StImm           ; Set LD H,0
  18108.         db      a_L64
  18109. s_I64:
  18110.         LD      H,0
  18111. a_L64   equ     $-s_I64
  18112.         ret
  18113. l671b:
  18114.         call    l678b
  18115.         ld      a,(l7b62)       ; Get length of type
  18116.         dec     a
  18117.         jr      nz,l672b
  18118.         call    StImm           ; Set LD L,(HL)
  18119.         db      a_L65
  18120. s_I65:
  18121.         LD      L,(HL)
  18122. a_L65   equ     $-s_I65
  18123.         jr      l6714
  18124. l672b:
  18125.         call    StImm           ; Set sequence
  18126.         db      a_L66
  18127. s_I66:
  18128.         LD      E,(HL)
  18129.         INC     HL
  18130.         LD      D,(HL)
  18131.         EX      DE,HL
  18132. a_L66   equ     $-s_I66
  18133.         ret
  18134. l6734:
  18135.         ld      hl,(l7b5e)      ; Get lo set limit
  18136.         call    l5271           ; Load name
  18137.         ld      hl,(l7b62)      ; Get length of type
  18138.         ld      a,(l7b6b)
  18139.         rra
  18140.         rra
  18141.         rra
  18142.         and     1fh
  18143.         ld      h,a
  18144.         jp      StLD.BC
  18145. l6749:
  18146.         call    GetConst                ; Get constant
  18147.         jr      nz,l677f
  18148.         ld      a,b
  18149.         cp      8
  18150.         call    ErrNZ
  18151.         db      _IllConst
  18152.         ld      l,18h
  18153.         ld      h,c
  18154.         call    writeword_hl_addriy
  18155.         ld      (l7b58),iy      ; Set value
  18156.         ld      a,_Array
  18157.         ld      (l7b5c),a       ; Set ARRAY
  18158.         ld      hl,l74db+7
  18159.         ld      (l7b5e),hl      ; Set lo set limit
  18160.         ld      hl,l0000
  18161.         ld      (l7b60),hl      ; Reset hi set limit
  18162.         ld      l,c
  18163.         ld      (l7b62),hl      ; Set length of type
  18164.         call    StConst         ; Store string
  18165.         ld      a,_LD.HL
  18166.         ld      hl,(l7b58)      ; Get value
  18167.         jp      StCode
  18168. l677f:
  18169.         call    l6787
  18170.         ret     z
  18171.         call    ERROR
  18172.         db      _Undef
  18173. l6787:
  18174.         call    l67b2
  18175.         ret     nz
  18176. l678b:
  18177.         ld      a,(l7bbd)
  18178.         ld      hl,(l7bbe)
  18179.         bit     1,a
  18180.         jr      nz,l67a2
  18181.         bit     0,a
  18182.         ld      a,_LD.HL
  18183.         jr      z,l679d
  18184.         ld      a,_LD_a_HL
  18185. l679d:
  18186.         call    StCode
  18187.         jr      l67b0
  18188. l67a2:
  18189.         bit     0,a
  18190.         jr      nz,l67b0
  18191.         ld      a,_LD.DE
  18192.         call    StCode
  18193.         call    StImm           ; Set ADD HL,DE
  18194.         db      a_L67
  18195. s_I67:
  18196.         ADD     HL,DE
  18197. a_L67   equ     $-s_I67
  18198. l67b0:
  18199.         xor     a
  18200.         ret
  18201. l67b2:
  18202.         call    l680c
  18203.         jr      z,l67d9
  18204.         ld      bc,256*4+0
  18205.         call    FndLABEL
  18206.         jr      nz,l67ed
  18207.         call    l5276
  18208.         ld      a,(Envir1)
  18209.         or      a
  18210.         ld      a,'!'
  18211.         ld      b,0
  18212.         jr      z,l67cf
  18213.         ld      a,'*'
  18214.         inc     b
  18215. l67cf:
  18216.         ld      hl,l7bbd
  18217.         ld      (hl),b
  18218.         ld      hl,(l7b58)      ; Get value
  18219.         ld      (l7bbe),hl
  18220. l67d9:
  18221.         call    l683a
  18222.         jr      z,l67d9
  18223.         call    l6931
  18224.         jr      z,l67d9
  18225.         call    l6974
  18226.         jr      z,l67d9
  18227.         call    l699f
  18228.         xor     a
  18229.         ret
  18230. l67ed:
  18231.         call    FindStr         ; Find MEM
  18232.         dw      l78fa
  18233.         ret     nz              ; Nope
  18234.         call    l65d5
  18235.         ld      a,_Integ
  18236.         ld      (l7b5c),a       ; Set INTEGER
  18237.         ld      hl,l0001
  18238.         ld      (l7b62),hl      ; Set length of type
  18239.         dec     l
  18240.         ld      (l7b5e),hl      ; Set lo set limit
  18241.         dec     l
  18242.         ld      (l7b60),hl      ; Set hi set limit
  18243.         jp      l6903
  18244. l680c:
  18245.         ld      a,(l7bc9)
  18246.         ld      b,a
  18247. l6810:
  18248.         dec     b
  18249.         ret     m
  18250.         push    bc
  18251.         ld      e,b
  18252.         ld      d,0
  18253.         ld      hl,l7bcc
  18254.         add     hl,de
  18255.         ld      a,(hl)
  18256.         ld      c,a
  18257.         ld      b,4
  18258.         call    FndLABEL
  18259.         pop     bc
  18260.         jr      nz,l6810
  18261.         push    hl
  18262.         ld      a,b
  18263.         add     a,a
  18264.         ld      e,a
  18265.         ld      d,0
  18266.         ld      hl,(l7bca)
  18267.         add     hl,de
  18268.         ld      (l7bbe),hl
  18269.         ld      hl,l7bbd
  18270.         ld      (hl),1
  18271.         pop     hl
  18272.         jp      l6948
  18273. l683a:
  18274.         ld      a,(l7b5c)       ; Get type
  18275.         cp      _Array
  18276.         ret     nz
  18277.         call    l6ee0
  18278.         ret     nz
  18279.         call    l678b
  18280. l6847:
  18281.         call    StPUSH          ; Set PUSH HL
  18282.         call    l5e84
  18283.         ld      hl,(l7b60)      ; Get hi set limit
  18284.         call    l5271           ; Load name
  18285.         ld      a,(l7b69)
  18286.         cp      b
  18287.         call    ErrNZ
  18288.         db      _InvType
  18289.         ld      hl,(l7b6b)
  18290.         ld      a,h
  18291.         or      a
  18292.         jr      nz,l6874
  18293.         ld      a,l
  18294.         cp      4
  18295.         jr      nc,l6888
  18296. l6867:
  18297.         or      a
  18298.         jr      z,l6893
  18299.         push    af
  18300.         call    StImm           ; Set DEC HL
  18301.         db      a_L68
  18302. s_I68:
  18303.         DEC     HL
  18304. a_L68   equ     $-s_I68
  18305.         pop     af
  18306.         dec     a
  18307.         jr      l6867
  18308. l6874:
  18309.         inc     a
  18310.         jr      nz,l6888
  18311.         ld      a,l
  18312.         cp      0fdh
  18313.         jr      c,l6888
  18314. l687c:
  18315.         push    af
  18316.         call    StImm           ; Set INC HL
  18317.         db      a_L69
  18318. s_I69:
  18319.         INC     HL
  18320. a_L69   equ     $-s_I69
  18321.         pop     af
  18322.         inc     a
  18323.         jr      nz,l687c
  18324.         jr      l6893
  18325. l6888:
  18326.         call    NegateInt
  18327.         call    StLD.DE         ; Set LD DE,val16
  18328.         call    StImm           ; Set ADD HL,DE
  18329.         db      a_L70
  18330. s_I70:
  18331.         ADD     HL,DE
  18332. a_L70   equ     $-s_I70
  18333. l6893:
  18334.         ld      a,(l7b9e)       ; Get local options
  18335.         bit     _Ropt,a         ; Test $R+
  18336.         jr      z,l68ae
  18337.         ld      hl,(l7b6d)      ; Get last memory address
  18338.         ld      de,(l7b6b)
  18339.         or      a
  18340.         sbc     hl,de
  18341.         inc     hl
  18342.         call    StLD.DE         ; Set LD DE,val16
  18343.         ld      hl,l064c
  18344.         call    StCALL_         ; Index check on compiler directive {$R+}
  18345. l68ae:
  18346.         ld      hl,(l7b5e)      ; Get lo set limit
  18347.         call    l5287           ; Get name
  18348.         ld      hl,(l7b62)      ; Get length of type
  18349.         ld      a,h
  18350.         or      a
  18351.         jr      nz,l68d8
  18352.         ld      a,l
  18353.         dec     a
  18354.         jr      z,l68ed
  18355.         dec     a
  18356.         jr      nz,l68c9
  18357.         call    StImm           ; Set ADD HL,HL
  18358.         db      a_L71
  18359. s_I71:
  18360.         ADD     HL,HL
  18361. a_L71   equ     $-s_I71
  18362.         jr      l68ed
  18363. l68c9:
  18364.         cp      4
  18365.         jr      nz,l68d8
  18366.         call    StImm           ; Set sequence
  18367.         db      a_L72
  18368. s_I72:
  18369.         ADD     HL,HL
  18370.         LD      E,L
  18371.         LD      D,H
  18372.         ADD     HL,HL
  18373.         ADD     HL,DE
  18374. a_L72   equ     $-s_I72
  18375.         jr      l68ed
  18376. l68d8:
  18377.         ld      a,(l7b9e)       ; Get local options
  18378.         bit     _Xopt,a         ; Test $X+
  18379.         jr      nz,l68ea        ; Yeap
  18380.         call    StLD.DE         ; Set LD DE,val16
  18381.         ld      hl,l06f5        ; Set integer multiply
  18382.         call    StCALL_
  18383.         jr      l68ed
  18384. l68ea:
  18385.         call    l690a
  18386. l68ed:
  18387.         call    StImm           ; Set sequence
  18388.         db      a_L73
  18389. s_I73:
  18390.         POP     DE
  18391.         ADD     HL,DE
  18392. a_L73   equ     $-s_I73
  18393.         ld      a,(l7b5c)       ; Get type
  18394.         cp      _Array
  18395.         jr      nz,l6900
  18396.         call    l6f13           ; Test ,
  18397.         jp      z,l6847         ; Yeap
  18398. l6900:
  18399.         call    l6f38           ; Verify ]
  18400. l6903:
  18401.         ld      a,3
  18402.         ld      (l7bbd),a
  18403.         xor     a
  18404.         ret
  18405. l690a:
  18406.         ld      b,1
  18407. l690c:
  18408.         ld      a,h
  18409.         or      a
  18410.         jr      nz,l6914
  18411.         ld      a,l
  18412.         dec     a
  18413.         jr      z,l6927
  18414. l6914:
  18415.         bit     0,l
  18416.         jr      z,l691c
  18417.         call    StPUSH          ; Set PUSH HL
  18418.         inc     b
  18419. l691c:
  18420.         call    StImm           ; Set ADD HL,HL
  18421.         db      a_L74
  18422. s_I74:
  18423.         ADD     HL,HL
  18424. a_L74   equ     $-s_I74
  18425.         srl     h
  18426.         rr      l
  18427.         jr      l690c
  18428. l6927:
  18429.         dec     b
  18430.         ret     z
  18431.         call    StImm           ; Set sequence
  18432.         db      a_L75
  18433. s_I75:
  18434.         POP     DE
  18435.         ADD     HL,DE
  18436. a_L75   equ     $-s_I75
  18437.         jr      l6927
  18438. l6931:
  18439.         ld      a,(l7b5c)       ; Get type
  18440.         cp      _Record
  18441.         ret     nz
  18442.         call    l6f17
  18443.         ret     nz
  18444.         ld      a,(l7b5d)
  18445.         ld      c,a
  18446.         ld      b,4
  18447.         call    FndLABEL
  18448.         call    ErrNZ
  18449.         db      _Undef
  18450. l6948:
  18451.         call    l5276
  18452.         ld      hl,(l7b58)      ; Get value
  18453.         ld      a,h
  18454.         or      l
  18455.         ret     z
  18456.         ld      hl,l7bbd
  18457.         bit     0,(hl)
  18458.         jr      z,l6967
  18459.         push    hl
  18460.         call    l678b
  18461.         pop     hl
  18462.         ld      (hl),2
  18463.         ld      hl,(l7b58)      ; Get value
  18464.         ld      (l7bbe),hl
  18465.         xor     a
  18466.         ret
  18467. l6967:
  18468.         ld      hl,(l7bbe)
  18469.         ld      de,(l7b58)      ; Get value
  18470.         add     hl,de
  18471.         ld      (l7bbe),hl
  18472.         xor     a
  18473.         ret
  18474. l6974:
  18475.         ld      a,(l7b5c)       ; Get type
  18476.         cp      _Ptr
  18477.         ret     nz
  18478.         call    l6f27
  18479.         ret     nz
  18480.         ld      hl,l7bbd
  18481.         ld      a,(hl)
  18482.         or      a
  18483.         jr      nz,l6988
  18484.         inc     (hl)
  18485.         jr      l6997
  18486. l6988:
  18487.         push    hl
  18488.         call    l678b
  18489.         pop     hl
  18490.         ld      (hl),3
  18491.         call    StImm           ; Set sequence
  18492.         db      a_L76
  18493. s_I76:
  18494.         LD      E,(HL)
  18495.         INC     HL
  18496.         LD      D,(HL)
  18497.         EX      DE,HL
  18498. a_L76   equ     $-s_I76
  18499. l6997:
  18500.         ld      hl,(l7b5e)      ; Get lo set limit
  18501.         call    l5287           ; Get name
  18502.         xor     a
  18503.         ret
  18504. l699f:
  18505.         ld      a,(l7b5c)       ; Get type
  18506.         cp      _String
  18507.         ret     nz
  18508.         call    l6ee0
  18509.         ret     nz
  18510.         call    l678b
  18511.         call    StPUSH          ; Set PUSH HL
  18512.         ld      hl,(l7b62)      ; Get length of type
  18513.         push    hl
  18514.         call    l5e97
  18515.         pop     hl
  18516.         ld      a,(l7b9e)       ; Get local options
  18517.         bit     _Ropt,a         ; Test $R+
  18518.         jr      z,l69c7         ; Nope
  18519.         call    StLD.DE         ; Set LD DE,val16
  18520.         ld      hl,l064c
  18521.         call    StCALL_         ; Index check on compiler directive {$R+}
  18522. l69c7:
  18523.         call    StImm           ; Set sequence
  18524.         db      a_L77
  18525. s_I77:
  18526.         POP     DE
  18527.         ADD     HL,DE
  18528. a_L77   equ     $-s_I77
  18529.         call    l6f38           ; Verify ]
  18530.         ld      a,_Char
  18531.         ld      (l7b5c),a       ; Set CHAR
  18532.         ld      hl,l0001
  18533.         ld      (l7b62),hl      ; Set length of type
  18534.         dec     hl
  18535.         ld      (l7b5e),hl      ; Set lo set limit
  18536.         dec     l
  18537.         ld      (l7b60),hl      ; Set hi set limit
  18538.         ld      a,3
  18539.         ld      (l7bbd),a
  18540.         xor     a
  18541.         ret
  18542. ;
  18543. ; Get constant
  18544. ;
  18545. _GetConst:
  18546.         call    GetConst                ; Get constant
  18547.         ret     z
  18548.         call    ERROR
  18549.         db      _Undef
  18550. ;
  18551. ; Get integer constant
  18552. ;
  18553. _GetIntC:
  18554.         call    _GetConst               ; Get constant
  18555.         ld      a,b
  18556.         cp      0ah ;_Integ
  18557.         ret     z
  18558.         call    ERROR
  18559.         db      _IntConst
  18560. ;
  18561. ; Get string constant
  18562. ;
  18563. _GetStrC:
  18564.         call    _GetConst               ; Get constant
  18565.         ld      a,b
  18566.         cp      8 ;_String
  18567.         ret     z
  18568.         cp      0ch ;_Char
  18569.         call    ErrNZ
  18570.         db      _StrgConExp
  18571.         ld      b,8 ;_String
  18572.         ret
  18573. ;
  18574. ; Get constant
  18575. ;
  18576. GetConst:
  18577.         call    GetSign
  18578.         push    de
  18579.         call    GetLabType
  18580.         pop     de
  18581.         jr      z,NegateNum
  18582.         inc     e
  18583.         dec     e
  18584.         call    ErrNZ
  18585.         db      _IntRealCexp
  18586.         dec     e
  18587.         ret
  18588. NegateNum:
  18589.         call    ChkNumSign
  18590.         ret     z
  18591.         ld      a,b
  18592.         cp      9 ;_Real
  18593.         jr      nz,NegateInt
  18594.         exx
  18595.         ld      a,b
  18596.         xor     80h
  18597.         ld      b,a
  18598.         exx
  18599.         xor     a
  18600.         ret
  18601. NegateInt:
  18602.         ld      a,h
  18603.         cpl
  18604.         ld      h,a
  18605.         ld      a,l
  18606.         cpl
  18607.         ld      l,a
  18608.         inc     hl
  18609.         xor     a
  18610.         ret
  18611. GetSign:
  18612.         ld      e,0ffh
  18613.         ld      a,(ix+0)
  18614.         cp      '-'
  18615.         jr      z,l6a47
  18616.         inc     e
  18617.         cp      '+'
  18618.         ret     nz
  18619.         inc     e
  18620. l6a47:
  18621.         jp      NewLine         ; Process line
  18622. ChkNumSign:
  18623.         inc     e
  18624.         dec     e
  18625.         ret     z
  18626.         ld      a,b
  18627.         cp      0ah ;_Integ
  18628.         jr      z,ChkNumSign_valid
  18629.         cp      9 ;_Real
  18630.         jr      nz,ChkNumSign_bad
  18631. ChkNumSign_valid:
  18632.         dec     e
  18633.         ret
  18634. ChkNumSign_bad:
  18635.         call    ERROR
  18636.         db      _IntRealCexp
  18637. GetLabType:
  18638.         call    GetConstType            ; Sample constant
  18639.         ret     z               ; Got one
  18640.         ld      bc,256*2+0
  18641.         call    FndLABEL
  18642.         ret     nz
  18643.         ld      b,(hl)
  18644.         ld      a,b
  18645.         dec     hl
  18646.         cp      0ah ;_Integ
  18647.         jr      c,GetLabType_noOrd
  18648.         ld      d,(hl)
  18649.         dec     hl
  18650.         ld      e,(hl)
  18651.         ex      de,hl
  18652.         xor     a
  18653.         ret
  18654. GetLabType_noOrd:
  18655.         cp      9 ;_Real
  18656.         jr      nz,GetLabType_noReal
  18657.         push    bc
  18658.         ld      b,(hl)
  18659.         dec     hl
  18660.         ld      c,(hl)
  18661.         dec     hl
  18662.         ld      d,(hl)
  18663.         dec     hl
  18664.         ld      e,(hl)
  18665.         dec     hl
  18666.         ld      a,(hl)
  18667.         dec     hl
  18668.         ld      l,(hl)
  18669.         ld      h,a
  18670.         exx
  18671.         pop     bc
  18672.         ret
  18673. GetLabType_noReal:
  18674.         ld      c,(hl)
  18675.         ld      de,l7a57
  18676.         push    bc
  18677.         inc     c
  18678. GetLabType_cpyStr:
  18679.         dec     c
  18680.         jr      z,GetLabType_ex
  18681.         dec     hl
  18682.         ld      a,(hl)
  18683.         ld      (de),a
  18684.         inc     de
  18685.         jr      GetLabType_cpyStr
  18686. GetLabType_ex:
  18687.         pop     bc
  18688.         ret
  18689. ;
  18690. ; Sample constant - Z set indicates constant
  18691. ;
  18692. ; Reg B holds type of constant
  18693. ; Reg C holds length of constant
  18694. ;
  18695. GetConstType:
  18696.         ld      a,(ix+0)        ; Get character
  18697.         cp      ''''            ; Test string
  18698.         jr      z,GetConstType_strg
  18699.         cp      '^'             ; Test control character prefix
  18700.         jr      z,GetConstType_strg
  18701.         cp      '#'             ; Test character prefix
  18702.         jr      nz,GetConstType_noStrg
  18703. GetConstType_strg:
  18704.         ld      hl,l7a57        ; Init parameter buffer
  18705.         ld      c,0             ; Init length
  18706. GetConstType_chkMore:
  18707.         ld      a,(ix+0)
  18708.         cp      '^'             ; Test control character prefix
  18709.         jr      z,GetConstType_ctrChr
  18710.         cp      '#'             ; Test character prefix
  18711.         jr      z,GetConstType_chrPrfx
  18712.         cp      ''''            ; Test string
  18713.         jr      nz,GetConstType_ex
  18714. GetConstType_cpyStrg:
  18715.         inc     ix
  18716.         ld      a,(ix+0) ;Get character
  18717.         or      a
  18718.         call    ErrZ
  18719.         db      _StrConLong
  18720.         cp      ''''
  18721.         jr      nz,GetConstType_unp
  18722.         inc     ix
  18723.         ld      a,(ix+0) ;Get character
  18724.         cp      ''''
  18725.         jr      nz,GetConstType_chkMore
  18726. GetConstType_unp:
  18727.         ld      (hl),a
  18728.         inc     hl
  18729.         inc     c
  18730.         jr      GetConstType_cpyStrg
  18731. GetConstType_ctrChr:
  18732.         inc     ix
  18733.         ld      a,(ix+0) ;Get character
  18734.         call    doupcase                ; Convert to upper case
  18735.         or      a
  18736.         call    ErrZ
  18737.         db      _StrConLong
  18738.         xor     '@'
  18739.         inc     ix
  18740. GetConstType_sav:
  18741.         ld      (hl),a
  18742.         inc     hl
  18743.         inc     c
  18744.         jr      GetConstType_chkMore
  18745. GetConstType_chrPrfx:
  18746.         inc     ix
  18747.         push    bc
  18748.         push    hl
  18749.         call    cnv_int         ; Convert ASCII to integer
  18750.         ld      a,l
  18751.         pop     hl
  18752.         pop     bc
  18753.         call    ErrCY
  18754.         db      _IntegErr
  18755.         jr      GetConstType_sav
  18756. GetConstType_ex:
  18757.         ld      b,8 ;_String
  18758.         ld      a,c ; Get count
  18759.         dec     a   ; Test character
  18760.         jr      nz,GetConstType_getLine ; .. nope
  18761.         ld      h,a                ; .. clear HI
  18762.         ld      a,(l7a57)          ; .. get LO
  18763.         ld      l,a
  18764.         ld      b,0ch ;_Char    ; Change mode
  18765. GetConstType_getLine:
  18766.         jp      GetLine         ; Process line
  18767. GetConstType_noStrg:
  18768.         cp      '$'
  18769.         jr      z,GetConstType_hex
  18770.         call    IsItDigit       ; Test digit
  18771.         jr      nc,GetConstType_numb
  18772.         xor     a
  18773.         dec     a
  18774.         ret
  18775. GetConstType_numb:
  18776.         push    ix
  18777.         pop     de
  18778. GetConstType_wtNoNum:
  18779.         inc     de
  18780.         ld      a,(de)
  18781.         call    IsItDigit               ; Test digit
  18782.         jr      nc,GetConstType_wtNoNum
  18783.         call    doupcase                ; Convert to upper case
  18784.         cp      'E'
  18785.         jr      z,GetConstType_real
  18786.         cp      '.'
  18787.         jr      nz,GetConstType_hex
  18788.         inc     de
  18789.         ld      a,(de)
  18790.         cp      '.'
  18791.         jr      z,GetConstType_hex
  18792.         cp      ')'
  18793.         jr      z,GetConstType_hex
  18794. GetConstType_real:
  18795.         call    cnv_flp ; Convert to real
  18796.         call    ErrCY   ; Real constant error
  18797.         db      _RealErr
  18798.         exx              ; Real into alternate set
  18799.         ld      b,9 ;_Real ; .. set mode
  18800.         jr      GetConstType_getLine
  18801. GetConstType_hex:
  18802.         call    cnv_int         ; Convert ASCII to integer
  18803.         call    ErrCY
  18804.         db      _IntegErr
  18805.         ld      b,0ah
  18806.         jr      GetConstType_getLine
  18807. ;
  18808. ; Transfer immediate opcodes
  18809. ; Sequence starts with length
  18810. ;
  18811. StImm:
  18812.         ex      (sp),hl
  18813.         push    bc
  18814.         ld      b,(hl)          ; Get length
  18815.         inc     hl
  18816. StI_loop:
  18817.         ld      a,(hl)          ; Get byte
  18818.         call    writebyte_a_addriy              ; Store it
  18819.         inc     hl
  18820.         djnz    StI_loop
  18821.         pop     bc
  18822.         ex      (sp),hl
  18823.         ret
  18824. StLen:
  18825.         ld      a,c             ; Get byte
  18826.         call    writebyte_a_addriy              ; Store it
  18827. ;
  18828. ; Store string
  18829. ;
  18830. StConst:
  18831.         ld      hl,l7a57
  18832.         inc     c
  18833. StC_loop:
  18834.         dec     c
  18835.         ret     z
  18836.         ld      a,(hl)          ; Get character
  18837.         inc     hl
  18838.         call    writebyte_a_addriy              ; Store it
  18839.         jr      StC_loop
  18840. ;
  18841. ; Set PUSH HL
  18842. ;
  18843. StPUSH:
  18844.         ld      a,_PUSH.HL
  18845.         jr      writebyte_a_addriy
  18846. ;
  18847. ; Set POP HL
  18848. ;
  18849. StPOP:
  18850.         ld      a,_POP.HL
  18851.         jr      writebyte_a_addriy
  18852. ;
  18853. ; Set JP
  18854. ;
  18855. StJP:
  18856.         ld      a,_JP
  18857.         jr      writebyte_a_addriy
  18858. ;
  18859. ; Insert operand
  18860. ; ENTRY Reg DE holds operand
  18861. ; (Set word in reg DE)
  18862. ;
  18863. writeword_de_addriy:
  18864.         ld      a,e
  18865.         call    writebyte_a_addriy
  18866.         ld      a,d
  18867.         jr      writebyte_a_addriy
  18868. ;
  18869. ; Set JP WORD
  18870. ;
  18871. StJP_:
  18872.         ld      a,_JP
  18873.         jr      StCode
  18874. ;
  18875. ; Set CALL WORD
  18876. ;
  18877. StCALL_:
  18878.         ld      a,_CALL
  18879.         jr      StCode
  18880. ;
  18881. ; Set LD BC,WORD
  18882. ;
  18883. StLD.BC:
  18884.         ld      a,_LD.BC
  18885.         jr      StCode
  18886. ;
  18887. ; Set LD DE,WORD
  18888. ;
  18889. StLD.DE:
  18890.         ld      a,_LD.DE
  18891.         jr      StCode
  18892. ;
  18893. ; Set LD HL,WORD
  18894. ;
  18895. StLD.HL:
  18896.         ld      a,_LD.HL
  18897. ;
  18898. ; Insert opcodes in Accu, reg L and reg H
  18899. ;
  18900. StCode:
  18901.         call    writebyte_a_addriy
  18902. ;
  18903. ; Insert word in reg HL
  18904. ;
  18905. writeword_hl_addriy:
  18906.         ld      a,l
  18907.         call    writebyte_a_addriy
  18908.         ld      a,h
  18909. ;
  18910. ; Insert byte in Accu
  18911. ;
  18912. writebyte_a_addriy:
  18913.         push    bc
  18914.         ld      b,a
  18915.         ld      a,(CmpTyp)      ; Get compile flag
  18916.         or      a               ; Test mode
  18917.         jr      nz,St__noSt     ; Searching or compiling       
  18918.         ld      (iy+0),b        ; Store byte into memory
  18919. St__noSt:
  18920.         inc     iy              ; Update PC
  18921.         or      a               ; Test compile to memory
  18922.         jr      z,St__skp               ; Yeap
  18923.         push    hl
  18924.         push    de
  18925.         dec     a               ; Test search
  18926.         jr      z,St__St                ; Nope ; .. compile to file
  18927.         push    iy
  18928.         pop     de
  18929.         dec     de
  18930.         ld      hl,(l00ce)      ; Get current PC
  18931.         or      a
  18932.         sbc     hl,de
  18933.         call    ErrZ
  18934.         db      _FndRTerr
  18935.         jr      St__pop
  18936. St__St:
  18937.         call    savebyte_b              ; Put byte to file
  18938. St__pop:
  18939.         pop     de
  18940.         pop     hl
  18941. St__skp:
  18942.         pop     bc
  18943. ;
  18944. ; Check enough memory
  18945. ;
  18946. ChkOvfl:
  18947.         push    hl
  18948.         push    de
  18949.         push    iy
  18950.         pop     de
  18951.         ld      a,(CmpTyp)      ; Get compile flag
  18952.         or      a
  18953.         jr      z,ChkOv.mem             ; Skip if compiling to memory
  18954.         ld      de,(MemsTop)    ; Get memory top
  18955.         dec     a
  18956.         jr      nz,ChkOv.mem
  18957.         ld      de,(COMsTop)    ; Get top of .COM file
  18958.         ld      a,(IncFlg)      ; Test memory read
  18959.         or      a
  18960.         jr      z,ChkOv.mem             ; Yeap
  18961.         ld      de,(INCsTop)
  18962. ChkOv.mem:
  18963.         ld      hl,(LabPtr)     ; Get label pointer
  18964.         scf
  18965.         sbc     hl,de
  18966.         call    ErrCY
  18967.         db      _CompOvfl
  18968.         push    iy
  18969.         pop     de
  18970.         ld      hl,(DataBeg)    ; Get start of data
  18971.         dec     h
  18972.         dec     h
  18973.         sbc     hl,de
  18974.         call    ErrCY
  18975.         db      _MemOvfl
  18976.         pop     de
  18977.         pop     hl
  18978.         ret
  18979. ;
  18980. ; Put byte in reg B to file
  18981. ;
  18982. savebyte_b:
  18983.         ld      hl,RRN_stat     ; Point to file access
  18984.         set     1,(hl)          ; Set write enabled
  18985.         bit     0,(hl)          ; Test re-read
  18986.         jr      z,SkpRdRRN              ; Nope
  18987.         res     0,(hl)          ; Clear it
  18988.         push    bc
  18989.         call    readrecord_TmpBuff              ; Re-read record
  18990.         pop     bc
  18991. SkpRdRRN:
  18992.         ld      a,(RecPtr)      ; Get record pointer
  18993.         ld      e,a
  18994.         ld      d,0
  18995.         ld      hl,TmpBuff
  18996.         add     hl,de           ; Build buffer address
  18997.         ld      (hl),b          ; Store byte
  18998.         inc     a               ; Advance record pointer
  18999.         jp      p,StToF__ex             ; Still within limits
  19000.         call    writerecord_TmpBuff             ; Write record
  19001.         ld      hl,(FFCB+_rrn)
  19002.         inc     hl              ; Advance record count
  19003.         ld      (FFCB+_rrn),hl
  19004.         xor     a
  19005. StToF__ex:
  19006.         ld      (RecPtr),a      ; Set record pointer
  19007.         ret
  19008. ;
  19009. ; Allocate space in reg DE
  19010. ;
  19011. VarAlloc:
  19012.         ld      hl,(DataBeg)    ; Get start of data
  19013.         or      a
  19014.         sbc     hl,de
  19015.         call    ErrCY
  19016.         db      _MemOvfl
  19017.         ld      (DataBeg),hl    ; Set start of data
  19018.         jr      ChkOvfl         ; Check enough memory
  19019. ;
  19020. ; Store back current PC to ^HL
  19021. ;
  19022. storeback_iy_to_addrhl:
  19023.         push    iy              ; Get PC
  19024.         pop     de
  19025. ;
  19026. ; Store back reg DE to ^HL
  19027. ;
  19028. storeback_de_to_addrhl:
  19029.         ld      a,(CmpTyp)      ; Get compile flag
  19030.         dec     a               ; Test compiling to memory
  19031.         jr      z,StBackMem             ; nope
  19032.         push    iy
  19033.         push    hl
  19034.         pop     iy
  19035.         call    writeword_de_addriy             ; Set word
  19036.         pop     iy
  19037.         ret
  19038. flushunfinished
  19039.         ld a,(RecPtr)   ; Get record pointer
  19040.         or a
  19041.         ret z
  19042.          push bc
  19043.          push de
  19044.          push hl
  19045.         ;ld a,h
  19046.         ;and l
  19047.         ;inc a ;-1=fake record number
  19048.         ;jr z,flushunfinished_skip
  19049.          call flushunfinishedpp
  19050. ;flushunfinished_skip
  19051. ;close, open to force flush???
  19052.         ;ld de,FFCB
  19053.         ;ld c,_close
  19054.         ;call _BDOS             ; BDOS with keep ix,iy
  19055.         ;ld de,FFCB
  19056.         ;ld c,_open
  19057.         ;call _BDOS             ; BDOS with keep ix,iy
  19058.          pop hl
  19059.          pop de
  19060.          pop bc
  19061.          ret
  19062. StBackMem:
  19063.          call flushunfinished
  19064.         push    bc
  19065.         push    de
  19066.         push    hl
  19067.         ld      hl,(MemsTop)    ; Get memory top
  19068.         ld      a,(BackLevel)   ; Get back fix level
  19069.         ld      b,a
  19070.         inc     b
  19071. l6c5e:
  19072.         dec     b
  19073.         jr      z,l6c84
  19074.         ld      e,(hl)
  19075.         inc     hl
  19076.         ld      d,(hl)
  19077.         ex      (sp),hl
  19078.         or      a
  19079.         sbc     hl,de
  19080.         add     hl,de
  19081.         ex      (sp),hl
  19082.         jr      c,l6c71
  19083.         inc     hl
  19084.         inc     hl
  19085.         inc     hl
  19086.         jr      l6c5e
  19087. l6c71:
  19088.         dec     hl
  19089.         ex      de,hl
  19090.         ld      l,b
  19091.         ld      h,0
  19092.         add     hl,hl
  19093.         add     hl,hl
  19094.         ld      b,h
  19095.         ld      c,l
  19096.         add     hl,de
  19097.         ld      d,h
  19098.         ld      e,l
  19099.         dec     hl
  19100.         inc     de
  19101.         inc     de
  19102.         inc     de
  19103.         lddr
  19104.         inc     hl
  19105. l6c84:
  19106.         pop     de
  19107.         ld      (hl),e
  19108.         inc     hl
  19109.         ld      (hl),d
  19110.         inc     hl
  19111.         pop     de
  19112.         ld      (hl),e
  19113.         inc     hl
  19114.         ld      (hl),d
  19115.         pop     bc
  19116.         ld      hl,BackLevel    ; Point to back fix level
  19117.         inc     (hl)
  19118.         ret     nz
  19119.         xor     a
  19120.         jr      ForceBack
  19121. ;
  19122. ; Fix back level
  19123. ;
  19124. FixBack:
  19125.         ld      a,(BackLevel)   ; Get back fix level
  19126.         or      a
  19127.         ret     z
  19128. ForceBack:
  19129.         push    bc
  19130.         push    de
  19131.         push    iy
  19132.         ld      b,a
  19133.         ld      hl,(MemsTop)    ; Get memory top
  19134. Back_Loop:
  19135.         push    bc
  19136.         ld      e,(hl)
  19137.         inc     hl
  19138.         ld      d,(hl)
  19139.         inc     hl
  19140.         push    hl
  19141.         ex      de,hl
  19142.         call    ChkChn          ; Check chaining
  19143.         pop     hl
  19144.         ld      b,(hl)
  19145.         inc     hl
  19146.         push    hl
  19147.         call    savebyte_b              ; Put byte to file
  19148.         pop     hl
  19149.         ld      b,(hl)
  19150.         inc     hl
  19151.         push    hl
  19152.         call    savebyte_b              ; Put byte to file
  19153.         pop     hl
  19154.         pop     bc
  19155.         djnz    Back_Loop
  19156.         pop     hl
  19157.         pop     de
  19158.         pop     bc
  19159. ;
  19160. ; Check chaining
  19161. ;
  19162. ChkChn:
  19163.          ld     a,(CmpTyp)      ; Get compile flag
  19164.          dec    a               ; Test compiling to memory
  19165.          call z,flushunfinished ;nope
  19166.         push    hl
  19167.         pop     iy
  19168.         ld      a,(CmpTyp)      ; Get compile flag
  19169.         dec     a               ; Test compiling to memory
  19170.         ret     nz              ; yes
  19171.         push    de
  19172.         push    bc
  19173.         ld      de,(CodePC)     ; Get code pointer
  19174.         or      a
  19175.         sbc     hl,de
  19176.         ld      a,l
  19177.         and     7fh
  19178.         ld      (RecPtr),a      ; Set record pointer
  19179.         add     hl,hl
  19180.         ld      l,h
  19181.         rla
  19182.         and     1
  19183.         ld      h,a
  19184.         ld      de,(RRN_off)    ; Get record base
  19185.         add     hl,de           ; Calculate new record
  19186.         ld      de,(FFCB+_rrn)
  19187.         or      a
  19188.         sbc     hl,de
  19189.         add     hl,de
  19190.         jr      z,Chk_sameRRN
  19191.         push    hl
  19192.         call    writerecord_TmpBuff             ; Write record
  19193.         pop     hl
  19194.         ld      (FFCB+_rrn),hl  ; Reset record
  19195. Chk_sameRRN:
  19196.         pop     bc
  19197.         pop     de
  19198.         ret
  19199.  
  19200. ;
  19201. ; Read random record from file
  19202. ; Read a record
  19203. ;
  19204. readrecord_TmpBuff:
  19205.          ;ld hl,(FFCB+_rrn)
  19206.          ;jr $
  19207.         ld      c,_rndrd ; .. load read function
  19208.         jr      l6d09    ; .. fall in read
  19209. ;
  19210. ; Write a record
  19211. ;
  19212. writerecord_TmpBuff:
  19213.         ld      hl,RRN_stat     ; Point to file access
  19214.         set     0,(hl)          ; Set re-read enabled
  19215.         bit     1,(hl)          ; Test record to be written
  19216.         ret     z               ; Nope
  19217.         res     1,(hl)          ; Reset it
  19218. flushunfinishedpp
  19219. ;write unfinished last sector???
  19220.         ld      c,_rndwr
  19221. l6d09:
  19222.         push    bc              ; Save function
  19223.         ld      de,TmpBuff
  19224.         ld      c,_setdma
  19225.         call    _BDOS           ; Set disk buffer
  19226.         pop     bc
  19227.         ld      de,FFCB
  19228.         call    _BDOS           ; Read or write record
  19229.       ret ;КОСТЫЛЬ!!! иначе lister не компилируется на диск (читает сектор за границей файла перед патчем и записью?)
  19230.         or      a
  19231.         ret     z
  19232.         ;dec    a
  19233.         ;ret    z
  19234.         ;cp     3
  19235.         ;ret    z
  19236.          cp 128 ;fail
  19237.          ret nz ;not fail
  19238.         call    ERROR
  19239.         db      _DskFull
  19240. ;
  19241. ; Save environment to stack
  19242. ;
  19243. SavEnv2:
  19244.         exx
  19245.         ld      de,Envir2
  19246.         jr      SavEnv7
  19247. ;
  19248. ; Save environment to stack
  19249. ;
  19250. l6d2a:
  19251.         exx
  19252.         ld      de,Envir1
  19253. SavEnv7:
  19254.         pop     hl
  19255.         ld      (Env_PC),hl
  19256.         ld      hl,-l000d;lfff3
  19257.         add     hl,sp
  19258.         ld      sp,hl
  19259.         ex      de,hl
  19260.         ld      bc,l000d
  19261.         ldir
  19262. BackEnv_PC:
  19263.         ld      hl,(Env_PC)
  19264.         push    hl
  19265.         exx
  19266.         ret
  19267. RestEnv2:
  19268.         exx
  19269.         ld      de,Envir2
  19270.         jr      RestEnv7
  19271. ;
  19272. ; Get back environment
  19273. ;
  19274. RestEnv1:
  19275.         exx
  19276.         ld      de,Envir1
  19277. RestEnv7:
  19278.         pop     hl
  19279.         ld      (Env_PC),hl
  19280.         ld      hl,0;l0000
  19281.         add     hl,sp
  19282.         ld      bc,l000d
  19283.         ldir
  19284.         ld      sp,hl
  19285.         jr      BackEnv_PC
  19286. ;
  19287. ; Restore environment from stack, leave stack intact
  19288. ;
  19289. CpyEnv2:
  19290.         exx
  19291.         ld      de,Envir2
  19292.         jr      CpyEnv7
  19293. l6d63:
  19294.         exx
  19295.         ld      de,Envir1
  19296. CpyEnv7:
  19297.         ld      hl,2;l0002
  19298.         add     hl,sp
  19299.         ld      bc,l000d
  19300.         ldir
  19301.         exx
  19302.         ret
  19303. ;
  19304. ; Store current PC into label table
  19305. ;
  19306. puttolabel_i_y:
  19307.         push    iy
  19308.         pop     de
  19309. puttolabel_d_e:
  19310.         ld      a,d
  19311.         call    puttolabel
  19312.         ld      a,e
  19313. puttolabel:
  19314.         push    hl
  19315.         ld      hl,(LabPtr)     ; Get label pointer
  19316.         ld      (hl),a
  19317.         dec     hl
  19318.         ld      (LabPtr),hl     ; Set label pointer
  19319.         pop     hl
  19320.         jp      ChkOvfl         ; Check enough memory
  19321. ;
  19322. ; Get label
  19323. ;
  19324. GetLabel:
  19325.         ld      a,(ix+0)   ; Get 1st character
  19326.         call    IsItLab         ; Test label character
  19327. ;
  19328. ; Build label
  19329. ;
  19330. SampLabel:
  19331.         call    ErrCY
  19332.         db      _IllChar
  19333.         call    DoubleLabel  ; Verify no double label
  19334. l6d94:
  19335.         call    Reserved ; Verify no reserved word
  19336.         ld      a,(ix+0)
  19337. l6d9a:
  19338.         cp      'a'
  19339.         jr      c,l6da4
  19340.         cp      'z'+1
  19341.         jr      nc,l6da4
  19342.         sub     'a'-'A'
  19343. l6da4:
  19344.         call    puttolabel
  19345.         inc     ix
  19346.         ld      a,(ix+0)
  19347.         call    IsItValid               ; Test valid character
  19348.         jr      nc,l6d9a        ; Yeap
  19349.         ld      hl,(LabPtr)     ; Get label pointer
  19350.         inc     hl
  19351.         set     7,(hl)
  19352.         jp      GetLine         ; Process line
  19353. l6dba:
  19354.         ld      a,(ix+0)
  19355.         call    IsItLab         ; Test label character
  19356.         call    ErrCY
  19357.         db      _IllChar
  19358.         jr      l6d94
  19359. ;
  19360. ; Set label pointer
  19361. ;
  19362. SetLabPtr:
  19363.         ld      hl,(PrevLabPtr) ; Get previous label pointer
  19364.         ld      de,(LabPtr)     ; Get label pointer
  19365.         or      a
  19366.         sbc     hl,de
  19367.         ex      de,hl
  19368.         call    puttolabel_d_e          ; Put to table
  19369.         ld      hl,(LabPtr)     ; Get label pointer
  19370.         ld      (PrevLabPtr),hl ; Unpack into previous
  19371.         ret
  19372. l6ddb:
  19373.         ld      hl,(CurLab)     ; Get current label pointer
  19374.         jr      l6de3
  19375. ;
  19376. ;
  19377. ; Find label from table
  19378. ; ENTRY Reg B holds selected TYPE
  19379. ;       Reg C holds item flag
  19380. ;                0 if 1st item in line
  19381. ;               -1 if not 1st one
  19382. ; EXIT  Zero set if label found
  19383. ;;
  19384. ;; l7bc1 = 00, A = -1, NZ ---->>> Not found
  19385. ;; l7bc1 = type, NZ       ---->>> Not same type as B
  19386. ;;                Z       ---->>> Same type
  19387. ;;              HL, DE hold pointers
  19388. ;
  19389. FndItem:
  19390.         ld      hl,(l7b77)      ; Get top of available memory
  19391. l6de3:
  19392.         ld      (l7b7d),hl
  19393.         ld      a,(FirstVAR)
  19394.         cp      c
  19395.         jr      z,l6e48
  19396.         ld      a,c
  19397.         ld      (FirstVAR),a
  19398.         ld      hl,(PrevLabPtr) ; Get previous label pointer
  19399. l6df3:
  19400.         ld      de,(l7b7d)
  19401.         xor     a
  19402.         sbc     hl,de          ; Test pointer reached
  19403.         add     hl,de
  19404.         jr      nz,l6e03
  19405.         xor     a
  19406.         ld      (l7bc1),a
  19407.         dec     a
  19408.         ret
  19409. l6e03:
  19410.         inc     hl
  19411.         ld      e,(hl)          ; Get length of entry ?????????
  19412.         inc     hl
  19413.         ld      d,(hl)
  19414.         add     hl,de           ; Point to end
  19415.         ld      a,(hl)          ; Test more
  19416.         or      a
  19417.         jr      z,l6df3         ; .. end of table ??????????????
  19418.         dec     hl
  19419.         ld      a,(hl)          ; Get type
  19420.         inc     hl
  19421.         cp      c
  19422.         jr      nz,l6df3        ; .. not what we expect
  19423.         push    ix
  19424.         pop     de   ; Copy pointer
  19425.         push    bc
  19426.         push    hl
  19427.         dec     hl   ; Fix to lable
  19428.         dec     hl
  19429. l6e19:
  19430.         ld      b,(hl) ; Get characters
  19431.         ld      a,(de)
  19432.         dec     hl
  19433.         inc     de
  19434.         ld      c,b       ; Save label
  19435.         res     7,b       ; Clear MSB
  19436.         cp      'a'       ; Check a..z
  19437.         jr      c,l6e2a
  19438.         cp      'z'+1
  19439.         jr      nc,l6e2a
  19440.         sub     'a'-'A'   ; .. map to a..z
  19441. l6e2a:
  19442.         cp      b         ; Compare
  19443.         jr      nz,l6e37
  19444.         bit     7,c        ; Test last character
  19445.         jr      z,l6e19    ; .. nope
  19446.         ld      a,(de)     ; Verify end of label
  19447.         call    IsItValid               ; Test valid character
  19448.         jr      c,l6e3b         ; Nope
  19449. l6e37:
  19450.         pop     hl
  19451.         pop     bc
  19452.         jr      l6df3
  19453. l6e3b:
  19454.         ld      (l7bc2),hl     ; Save pointers
  19455.         ld      (l7bc4),de
  19456.         pop     hl
  19457.         pop     bc
  19458.         ld      a,(hl)         ; Save type
  19459.         ld      (l7bc1),a
  19460. l6e48:
  19461.         ld      hl,(l7bc2)
  19462.         ld      de,(l7bc4)
  19463.         ld      a,(l7bc1)
  19464.         cp      b              ; Fix result
  19465.         ret
  19466. ;
  19467. ; Get TYPE from table
  19468. ; ENTRY Reg B holds TYPE searched for
  19469. ;       Reg C holds flag ???????
  19470. ; EXIT  Zero set if TYPE found
  19471. ;       Reg HL points to TYPE
  19472. ; (Find label with type in reg B)
  19473. ;
  19474. FndLABEL:
  19475.         call    FndItem    ; Find it
  19476.         ret     nz         ; .. nope
  19477.         jr      SetLine    ; .. set source pointer
  19478. ;
  19479. ; Find string
  19480. ; ENTRY <SP> points to length of code
  19481. ;       followed by address of string
  19482. ; EXIT  Zero flag set indicates found
  19483. ; (Find constant string list ^PC)
  19484. ; Z set says found
  19485. ;
  19486. FndTabStr:
  19487.         ex      (sp),hl
  19488.         ld      c,(hl)          ; Get length of data following string
  19489.         inc     hl
  19490.         ld      e,(hl)          ; Get address of string
  19491.         inc     hl
  19492.         ld      d,(hl)
  19493.         inc     hl
  19494.         ex      (sp),hl
  19495.         ex      de,hl
  19496. FndDirStr:
  19497.         call    FndStr          ; Find string
  19498.         ret     z               ; Got it
  19499.         dec     hl              ; Postion to previous character
  19500. FndDirStr_fix:
  19501.         bit     _MB,(hl)        ; Find end of string
  19502.         inc     hl
  19503.         jr      z,FndDirStr_fix
  19504.         ld      b,0
  19505.         add     hl,bc           ; Position to next string in list
  19506.         ld      a,(hl)
  19507.         or      a               ; Test more in list
  19508.         jr      nz,FndDirStr    ; Yeap
  19509.         dec     a               ; Set string not found
  19510.         ret
  19511. ;
  19512. ; Find constant string ^PC
  19513. ; Z set says found
  19514. ;
  19515. FindStr:
  19516.         ex      (sp),hl
  19517.         ld      e,(hl)          ; Get address of string
  19518.         inc     hl
  19519.         ld      d,(hl)
  19520.         inc     hl
  19521.         ex      (sp),hl
  19522.         ex      de,hl
  19523. ;
  19524. ; Find string ^HL
  19525. ;
  19526. FndStr:
  19527.         push    ix              ; Copy source pointer
  19528.         pop     de
  19529.         ld      a,(hl)          ; Get character from searched string
  19530.         call    IsItLab         ; Test label character
  19531.         jr      c,l6e92         ; Nope
  19532.         call    l6e9c           ; Compare
  19533.         ret     nz              ; Not found
  19534.         ld      a,(de)          ; Get character from source
  19535.         call    IsItValid               ; Test valid character
  19536.         jr      c,SetLine               ; Nope
  19537.         or      a
  19538.         ret
  19539. l6e92:
  19540.         call    l6e9c           ; Compare
  19541.         ret     nz              ; Not found
  19542. SetLine:
  19543.         push    de              ; Set resulting source pointer
  19544.         pop     ix
  19545.         jp      GetLine         ; Process line
  19546. ;
  19547. ; Compare reference ^HL: source ^DE
  19548. ; Z set says match
  19549. ;
  19550. l6e9c:
  19551.         push    bc
  19552. l6e9d:
  19553.         ld      b,(hl)          ; Get from reference
  19554.         ld      a,(de)          ; Get from source
  19555.         inc     hl
  19556.         inc     de
  19557.         ld      c,b             ; Save reference
  19558.         res     _MB,b           ; Strip off MSB
  19559.         cp      'a'             ; Test range
  19560.         jr      c,l6eae
  19561.         cp      'z'+1
  19562.         jr      nc,l6eae
  19563.         sub     'a'-'A'         ; Convert to UPPER case
  19564. l6eae:
  19565.         cp      b               ; Compare
  19566.         jr      nz,l6eb6        ; No match
  19567.         bit     _MB,c           ; Test end of reference
  19568.         jr      z,l6e9d         ; Nope
  19569.         xor     a               ; Force match
  19570. l6eb6:
  19571.         pop     bc
  19572.         ret
  19573. ;
  19574. ; Verify no reserved word
  19575. ;
  19576. Reserved:
  19577.         ld      hl,l7513
  19578. l6ebb:
  19579.         ld      c,(hl)
  19580.         inc     c
  19581.         ret     z
  19582.         dec     c
  19583.         inc     hl
  19584.         ld      e,(hl)
  19585.         inc     hl
  19586.         ld      d,(hl)
  19587.         inc     hl
  19588.         push    hl
  19589.         ex      de,hl
  19590.         call    FndDirStr
  19591.         pop     hl
  19592.         jr      nz,l6ebb
  19593.         call    ERROR
  19594.         db      _ResWord
  19595. DoubleLabel:
  19596.         ld      a,(l7b91)       ; Get ???
  19597.         ld      c,a
  19598.         call    l6ddb
  19599.         ld      a,(l7bc1)
  19600.         or      a
  19601.         ret     z
  19602.         call    ERROR
  19603.         db      _DoubleLab
  19604. l6ee0:
  19605.         ld      a,'['
  19606.         call    l6f29
  19607.         ret     z
  19608.         ld      a,(ix+0)
  19609.         cp      '('
  19610.         ret     nz
  19611.         ld      a,(ix+1)
  19612.         cp      '.'
  19613.         ret     nz
  19614. l6ef2:
  19615.         inc     ix
  19616.         jp      NewLine         ; Process line
  19617. ;
  19618. ; Test ] - Z set says found
  19619. ;
  19620. l6ef7:
  19621.         ld      a,']'
  19622.         call    l6f29
  19623.         ret     z
  19624. ;;:::
  19625.         ld      a,(ix+0)
  19626.         cp      '.'
  19627.         ret     nz
  19628.         ld      a,(ix+1)
  19629.         cp      ')'
  19630.         ret     nz
  19631.         jr      l6ef2
  19632. ;
  19633. ; Test colon : - Z set says found
  19634. ;
  19635. l6f0b:
  19636.         ld      a,':'
  19637.         jr      l6f29
  19638. ;
  19639. ; Test semicolon ; - Z set says found
  19640. ;
  19641. l6f0f:
  19642.         ld      a,';'
  19643.         jr      l6f29
  19644. ;
  19645. ; Test comma , - Z set says found
  19646. ;
  19647. l6f13:
  19648.         ld      a,','
  19649.         jr      l6f29
  19650. l6f17:
  19651.         ld      a,'.'
  19652.         jr      l6f29
  19653. ;
  19654. ; Test left parenthesis ( - Z set says found
  19655. ;
  19656. l6f1b:
  19657.         ld      a,'('
  19658.         jr      l6f29
  19659. l6f1f:
  19660.         ld      a,')'
  19661.         jr      l6f29
  19662. ;
  19663. ; Test equate = - Z set says found
  19664. ;
  19665. l6f23:
  19666.         ld      a,'='
  19667.         jr      l6f29
  19668. l6f27:
  19669.         ld      a,'^'
  19670. l6f29:
  19671.         cp      (ix+0)
  19672.         ret     nz
  19673.         jp      NewLine         ; Process line
  19674. ;
  19675. ; Verify [
  19676. ;
  19677. l6f30:
  19678.         call    l6ee0
  19679.         ret     z
  19680.         call    ERROR
  19681.         db      _LftBrExp
  19682. ;
  19683. ; Verify ]
  19684. ;
  19685. l6f38:
  19686.         call    l6ef7           ; Test ]
  19687.         ret     z
  19688.         call    ERROR
  19689.         db      _RgtBrExp
  19690. ;
  19691. ; Verify :
  19692. ;
  19693. l6f40:
  19694.         call    l6f0b           ; Test :
  19695.         ret     z
  19696.         call    ERROR
  19697.         db      _SemiExp
  19698. ;
  19699. ; Verify ;
  19700. ;
  19701. l6f48:
  19702.         call    l6f0f           ; Test ;
  19703.         ret     z               ; Yeap
  19704. l6f4c:
  19705.         call    ERROR
  19706.         db      _ColExp
  19707. l6f50:
  19708.         call    l6f0f           ; Test ;
  19709.         ret     z               ; Yeap
  19710.         ld      a,(l7b98)
  19711.         or      a
  19712.         jr      z,l6f4c
  19713.         call    ERROR
  19714.         db      _Undef
  19715. ;
  19716. ; Verify ,
  19717. ;
  19718. l6f5e:
  19719.         call    l6f13           ; Test ,
  19720.         ret     z               ; Yeap
  19721.         call    ERROR
  19722.         db      _CommaExp
  19723. ;
  19724. ; Verify (
  19725. ;
  19726. l6f66:
  19727.         call    l6f1b           ; Test (
  19728.         ret     z               ; Yeap
  19729.         call    ERROR
  19730.         db      _LftPar
  19731. ;
  19732. ; Verify )
  19733. ;
  19734. l6f6e:
  19735.         call    l6f1f
  19736.         ret     z
  19737.         call    ERROR
  19738.         db      _RgtPar
  19739. ;
  19740. ; Verify =
  19741. ;
  19742. l6f76:
  19743.         call    l6f23           ; Find =
  19744.         ret     z
  19745.         call    ERROR
  19746.         db      _EquExp
  19747. l6f7e:
  19748.         call    FindStr         ; Find :=
  19749.         dw      l7582
  19750.         ret     z               ; Yeap
  19751.         call    ERROR
  19752.         db      _AssigExp
  19753. l6f88:
  19754.         call    FindStr         ; Find OF
  19755.         dw      l7560
  19756.         ret     z               ; Yeap
  19757.         call    ERROR
  19758.         db      _NoOF
  19759. ;
  19760. ; Process source line
  19761. ;
  19762. NewLine:
  19763.         call    l7124           ; Get character from file
  19764. GetLine:
  19765.         xor     a
  19766.         ld      (l7b98),a
  19767.         dec     a
  19768.         ld      (FirstVAR),a
  19769.         ld      a,(ix+0)        ; Get a character
  19770.         or      a               ; Test empty
  19771.         jr      z,NewLine               ; Yeap, so get next
  19772.         cp      ' '             ; Skip blanks
  19773.         jr      z,NewLine
  19774.         cp      tab             ; Skip tabs
  19775.         jr      z,NewLine
  19776.         cp      '('             ; Test possible comment
  19777.         jr      z,l6fb5
  19778.         cp      '{'             ; Test real comment
  19779.         jr      z,l6fbf
  19780. l6fb3:
  19781.         xor     a
  19782.         ret
  19783. l6fb5:
  19784.         ld      a,(ix+1)        ; Get next
  19785.         cp      '*'             ; Test comment
  19786.         jr      nz,l6fb3        ; Nope
  19787.         call    l7124           ; Get next character
  19788. l6fbf:
  19789.         push    bc
  19790.         ld      b,(ix+0)        ; Get comment indicator
  19791.         ld      a,(ix+1)        ; Get next character
  19792.         cp      '$'             ; Test compiler directive
  19793.         jr      z,l6feb         ; Maybe
  19794. l6fca:
  19795.         call    l7124           ; Get next character
  19796. l6fcd:
  19797.         ld      a,b
  19798.         cp      '*'             ; Test two character indicators
  19799.         ld      a,(ix+0)
  19800.         jr      nz,l6fe4        ; Nope
  19801.         cp      b
  19802.         jr      nz,l6fca
  19803.         ld      a,(ix+1)
  19804.         cp      ')'
  19805.         jr      nz,l6fca
  19806.         call    l7124           ; Get character from file
  19807.         jr      l6fe8
  19808. l6fe4:
  19809.         cp      '}'             ; Test end of comment
  19810.         jr      nz,l6fca        ; Nope, wait for
  19811. l6fe8:
  19812.         pop     bc
  19813.         jr      NewLine
  19814. l6feb:
  19815.         push    bc
  19816.         push    de
  19817.         push    hl
  19818.         call    l7124           ; Get character from file
  19819. l6ff1:
  19820.         call    l7124           ; Get character from file
  19821.         ld      a,(ix+0)
  19822.         call    doupcase                ; Convert to upper case
  19823.         cp      'I'             ; Test include or I/O error
  19824.         ld      b,00000001b
  19825.         jr      z,l704d
  19826.         cp      'R'             ; Test index range test
  19827.         ld      b,00000010b
  19828.         jr      z,l704d
  19829.         cp      'A'             ; Test absolute code
  19830.         ld      b,00000100b
  19831.         jr      z,l704d
  19832.         cp      'U'             ; Test user break
  19833.         ld      b,00001000b
  19834.         jr      z,l704d
  19835.         cp      'X'             ; Test arry optimization
  19836.         ld      b,00010000b
  19837.         jr      z,l704d
  19838.         cp      'V'             ; Test var type test
  19839.         ld      b,00100000b
  19840.         jr      z,l704d
  19841.         cp      'B'             ; Test I/O mode
  19842.         ld      b,01000000b
  19843.         jr      z,l704d
  19844.         cp      'C'             ; Test keyboard interrupt
  19845.         ld      b,10000000b
  19846.         jr      z,l704d
  19847.         cp      'W'             ; Test WITH check
  19848.         jr      z,l707a
  19849. ;
  19850. ; Next directives used by MS-DOS only.
  19851. ; They will be checked for compatibility only
  19852. ;
  19853.         ld      b,00000000b
  19854.         cp      'K'             ; Test stack check ([$K+, $K-])
  19855.         jr      z,l704d
  19856.         cp      'D'             ; Test device check ([$D+, $D-])
  19857.         jr      z,l704d
  19858.         cp      'F'             ; Test number of open files ([$Fnum])
  19859.         jr      z,l708e
  19860.         cp      'G'             ; Test input buffer ([$Gnum])
  19861.         jr      z,l708e
  19862.         cp      'P'             ; Test output buffer ([$Pnum])
  19863.         jr      z,l708e
  19864.         call    ERROR           ; Invalid directive
  19865.         db      _CompDirec
  19866. l7048:
  19867.         pop     hl
  19868.         pop     de
  19869.         pop     bc
  19870.         jr      l6fcd
  19871. ;
  19872. ; Set or reset directive $x+ or $x-
  19873. ;
  19874. ; Bit to be attached held in reg B
  19875. ;
  19876. l704d:
  19877.         call    l7124           ; Get character from file
  19878.         ld      a,(ix+0)
  19879.         ld      c,0             ; Init for set
  19880.         cp      '+'             ; Test it
  19881.         jr      z,l7065         ; Yeap
  19882.         dec     c               ; Prepare for reset - all bits set
  19883.         cp      '-'
  19884.         jr      z,l7065
  19885.         dec     b               ; Remember $I is 00000001b - used multiple
  19886.         call    ErrNZ           ; Else error
  19887.         db      _CompDirec
  19888.         jr      l709b           ; Now process include
  19889. l7065:
  19890.         ld      hl,l7b9d        ; Point to options
  19891.         ld      a,(hl)          ; Get current bits
  19892.         xor     c               ; Toggle bits or let in tact
  19893.         or      b               ; Insert bit
  19894.         xor     c               ; Set result
  19895.         ld      (hl),a
  19896. l706d:
  19897.         call    l7124           ; Get character from file
  19898. l7070:
  19899.         ld      a,(ix+0)
  19900.         cp      ','             ; Test more
  19901.         jp      z,l6ff1         ; Yeap
  19902.         jr      l7048
  19903. l707a:
  19904.         call    l7124           ; Get character from file
  19905.         ld      a,(ix+0)
  19906.         call    IsItDigit               ; Test digit
  19907.         call    ErrCY
  19908.         db      _CompDirec
  19909.         sub     '0'
  19910.         ld      (l7bc7),a       ; Change depth for WITH
  19911.         jr      l706d
  19912. ;
  19913. ; Process MS-DOS compatible directives
  19914. ;
  19915. l708e:
  19916.         call    l7124           ; Get character from file
  19917.         ld      a,(ix+0)
  19918.         call    IsItDigit               ; Test digit
  19919.         jr      nc,l708e        ; Yeap, skip over
  19920.         jr      l7070
  19921. l709b:
  19922.         cp      ' '
  19923.         jr      nz,l70a7        ; Skip over directive
  19924.         call    l7124           ; Get character from file
  19925.         ld      a,(ix+0)
  19926.         jr      l709b
  19927. l70a7: ;include???
  19928.         ld      a,(IncFlg)      ; Get memory read flag
  19929.         or      a
  19930.         call    ErrNZ           ; Should be memory read
  19931.         db      _INCLerr
  19932.         push    ix
  19933.         pop     de
  19934.         call    l2d2a           ; Prepare .PAS file
  19935.         push    de
  19936.         pop     ix
  19937.         ld      de,l005c
  19938.         push    de
  19939.          ;jr $
  19940.         ld      c,_open
  19941.         call    _BDOS           ; Open file ;WHERE IS CLOSE???
  19942.         pop     hl
  19943.         inc     a
  19944.         call    ErrZ
  19945.         db      _NoFileErr
  19946.         ld      de,l790f
  19947.         ld      bc,FCBlen
  19948.         ldir                    ; Unpack file
  19949.         ld      a,(CmpTyp)      ; Get compile flag
  19950.         dec     a               ; Test compiling to file
  19951.         jr      z,l70e2         ; Yeap
  19952.         ld      hl,TmpBuff
  19953.         ld      (l7be4),hl      ; Save top of .COM file
  19954.         ld      hl,l79d7        ; Get start of source line
  19955.         ld      a,1
  19956.         jr      l7103
  19957. l70e2:
  19958.         ld      hl,(LabPtr)     ; Get label pointer
  19959.         ld      de,(COMsTop)    ; Get top of .COM file
  19960.         ld      (l7be4),de      ; Save it
  19961.         or      a
  19962.         sbc     hl,de           ; Calculate difference
  19963.         srl     h
  19964.         rr      l
  19965.         ld      a,h
  19966.         or      a
  19967.         call    ErrZ            ; If hi zero, no memory
  19968.         db      _CompOvfl
  19969.         ld      a,l
  19970.         and     RecLng
  19971.         ld      l,a
  19972.         push    hl
  19973.         add     hl,hl
  19974.         ld      a,h
  19975.         pop     hl
  19976.         add     hl,de
  19977. l7103:
  19978.         ld      (INCsTop),hl
  19979.         ld      (l7be9),hl
  19980.         ld      (l7be8),a
  19981.         ld      (IncFlg),a      ; Re/Set memory read flag
  19982.         ld      hl,l0000
  19983.         ld      (l7beb),hl
  19984.         ld      a,(l7b9d)       ; Get options
  19985.         ld      (l7b9f),a
  19986.         ld      a,(l7bc7)       ; Get depth for WITH
  19987.         ld      (l7bc8),a
  19988.         jp      l7048
  19989. ;
  19990. ; Get character from file
  19991. ;
  19992. l7124:
  19993.         ld      a,(ix+0)
  19994.         inc     ix
  19995.         or      a
  19996.         ret     nz
  19997.         push    bc
  19998.         push    de
  19999.         push    hl
  20000.         ld      a,(l7ba2)       ; Get end of file
  20001.         or      a
  20002.         call    ErrNZ
  20003.         db      _IllSrcEnd
  20004.         ld      hl,(l7bd7)      ; Get source pointer
  20005.         ld      (l7bd9),hl      ; Unpack it
  20006.         ld      hl,(l7beb)
  20007.         ld      (l7bed),hl
  20008.         ld      hl,l79d7        ; Get start of source line
  20009.         push    hl
  20010.         pop     ix              ; Copy it
  20011.         ld      b,RecLng-1      ; Set max length
  20012. l714a:
  20013.         push    hl
  20014.         push    bc
  20015.         call    l71f3
  20016.          if TERM
  20017.          ;push af
  20018.          ;push ix
  20019.          ;push iy
  20020.          ;PRCHAR_
  20021.          ;pop iy
  20022.          ;pop ix
  20023.          ;pop af
  20024.          else
  20025.          ;push af
  20026.          ;push ix
  20027.          ;push iy
  20028.          ;PRCHAR
  20029.          ;pop iy
  20030.          ;pop ix
  20031.          ;pop af
  20032.          endif
  20033.         pop     bc
  20034.         pop     hl
  20035.         cp      cr
  20036.         jr      z,l7175
  20037.         cp      eof
  20038.          ;jr z,$ ;never
  20039.         jr      z,l716a
  20040.         cp      tab
  20041.         jr      z,l7161
  20042.         cp      ' '
  20043.         jr      c,l714a
  20044. l7161:
  20045.         djnz    l7166
  20046.         inc     b
  20047.         jr      l714a
  20048. l7166:
  20049.         ld      (hl),a
  20050.         inc     hl
  20051.         jr      l714a
  20052. l716a:
  20053.         ld      (l7ba2),a       ; Set end of file
  20054.         call    l717e
  20055.         call    l718f           ; Test abort
  20056.         jr      l7178
  20057. l7175:
  20058.         call    l717e ;compile_newline
  20059. l7178:
  20060.         ld      (hl),0
  20061.         pop     hl
  20062.         pop     de
  20063.         pop     bc
  20064.         ret
  20065. l717e: ;compile_newline
  20066.         push    af
  20067.         push    hl
  20068.         ld      hl,(l7bef)
  20069.         inc     hl              ; Advance line count
  20070.         ld      (l7bef),hl
  20071.         ld      a,l
  20072.         and     0fh
  20073.         ;jr     z,l7191
  20074.         pop     hl
  20075.         pop     af
  20076.         ret
  20077. ;
  20078. ; Test abortion of compilation
  20079. ;
  20080. l718f:
  20081.         push    af
  20082.         push    hl
  20083. l7191:
  20084.         push    bc
  20085.         push    de
  20086.         push    ix
  20087.         push    iy
  20088.         ld      a,cr
  20089.         call    puttoconsole_a          ; Put to console
  20090.         ld      a,(IncFlg)      ; Test memory read
  20091.         or      a
  20092.         jr      z,l71a6         ; Yeap
  20093.         ld      a,'I'
  20094.         jr      l71a8
  20095. l71a6:
  20096.         ld      a,' '
  20097. l71a8:
  20098.         call    puttoconsole_a          ; Put to console
  20099.         ld      a,' '
  20100.         call    puttoconsole_a          ; Put to console
  20101.         ld      hl,(l7bef)      ; Get line count
  20102.         call    l2e61           ; Print number
  20103.         call    l00a0           ; Test key pressed
  20104.         or      a
  20105.         jr      z,l71ea
  20106.         call    l0200
  20107.         db      '   *** Abort compilation'
  20108.         db      null
  20109.         call    l2d01           ; Ask for YES or NO
  20110.         call    ErrNZ
  20111.         db      _ABORT
  20112.         ld      b,32
  20113. l71e1:
  20114.         call    l0200
  20115.         db      bs,' ',bs
  20116.         db      null
  20117.         djnz    l71e1
  20118. l71ea:
  20119.         pop     iy
  20120.         pop     ix
  20121.         pop     de
  20122.         pop     bc
  20123.         pop     hl
  20124.         pop     af
  20125.         ret
  20126. ;
  20127. ; Read character from file
  20128. ;
  20129. l71f3:
  20130.         ld      a,(IncFlg)      ; Test memory read
  20131.         or      a
  20132.         jr      nz,l7205        ; Nope
  20133. l71f9:
  20134.         ld      hl,(l7bd7)      ; Get source pointer
  20135.         ld      a,(hl)
  20136.         cp      eof             ; Test end of file
  20137.         ret     z               ; Yeap
  20138.         inc     hl
  20139.         ld      (l7bd7),hl
  20140.         ret
  20141. l7205:
  20142.         ld      hl,(l7be9)
  20143.         ld      de,(INCsTop)
  20144.         or      a
  20145.         sbc     hl,de
  20146.         add     hl,de
  20147.         jr      c,l7242
  20148.         ld      de,(l7be4)      ; Get top of .COM file
  20149.         ld      a,(l7be8)
  20150.         ld      b,a
  20151. l721a:
  20152.         push    bc
  20153.         push    de
  20154.         ld      c,_setdma
  20155.         call    _BDOS           ; Set disk buffer
  20156.         ld      de,l790f
  20157.         ld      c,_rdseq
  20158.         call    _BDOS           ; Read record
  20159.         pop     de
  20160.         pop     bc
  20161.         ;or     a
  20162.         ;jr     nz,l7237
  20163.          xor 128 ;EOF in NedoOS
  20164.          jr z,l7237
  20165.         ;ld     hl,RecLng
  20166.          ld l,a
  20167.          ld h,0
  20168. ;CP/M has eofs in the end of last sector?
  20169. ;do this by hand:
  20170.         xor 128
  20171.         jr z,readchar_load_noaddzeros ;full sector
  20172. ;a=128+bytes loaded
  20173.         neg
  20174. ;a=128-bytes loaded
  20175.         push bc
  20176.         push de
  20177.         ld b,a
  20178.         ld a,e
  20179.         add a,127
  20180.         ld e,a
  20181.         adc a,d
  20182.         sub e
  20183.         ld d,a
  20184.         ;de= Point to buffer end
  20185.         ld a,eof;-1
  20186.         ld (de),a
  20187.         dec de
  20188.         djnz $-2
  20189.         pop de
  20190.         pop bc
  20191. readchar_load_noaddzeros
  20192.         add     hl,de           ; Advance buffer
  20193.         ex      de,hl
  20194.         djnz    l721a
  20195.         jr      l723f
  20196. l7237:
  20197.         ld      a,eof           ; Set end of file
  20198.         ld      (de),a
  20199.         inc     de
  20200.         ld      (INCsTop),de
  20201. l723f:
  20202.         ld      hl,(l7be4)      ; Get top of .COM file
  20203. l7242:
  20204.         ld      a,(hl)
  20205.         inc     hl
  20206.         ld      (l7be9),hl
  20207.         cp      eof
  20208.         jr      nz,l725d
  20209.          ld c,_close
  20210.          call BDOS_with_FCB1
  20211.         xor     a
  20212.         ld      (IncFlg),a      ; Enable memory read
  20213.         ld      a,(l7b9f)
  20214.         ld      (l7b9d),a       ; Reset options
  20215.         ld      a,(l7bc8)
  20216.         ld      (l7bc7),a       ; Set depth for WITH
  20217.         jp      l71f9
  20218. l725d:
  20219.         ld      hl,(l7beb)
  20220.         inc     hl
  20221.         ld      (l7beb),hl
  20222.         ret
  20223. ;
  20224. ; Perform OS call
  20225. ;
  20226. _BDOS:
  20227.         push    ix              ; Preserve index registers
  20228.         push    iy
  20229.         call    BDOS            ; Call system
  20230.         pop     iy
  20231.         pop     ix
  20232.         ret
  20233. ;
  20234. ; Test label character
  20235. ; C set says no
  20236. ;
  20237. IsItLab:
  20238.         cp      'A'
  20239.         ret     c
  20240.         cp      'Z'+1
  20241.         ccf
  20242.         ret     nc
  20243.         cp      '_'
  20244.         ret     z
  20245.         cp      'a'
  20246.         ret     c
  20247.         cp      'z'+1
  20248.         ccf
  20249.         ret
  20250. ;
  20251. ; Test valid character
  20252. ; C set says no
  20253. ;
  20254. IsItValid:
  20255.         call    IsItLab         ; Test label character
  20256.         ret     nc              ; Yeap
  20257. ;
  20258. ; Test character a digit
  20259. ; C set says no
  20260. ;
  20261. IsItDigit:
  20262.         cp      '0'             ; Test digit
  20263.         ret     c
  20264.         cp      '9'+1
  20265.         ccf
  20266.         ret
  20267. ;
  20268. ; Compare signed integers HL:DE
  20269. ;
  20270. ; C set if HL<DE
  20271. ; Z set if HL=DE
  20272. ;
  20273. l728d:
  20274.         ld      a,h
  20275.         xor     d
  20276.         ld      a,h
  20277.         jp      m,l7298
  20278.         cp      d
  20279.         ret     nz
  20280.         ld      a,l
  20281.         cp      e
  20282.         ret
  20283. l7298:
  20284.         rla
  20285.         ret
  20286. ;
  20287. ; HL:=HL*DE - C set on overflow
  20288. ;
  20289. l729a:
  20290.         ld      b,h
  20291.         ld      c,l
  20292.         ld      hl,0            ; Init product
  20293.         ld      a,16
  20294. l72a1:
  20295.         add     hl,hl
  20296.         ret     c
  20297.         ex      de,hl
  20298.         add     hl,hl
  20299.         ex      de,hl
  20300.         jr      nc,l72aa
  20301.         add     hl,bc
  20302.         ret     c
  20303. l72aa:
  20304.         dec     a
  20305.         jr      nz,l72a1
  20306.         ret
  20307. ;
  20308. ; HL:=HL DIV DE                         *** NOT USED HERE
  20309. ; HL:=HL MOD DE
  20310. ;
  20311.         ld      b,d
  20312.         ld      c,e
  20313.         ex      de,hl
  20314.         xor     a
  20315.         ld      h,a
  20316.         ld      l,a
  20317.         ld      a,17
  20318. l72b6:
  20319.         adc     hl,hl
  20320.         sbc     hl,bc
  20321.         jr      nc,l72be
  20322.         add     hl,bc
  20323.         scf
  20324. l72be:
  20325.         ccf
  20326.         rl      e
  20327.         rl      d
  20328.         dec     a
  20329.         jr      nz,l72b6
  20330.         ex      de,hl
  20331.         ret
  20332. ;
  20333. ; Process error if entry C
  20334. ;
  20335. ErrCY:
  20336.         ex      (sp),hl
  20337.         inc     hl              ; Fix caller's address
  20338.         ex      (sp),hl
  20339.         ret     nc              ; No error
  20340.         jr      l72de
  20341. l72ce:: ;;**
  20342.         ex      (sp),hl
  20343.         inc     hl              ; Fix caller's address
  20344.         ex      (sp),hl
  20345.         ret     c               ; No error
  20346.         jr      l72de
  20347. ;
  20348. ; Process error if entry Z
  20349. ;
  20350. ErrZ:
  20351.         ex      (sp),hl
  20352.         inc     hl              ; Fix caller's address
  20353.         ex      (sp),hl
  20354.         ret     nz              ; No error
  20355.         jr      l72de
  20356. ;
  20357. ; Process error if entry NZ
  20358. ;
  20359. ErrNZ:
  20360.         ex      (sp),hl
  20361.         inc     hl              ; Fix caller's address
  20362.         ex      (sp),hl
  20363.         ret     z               ; No error
  20364. ;
  20365. ; Common entry of error routine
  20366. ;
  20367. l72de:
  20368.         pop     hl              ; Get back caller
  20369.         dec     hl              ; Fix pointer
  20370.         push    hl
  20371. ;
  20372. ; Process error
  20373. ;
  20374. ERROR:
  20375.         pop     hl              ; Get pointer
  20376.         ld      a,(hl)          ; Fetch error number
  20377. l72e3:
  20378.         call    l718f           ; Test abort
  20379.         ld      (l7901),a
  20380.         or      a
  20381.         jr      z,l730c
  20382.         push    ix
  20383.         pop     hl
  20384.         ld      de,l79d7        ; Get start of source line
  20385.         sbc     hl,de
  20386.         ld      de,(l7bed)
  20387.         ld      a,(IncFlg)      ; Test memory read
  20388.         or      a
  20389.         jr      nz,l7308        ; Nope
  20390.         ld      de,(l4544)      ; Get start of text
  20391.         sbc     hl,de
  20392.         ld      de,(l7bd9)      ; Get back source pointer
  20393. l7308:
  20394.         add     hl,de
  20395.         ld      (l790c),hl      ; Save current editor address
  20396. l730c:
  20397.         ld      a,(CmpTyp)      ; Get compile flag
  20398.         dec     a               ; Test compiling to file
  20399.         jr      nz,l731a        ; Nope
  20400.         ld      de,FFCB
  20401.         ld      c,_close
  20402.         call    _BDOS           ; Close file
  20403. l731a:
  20404.         ld      sp,(l7b71)      ; Get back stack
  20405.         ret                     ; Exit compiler
  20406.  
  20407. ;
  20408. ; Compiler tables
  20409. ; Internal label table
  20410. ;
  20411. ; -->> INTEGER
  20412. ;
  20413. l731f:
  20414.         dw      _.INT
  20415. ssINT:
  20416.         dw      l74d3+7
  20417.         db      'R'+MSB,'EGETNI'
  20418.         db      0,_Type
  20419. _.INT   equ     $-ssINT
  20420. ;
  20421. ; -->> CHAR
  20422. ;
  20423.         dw      _.CHAR
  20424. ssCHAR:
  20425.         dw      l74db+7
  20426.         db      'R'+MSB,'AHC'
  20427.         db      0,_Type
  20428. _.CHAR  equ     $-ssCHAR
  20429. ;
  20430. ; -->> REAL
  20431. ;
  20432.         dw      _.REAL
  20433. ssREAL:
  20434.         dw      l74e3+7
  20435.         db      'L'+MSB,'AER'
  20436.         db      0,_Type
  20437. _.REAL  equ     $-ssREAL
  20438. ;
  20439. ; -->> BOOLEAN
  20440. ;
  20441.         dw      _.BOOL
  20442. ssBOOL:
  20443.         dw      l74eb+7
  20444.         db      'N'+MSB,'AELOOB'
  20445.         db      0,_Type
  20446. _.BOOL  equ     $-ssBOOL
  20447. ;
  20448. ; -->> TEXT
  20449. ;
  20450.         dw      _.TEXT
  20451. ssTEXT:
  20452.         dw      l74f3+7 ;text file type???
  20453.         db      'T'+MSB,'XET'
  20454.         db      0,_Type
  20455. _.TEXT  equ     $-ssTEXT
  20456. ;
  20457. ; -->> BYTE
  20458. ;
  20459.         dw      _.BYTE
  20460. ssBYTE:
  20461.         dw      l74fb+7 ;byte type
  20462.         db      'E'+MSB,'TYB'
  20463.         db      0,_Type
  20464. _.BYTE  equ     $-ssBYTE
  20465. ;
  20466. ; -->> TRUE
  20467. ;
  20468.         dw      _.TRUE
  20469. ssTRUE:
  20470.         dw      _TRUE
  20471.         db      _Bool
  20472.         db      'E'+MSB,'URT'
  20473.         db      0,_Const
  20474. _.TRUE  equ     $-ssTRUE
  20475. ;
  20476. ; -->> FALSE
  20477. ;
  20478.         dw      _.FALSE
  20479. ssFALSE:
  20480.         dw      FALSE
  20481.         db      _Bool
  20482.         db      'E'+MSB,'SLAF'
  20483.         db      0,_Const
  20484. _.FALSE equ     $-ssFALSE
  20485. ;
  20486. ; -->> MAXINT
  20487. ;
  20488.         dw      _.MXINT
  20489. ssMAXINT:
  20490.         dw      MAXINT
  20491.         db      _Integ
  20492.         db      'T'+MSB,'NIXAM'
  20493.         db      0,_Const
  20494. _.MXINT equ     $-ssMAXINT
  20495. ;
  20496. ; -->> PI
  20497. ;
  20498.         dw      _.PI
  20499. ssPI:
  20500.         db      082h,021h,0a2h,0dah,00fh,049h
  20501.         db      _Real
  20502.         db      'I'+MSB,'P'
  20503.         db      0,_Const
  20504. _.PI    equ     $-ssPI
  20505. ;
  20506. ; -->> OUTPUT
  20507. ;
  20508.         dw      _.OUTP
  20509. ssOUTP:
  20510.         dw      l74f3+7 ;text file type???
  20511.         dw      l00c2
  20512.         db      0
  20513.         db      'T'+MSB,'UPTUO'
  20514.         db      0,4
  20515. _.OUTP  equ     $-ssOUTP
  20516. ;
  20517. ; -->> INPUT
  20518. ;
  20519.         dw      _.INPT
  20520. ssINPT:
  20521.         dw      l74f3+7 ;text file type???
  20522.         dw      l00c2
  20523.         db      0
  20524.         db      'T'+MSB,'UPNI'
  20525.         db      0,_Ptr
  20526. _.INPT  equ     $-ssINPT
  20527. ;
  20528. ; -->> CON
  20529. ;
  20530.         dw      _.CON
  20531. ssCON:
  20532.         dw      l74f3+7 ;text file type???
  20533.         dw      l00b8
  20534.         db      0
  20535.         db      'N'+MSB,'OC'
  20536.         db      0,_Ptr
  20537. _.CON   equ     $-ssCON
  20538. ;
  20539. ; -->> TRM
  20540. ;
  20541.         dw      _.TRM
  20542. ssTRM:
  20543.         dw      l74f3+7 ;text file type???
  20544.         dw      l00b8
  20545.         db      0
  20546.         db      'M'+MSB,'RT'
  20547.         db      0,_Ptr
  20548. _.TRM   equ     $-ssTRM
  20549. ;
  20550. ; -->> KBD
  20551. ;
  20552.         dw      _.KBD
  20553. ssKBD:
  20554.         dw      l74f3+7 ;text file type???
  20555.         dw      l00ba
  20556.         db      0
  20557.         db      'D'+MSB,'BK'
  20558.         db      0,_Ptr
  20559. _.KBD   equ     $-ssKBD
  20560. ;
  20561. ; -->> LST
  20562. ;
  20563.         dw      _.LST
  20564. ssLST:
  20565.         dw      l74f3+7 ;text file type???
  20566.         dw      l00bc
  20567.         db      0
  20568.         db      'T'+MSB,'SL'
  20569.         db      0,_Ptr
  20570. _.LST   equ     $-ssLST
  20571. ;
  20572. ; -->> AUX
  20573. ;
  20574.         dw      _.AUX
  20575. ssAUX:
  20576.         dw      l74f3+7 ;text file type???
  20577.         dw      l00be
  20578.         db      0
  20579.         db      'X'+MSB,'UA'
  20580.         db      0,_Ptr
  20581. _.AUX   equ     $-ssAUX
  20582. ;
  20583. ; -->> USR
  20584. ;
  20585.         dw      _.USR
  20586. ssUSR:
  20587.         dw      l74f3+7 ;text file type???
  20588.         dw      l00c0
  20589.         db      0
  20590.         db      'R'+MSB,'SU'
  20591.         db      0,_Ptr
  20592. _.USR   equ     $-ssUSR
  20593. ;
  20594. ; -->> BUFLEN
  20595. ;
  20596.         dw      _.BUFL
  20597. ssBUFL:
  20598.         dw      l74fb+7 ;byte type
  20599.         dw      l00d1
  20600.         db      0
  20601.         db      'N'+MSB,'ELFUB'
  20602.         db      0,_Ptr
  20603. _.BUFL  equ     $-ssBUFL
  20604. ;
  20605. ; -->> HEAPPTR
  20606. ;
  20607.         dw      _.HEAP
  20608. ssHEAP:
  20609.         dw      l74d3+7 ;integer type
  20610.         dw      l00c4
  20611.         db      0
  20612.         db      'R'+MSB,'TPPAEH'
  20613.         db      0,_Ptr
  20614. _.HEAP  equ     $-ssHEAP
  20615. ;
  20616. ; -->> RECURPTR
  20617. ;
  20618.         dw      _.RECUR
  20619. ssRECUR:
  20620.         dw      l74d3+7 ;integer type
  20621.         dw      l00c6
  20622.         db      0
  20623.         db      'R'+MSB,'TPRUCER'
  20624.         db      0,_Ptr
  20625. _.RECUR equ     $-ssRECUR
  20626. ;
  20627. ; -->> CONSTPTR
  20628. ;
  20629.         dw      _.CONSP
  20630. ssCONSP:
  20631.         dw      l74d3+7 ;integer type
  20632.         dw      l00a0+1
  20633.         db      0
  20634.         db      'R'+MSB,'TPTSNOC'
  20635.         db      0,_Ptr
  20636. _.CONSP equ     $-ssCONSP
  20637. ;
  20638. ; -->> CONINPTR
  20639. ;
  20640.         dw      _.CONIP
  20641. ssCONIP:
  20642.         dw      l74d3+7 ;integer type
  20643.         dw      l00a3+1
  20644.         db      0
  20645.         db      'R'+MSB,'TPNINOC'
  20646.         db      0,_Ptr
  20647. _.CONIP equ     $-ssCONIP
  20648. ;
  20649. ; -->> CONOUTPTR
  20650. ;
  20651.         dw      _.CONOP
  20652. ssCONOP:
  20653.         dw      l74d3+7 ;integer type
  20654.         dw      l00a6+1
  20655.         db      0
  20656.         db      'R'+MSB,'TPTUONOC'
  20657.         db      0,_Ptr
  20658. _.CONOP equ     $-ssCONOP
  20659. ;
  20660. ; -->> LSTOUTPTR
  20661. ;
  20662.         dw      _.LSTOP
  20663. ssLSTOP:
  20664.         dw      l74d3+7 ;integer type
  20665.         dw      l00a9+1
  20666.         db      0
  20667.         db      'R'+MSB,'TPTUOTSL'
  20668.         db      0,_Ptr
  20669. _.LSTOP equ     $-ssLSTOP
  20670. ;
  20671. ; -->> AUXINPTR
  20672. ;
  20673.         dw      _.AUXIP
  20674. ssAUXIP:
  20675.         dw      l74d3+7 ;integer type
  20676.         dw      l00af+1
  20677.         db      0
  20678.         db      'R'+MSB,'TPNIXUA'
  20679.         db      0,_Ptr
  20680. _.AUXIP equ     $-ssAUXIP
  20681. ;
  20682. ; -->> AUXOUTPTR
  20683. ;
  20684.         dw      _.AUXOP
  20685. ssAUXOP:
  20686.         dw      l74d3+7 ;integer type
  20687.         dw      l00ac+1
  20688.         db      0
  20689.         db      'R'+MSB,'TPTUOXUA'
  20690.         db      0,_Ptr
  20691. _.AUXOP equ     $-ssAUXOP
  20692. ;
  20693. ; -->> USRINPTR
  20694. ;
  20695.         dw      _.USRIP
  20696. ssUSRIP:
  20697.         dw      l74d3+7 ;integer type
  20698.         dw      l00b5+1
  20699.         db      0
  20700.         db      'R'+MSB,'TPNIRSU'
  20701.         db      0,_Ptr
  20702. _.USRIP equ     $-ssUSRIP
  20703. ;
  20704. ; -->> USROUTPTR
  20705. ;
  20706.         dw      _.USROP
  20707. ssUSROP:
  20708.         dw      l74d3+7 ;integer type
  20709.         dw      l00b2+1
  20710.         db      0
  20711.         db      'R'+MSB,'TPTUORSU'
  20712.         db      0,_Ptr
  20713. _.USROP equ     $-ssUSROP
  20714. ;
  20715. ; -->> ERRORPTR
  20716. ;
  20717.         dw      _.ERRPT
  20718. ssERRPT:
  20719.         dw      l74d3+7 ;integer type
  20720.         dw      l00da
  20721.         db      0
  20722.         db      'R'+MSB,'TPRORRE'
  20723.         db      0,_Ptr
  20724. _.ERRPT equ     $-ssERRPT
  20725. ;
  20726. ; -->> CBREAK
  20727. ;
  20728.         dw      _.CBRK
  20729. ssCBRK:
  20730.         dw      l74eb+7
  20731.         dw      l00dd
  20732.         db      0
  20733.         db      'K'+MSB,'AERBC'
  20734.         db      0,_Ptr
  20735. _.CBRK  equ     $-ssCBRK
  20736. IntLabTab:
  20737. LenLab  equ     IntLabTab-l731f
  20738. ;
  20739. ; Standard type length table
  20740. ; Note HI-LO entries of definition words
  20741. ;
  20742.  
  20743. dww     macro   val
  20744.         db      HIGH val
  20745.         db      LOW  val
  20746.         endm
  20747.  
  20748. l74d3:
  20749.         dww     2               ; Length for this type
  20750.         dww     MAXINT          ; Max value
  20751.         dww     (-MAXINT-1)     ; Min value
  20752.         dww     _Integ          ; Type
  20753. l74db:
  20754.         dww     1
  20755.         dww     255
  20756.         dww     0
  20757.         dww     _Char
  20758. l74e3:
  20759.         dww     6
  20760.         dww     0
  20761.         dww     0
  20762.         dww     _Real
  20763. l74eb:
  20764.         dww     1
  20765.         dww     _TRUE
  20766.         dww     FALSE
  20767.         dww     _Bool
  20768. l74f3:
  20769.         dww     (FIBlen+RecLng)
  20770.         dww     0
  20771.         dww     0
  20772.         dww     _TxtF
  20773. l74fb:
  20774.         dww     1
  20775.         dww     255
  20776.         dww     0
  20777.         dww     _Integ
  20778. ;
  20779.         dww     (DefSTR+1)
  20780.         dww     0
  20781.         dww     0
  20782.         dww     _String
  20783. l750b:
  20784.         dww     0
  20785.         dww     0
  20786.         dww     0
  20787.         dww     0
  20788. ;
  20789. ; Table of reserved words
  20790. ;
  20791. l7513:
  20792.         db      0
  20793.         dw      l7529
  20794.         db      _Byte
  20795.         dw      l7584
  20796.         db      _Addr
  20797.         dw      l75bb
  20798.         db      _Byte
  20799.         dw      l75f5
  20800.         db      _Byte
  20801.         dw      l7604
  20802.         db      _Byte
  20803.         dw      l761d
  20804.         db      _Byte
  20805.         dw      l7634
  20806.         db      -1
  20807. ;
  20808. ; Keywords
  20809. ;
  20810. l7529:
  20811.         dc      'PROGRAM'
  20812. l7530:
  20813.         dc      'END'
  20814. l7533:
  20815.         dc      'FORWARD'
  20816. l753a:
  20817.         dc      'EXTERNAL'
  20818. l7542:
  20819.         dc      'PACKED'
  20820. l7548:
  20821.         dc      'ARRAY'
  20822. l754d:
  20823.         dc      'FILE'
  20824. l7551:
  20825.         dc      'SET'
  20826. l7554:
  20827.         dc      'RECORD'
  20828. l755a:
  20829.         dc      'STRING'
  20830. l7560:
  20831.         dc      'OF'
  20832. l7562:
  20833.         dc      'ABSOLUTE'
  20834. l756a:
  20835.         dc      'THEN'
  20836. l756e:
  20837.         dc      'ELSE'
  20838. l7572:
  20839.         dc      'DO'
  20840. l7574:
  20841.         dc      'UNTIL'
  20842. l7579:
  20843.         dc      'NOT'
  20844. l757c:
  20845.         dc      'NIL'
  20846.         db      0
  20847. l7580:
  20848.         dc      '..'
  20849. l7582:
  20850.         dc      ':='
  20851. ;
  20852. ; Main block table
  20853. ; -->> Code is type
  20854. ;
  20855. l7584:
  20856.         dc      'LABEL'
  20857.         db      1
  20858.         dc      'CONST'
  20859.         db      2
  20860.         dc      'TYPE'
  20861.         db      3
  20862. l7595:
  20863.         dc      'VAR'
  20864.         db      4
  20865.         dc      'BEGIN'
  20866.         db      8
  20867. l759f:
  20868.         dc      'OVERLAY'
  20869.         db      7
  20870. l75a7:
  20871.         dc      'PROCEDURE'
  20872.         db      5
  20873.         dc      'FUNCTION'
  20874.         db      6
  20875.         db      0
  20876. ;
  20877. ; Statement table
  20878. ;
  20879. l75bb:
  20880.         dc      'BEGIN'
  20881.         dw      l5377
  20882.         dc      'IF'
  20883.         dw      l53ef
  20884.         dc      'WHILE'
  20885.         dw      l5424
  20886.         dc      'REPEAT'
  20887.         dw      l544c
  20888.         dc      'FOR'
  20889.         dw      l546b
  20890. l75da:
  20891.         dc      'CASE'
  20892.         dw      l5521
  20893.         dc      'GOTO'
  20894.         dw      l5626
  20895.         dc      'WITH'
  20896.         dw      l564e
  20897.         dc      'INLINE'
  20898.         dw      l5698
  20899.         db      0
  20900. l75f5:
  20901.         dc      'TO'
  20902.         inc     hl
  20903.         dc      'DOWNTO'
  20904.         dec     hl
  20905.         db      0
  20906. l7600:
  20907.         db      '*'+0x80
  20908.         db      0
  20909.         db      '/'+0x80
  20910.         db      1
  20911. l7604:
  20912.         dc      'AND'
  20913.         db      2
  20914.         dc      'DIV'
  20915.         db      3
  20916.         dc      'MOD'
  20917.         db      4
  20918.         dc      'SHL'
  20919.         db      5
  20920.         dc      'SHR'
  20921.         db      6
  20922.         db      0
  20923. l7619:
  20924.         db      '+'+0x80
  20925.         db      0
  20926.         db      '-'+0x80
  20927.         db      1
  20928. l761d:
  20929.         dc      'OR'
  20930.         db      2
  20931.         dc      'XOR'
  20932.         db      3
  20933.         db      0
  20934. l7625:
  20935.         db      '='+0x80
  20936.         db      00000000b
  20937.         db      '<','>'+0x80
  20938.         db      00001000b
  20939.         db      '>','='+0x80
  20940.         db      00010000b
  20941.         db      '<','='+0x80
  20942.         db      00011000b
  20943.         db      '>'+0x80
  20944.         db      00100000b
  20945.         db      '<'+0x80
  20946.         db      00101000b
  20947. l7634:
  20948.         dc      'IN'
  20949.         db      11111111b
  20950.         db      0
  20951. l7638:
  20952.         dc      'WRITELN'
  20953.         dw      l5ae7
  20954.         dc      'WRITE'
  20955.         dw      l5ae8
  20956.         dc      'READLN'
  20957.         dw      l5a32
  20958.         dc      'READ'
  20959.         dw      l5a33
  20960.         dc      'DELETE'
  20961.         dw      l5c66
  20962.         dc      'INSERT'
  20963.         dw      l5c87
  20964.         dc      'ASSIGN'
  20965.         dw      l5943
  20966.         dc      'RESET'
  20967.         dw      l59b9
  20968.         dc      'REWRITE'
  20969.         dw      l59be
  20970.         dc      'CLOSE'
  20971.         dw      l59db
  20972.         dc      'ERASE'
  20973.         dw      l5971
  20974.         dc      'RENAME'
  20975.         dw      l5966
  20976.         dc      'SEEK'
  20977.         dw      l598c
  20978.         dc      'GETMEM'
  20979.         dw      l5d94
  20980.         dc      'NEW'
  20981.         dw      l5d9f
  20982.         dc      'FREEMEM'
  20983.         dw      l5db4
  20984.         dc      'DISPOSE'
  20985.         dw      l5dbf
  20986.         dc      'MARK'
  20987.         dw      l5dd4
  20988.         dc      'RELEASE'
  20989.         dw      l5dd9
  20990.         dc      'OVRDRIVE'
  20991.         dw      l5df9
  20992.         dc      'CRTINIT'
  20993.         dw      l5e38
  20994.         dc      'CRTEXIT'
  20995.         dw      l5e3d
  20996.         dc      'GOTOXY'
  20997.         dw      l5d6d
  20998.         dc      'CLRSCR'
  20999.         dw      l5e42
  21000.         dc      'CLREOL'
  21001.         dw      l5e48
  21002.         dc      'NORMVIDEO'
  21003.         dw      l5e4d
  21004.         dc      'HIGHVIDEO'
  21005.         dw      l5e4d
  21006.         dc      'LOWVIDEO'
  21007.         dw      l5e52
  21008.         dc      'INSLINE'
  21009.         dw      l5e57
  21010.         dc      'DELLINE'
  21011.         dw      l5e5c
  21012.         dc      'DELAY'
  21013.         dw      l5d89
  21014.         dc      'BLOCKREAD'
  21015.         dw      l5c16
  21016.         dc      'BLOCKWRITE'
  21017.         dw      l5c1e
  21018.         dc      'RANDOMIZE'
  21019.         dw      l5d83
  21020.         dc      'MOVE'
  21021.         dw      l5e05
  21022.         dc      'FILLCHAR'
  21023.         dw      l5e1a
  21024.         dc      'EXIT'
  21025.         dw      l5e61
  21026.         dc      'HALT'
  21027.         dw      l5e67
  21028.         dc      'PORT'
  21029.         dw      l5e6d
  21030.         dc      'STACKPTR'
  21031.         dw      l5e78
  21032.         dc      'FLUSH'
  21033.         dw      l59ab
  21034.         dc      'EXECUTE'
  21035.         dw      l597e
  21036.         dc      'CHAIN'
  21037.         dw      l5979
  21038.         dc      'STR'
  21039.         dw      l5cba
  21040.         dc      'VAL'
  21041.         dw      l5d22
  21042.         dc      'BDOS'
  21043.         dw      l6553
  21044.         dc      'BIOS'
  21045.         dw      l651e
  21046.         db      0
  21047. l77b1:
  21048.         dc      'CHR'
  21049.         dw      l6425
  21050.         dc      'ORD'
  21051.         dw      l6411
  21052.         dc      'COPY'
  21053.         dw      l6460
  21054.         dc      'LENGTH'
  21055.         dw      l6441
  21056.         dc      'POS'
  21057.         dw      l6452
  21058.         dc      'CONCAT'
  21059.         dw      l6481
  21060.         dc      'SUCC'
  21061.         dw      l63d4
  21062.         dc      'PRED'
  21063.         dw      l63d7
  21064.         dc      'UPCASE'
  21065.         dw      l6437
  21066.         dc      'TRUNC'
  21067.         dw      l63be
  21068.         dc      'ROUND'
  21069.         dw      l63c3
  21070.         dc      'ODD'
  21071.         dw      l6401
  21072.         dc      'ABS'
  21073.         dw      l6371
  21074.         dc      'SQR'
  21075.         dw      l6360
  21076.         dc      'SQRT'
  21077.         dw      l6385
  21078.         dc      'SIN'
  21079.         dw      l638a
  21080.         dc      'COS'
  21081.         dw      l638f
  21082.         dc      'ARCTAN'
  21083.         dw      l6394
  21084.         dc      'LN'
  21085.         dw      l6399
  21086.         dc      'EXP'
  21087.         dw      l639e
  21088.         dc      'INT'
  21089.         dw      l63a3
  21090.         dc      'FRAC'
  21091.         dw      l63a8
  21092.         dc      'RANDOM'
  21093.         dw      l64ac
  21094.         dc      'PARAMCOUNT'
  21095.         dw      l649c
  21096.         dc      'PARAMSTR'
  21097.         dw      l64a1
  21098.         dc      'LO'
  21099.         dw      l63e1
  21100.         dc      'HI'
  21101.         dw      l63eb
  21102.         dc      'SWAP'
  21103.         dw      l63f6
  21104.         dc      'PTR'
  21105.         dw      l642b
  21106.         dc      'IORESULT'
  21107.         dw      l64c4
  21108.         dc      'EOF'
  21109.         dw      l64c9
  21110.         dc      'EOLN'
  21111.         dw      l64df
  21112.         dc      'SEEKEOF'
  21113.         dw      l64d5
  21114.         dc      'SEEKEOLN'
  21115.         dw      l64da
  21116.         dc      'FILESIZE'
  21117.         dw      l64fa
  21118.         dc      'FILEPOS'
  21119.         dw      l64f2
  21120.         dc      'KEYPRESSED'
  21121.         dw      l640c
  21122.         dc      'MEMAVAIL'
  21123.         dw      l6514
  21124.         dc      'MAXAVAIL'
  21125.         dw      l6519
  21126.         dc      'PORT'
  21127.         dw      l65bf
  21128.         dc      'STACKPTR'
  21129.         dw      l65ca
  21130.         dc      'ADDR'
  21131.         dw      l6576
  21132.         dc      'SIZEOF'
  21133.         dw      l659d
  21134.         dc      'BDOSHL'
  21135.         dw      l6553
  21136.         dc      'BDOS'
  21137.         dw      l6554
  21138.         dc      'BIOSHL'
  21139.         dw      l651e
  21140.         dc      'BIOS'
  21141.         dw      l651f
  21142.         db      0
  21143. l78fa:
  21144.         dc      'MEM'
  21145.         dw      0
  21146.         db      0
  21147. ;
  21148. ; Start of dynamic data
  21149. ; - originally at page boundary - here : 7900h
  21150. ;
  21151. ; Dynamic data area starts - shared by editor and compiler most
  21152. ;
  21153. CmpTyp:
  21154.         db      1ah             ; Compile flag:
  21155.                                 ; 0: Compile to memory
  21156.                                 ; 1: Compile to .COM/.CHN file
  21157.                                 ; 2: Searching
  21158. l7901:
  21159.         db      'd'             ; Error code
  21160. CodePC:
  21161.         db      'SE'            ; Code pointer
  21162. l7904:
  21163.         db      'EK'            ; Code start address
  21164. l7906:
  21165.         db      'EO'            ; Code end address
  21166. DataBeg:
  21167.         db      'L',0ceh        ; Start of data
  21168. l790a:
  21169.         db      0dah,'d'        ; End of code address
  21170. l790c:
  21171.         db      'FI'            ; Current editor address
  21172. IncFlg:
  21173.         db      'L'             ; Memory read flag (0 is read)
  21174. l790f:
  21175.         db      'ESIZ',0c5h,0fah,'dFILEPO',0d3h,0f2h
  21176.         db      'dKEYPRESSE',0c4h,0ch,'dMEMAVAI',0cch
  21177. ;
  21178. ; FCB of source file
  21179. ;
  21180. FFCB: ;36 bytes???
  21181.         db      14h
  21182.         db      'eMAXAVAI'
  21183.         db      0cch
  21184.         db      19h,'ePOR',0d4h,0bfh,'eSTACKPT'
  21185.         db      0d2h,0cah,'eADD',0d2h,'v'
  21186.         db      'eSI'
  21187. ;
  21188. ; DISK BUFFER
  21189. ;
  21190. TmpBuff:
  21191.         db      'ZEO',0c6h,9dh,'eBDOS'
  21192.         db      'H',0cch,'SeBDO',0d3h,'TeBIOSH'
  21193.         db      0cch,1eh,'eBIO',0d3h,1fh,'e'
  21194.         db      0,'ME',0cdh,0,0,0
  21195. l7980:: ;;**
  21196.  
  21197. l79d7   equ     TmpBuff+RecLng  ; Start of source line
  21198. l7a57   equ     l79d7+RecLng
  21199. l7ad7   equ     l7a57+RecLng    ; Top of used memory on start
  21200. Envir1  equ     l7ad7+RecLng
  21201. l7b58   equ     Envir1+1                ; Value of symbol
  21202. l7b59   equ     l7b58+1
  21203. l7b5a   equ     l7b59+1         ; Type table
  21204. l7b5c   equ     l7b5a+2         ; Type
  21205. l7b5d   equ     l7b5c+1
  21206. l7b5e   equ     l7b5d+1         ; Lo set limit
  21207. l7b60   equ     l7b5e+2         ; Hi set limit
  21208. l7b62   equ     l7b60+2         ; Length of type
  21209. Envir2  equ     l7b62+2
  21210. l7b65   equ     Envir2+1
  21211. l7b69   equ     l7b65+4
  21212. l7b6b   equ     l7b69+2
  21213. l7b6d   equ     l7b6b+2         ; Last memory address
  21214. l7b6f   equ     l7b6d+2         ; TEMP
  21215. l7b71   equ     l7b6f+2         ; TEMP
  21216. l7b72   equ     l7b71+1         ; EDT: Pointer to delimters
  21217. LabPtr  equ     l7b72+1         ; Label pointer
  21218. l7b74   equ     LabPtr+1                ; EDT: Edited line
  21219. PrevLabPtr      equ     l7b74+1         ; Previous label pointer
  21220. l7b77   equ     PrevLabPtr+2            ; Top of available memory
  21221. l7b79   equ     l7b77+2
  21222. CurLab  equ     l7b79+2         ; Current label pointer
  21223. l7b7d   equ     CurLab+2
  21224. l7b7f   equ     l7b7d+2
  21225. l7b81   equ     l7b7f+2
  21226. l7b83   equ     l7b81+2
  21227. l7b85   equ     l7b83+2
  21228. l7b87   equ     l7b85+2
  21229. l7b88   equ     l7b87+1
  21230. l7b89   equ     l7b88+1
  21231. l7b8b   equ     l7b89+2
  21232. l7b8d   equ     l7b8b+2
  21233. l7b8f   equ     l7b8d+2
  21234. l7b90   equ     l7b8f+1
  21235. l7b91   equ     l7b90+1         ; ???
  21236. l7b92   equ     l7b91+1         ; ???
  21237. curtype_l7b93   equ     l7b92+1         ; Type
  21238. l7b94   equ     curtype_l7b93+1         ; ???
  21239. l7b95   equ     l7b94+1
  21240. l7b96   equ     l7b95+1         ; OVERLAY number
  21241. l7b97   equ     l7b96+1         ; PROCEDURE (=0) or FUNCTION (<>0)
  21242. l7b98   equ     l7b97+1
  21243. l7b99   equ     l7b98+1         ; Overlay flag (-1)
  21244. l7b9a   equ     l7b99+1
  21245. l7b9b   equ     l7b9a+1
  21246. l7b9c   equ     l7b9b+1
  21247. l7b9d   equ     l7b9c+1         ; Option bits
  21248. l7b9e   equ     l7b9d+1         ; Local PROCEDURE/FUNCTION options
  21249. l7b9f   equ     l7b9e+1
  21250. l7ba0   equ     l7b9f+1         ; End on break
  21251. l7ba1   equ     l7ba0+1
  21252. l7ba2   equ     l7ba1+1         ; End of file
  21253. l7ba3   equ     l7ba2+1
  21254. l7ba4   equ     l7ba3+1
  21255. l7ba6   equ     l7ba4+2
  21256. l7ba7   equ     l7ba6+1
  21257. l7ba9   equ     l7ba7+2
  21258. l7bab   equ     l7ba9+2         ; Data pointer for overlay
  21259. l7bb0   equ     l7bab+5         ; Length of overlay
  21260. l7bb2   equ     l7bb0+2         ; OVERLAY file name
  21261. l7bbd   equ     l7bb2+11
  21262. l7bbe   equ     l7bbd+1
  21263. FirstVAR        equ     l7bbe+2
  21264. l7bc1   equ     FirstVAR+1
  21265. l7bc2   equ     l7bc1+1
  21266. l7bc4   equ     l7bc2+2
  21267. l7bc6   equ     l7bc4+2
  21268. l7bc7   equ     l7bc6+1         ; Depth for WITH
  21269. l7bc8   equ     l7bc7+1
  21270. l7bc9   equ     l7bc8+1
  21271. l7bca   equ     l7bc9+1
  21272. l7bcc   equ     l7bca+2
  21273. Env_PC  equ     l7bcc+9
  21274. l7bd7   equ     Env_PC+2                ; Source pointer
  21275. l7bd9   equ     l7bd7+2         ; Dtto.
  21276. RRN_stat        equ     l7bd9+2         ; File access
  21277. RecPtr  equ     RRN_stat +1             ; Record pointer
  21278. RRN_off equ     RecPtr+1                ; Record base
  21279. MemsTop equ     RRN_off+2
  21280. COMsTop equ     MemsTop+2               ; Top of .COM file
  21281. BackLevel       equ     COMsTop+2               ; Back fix level
  21282. l7be4   equ     BackLevel+1             ; Saved top of .COM file
  21283. INCsTop equ     l7be4+2
  21284. l7be8   equ     INCsTop+2
  21285. l7be9   equ     l7be8+1
  21286. l7beb   equ     l7be9+2
  21287. l7bed   equ     l7beb+2
  21288. l7bef   equ     l7bed+2         ; Line count
  21289. l7bf5   equ     l7bef+6         ; Start of text
  21290.  
  21291. end
  21292.         savebin "tp.com",begin,end-begin
  21293.        
  21294.         LABELSLIST "../../us/user.l"
  21295.