?login_element?

Subversion Repositories NedoOS

Rev

Rev 730 | Go to most recent revision | 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 ;TODO (return A=current drive)
  52. _setdma equ     26 ;
  53. _getalv equ     27 ;TODO
  54. _getdpb equ     31 ;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)       ; 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       ; 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       ; 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)       ; 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    ; 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       ; 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)       ; 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      ; Save address
  1146.         ld      a,b
  1147.         ld      (l00dd),a       ; 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       ; Clear I/O error
  1168.         ld      (l00d4),hl      ; Clear some pointers
  1169.         ld      (l00d6),hl
  1170.         ld      a,_MaxBuf
  1171.         ld      (l00d1),a       ; Set buffer length
  1172.         ld      (l00e0),a       ; 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)    ; Load old values
  2310.         ld      de,(l00c8)
  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      ; Save new values
  2333.         ex      de,hl
  2334.         ld      hl,0011011000011001b
  2335.         adc     hl,bc           ; Add 3619H
  2336.         ld      (l00c8+2),hl
  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
  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)      ; 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)      ; 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       ; Put into mode
  4722.         pop     iy              ; Get back caller
  4723.         ld      hl,(l00d2)      ; 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      ; 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
  4736.         ret
  4737. l1390:
  4738.         ld      a,(l00e8)       ; 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)      ; Get back FIB
  4744.         ld      (hl),a          ; Set flag
  4745.         ret
  4746. l13a0:
  4747.         call    l03f2           ; Parse file
  4748.         ld      hl,(l00e2)
  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)      ; 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       ; Set mode (0=RESET)
  4831.         call    l1469           ; Close open file
  4832.         ld      a,(l00d0)
  4833.         or      a               ; Test error
  4834.         ret     nz              ; End if so
  4835.         ld      hl,(l00e2)      ; 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)
  4842.         or      a               ; Test error
  4843.         ret     nz              ; Exit if so
  4844.         ld      hl,(l00e2)      ; Get back FIB
  4845.         ld      a,(l00e8)       ; 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)      ; Get FIB
  4862.         ld      de,FIB.FCB
  4863.         add     hl,de           ; Point to FCB
  4864.         ex      de,hl
  4865.         ld      a,(l00e8)       ; 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       ; Set error if not
  4884.         ret
  4885. ;
  4886. ; Clear FCB of current FIB
  4887. ;
  4888. l145a:
  4889.         ld      hl,(l00e2)      ; 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      ; 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)      ; 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       ; 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      ; Save caller
  4941.         ex      (sp),hl
  4942.         push    hl
  4943.         ld      hl,l00c2
  4944.         ld      (l00e2),hl      ; 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      ; Save caller for error
  4954.         ex      (sp),hl
  4955.         ld      (l00e2),hl      ; Save FIB
  4956.         bit     in.bit,(hl)     ; Test read allowed
  4957.         ret     nz              ; Yeap
  4958.         ld      a,_NoRead
  4959.         ld      (l00d0),a       ; 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      ; Save caller for error
  4968.         ex      (sp),hl
  4969.         ld      (l00e2),hl      ; Save FIB
  4970.         bit     out.bit,(hl)    ; Test write allowed
  4971.         ret     nz              ; Yeap
  4972.         ld      a,_NoWrite
  4973.         ld      (l00d0),a       ; 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      ; Save it
  4990.         ex      (sp),hl
  4991.         push    hl
  4992.         ld      hl,l00c2
  4993.         ld      (l00e2),hl      ; 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)      ; Get top of memory
  5019.         ld      (l00d4),hl      ; 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)       ; Get $C mode
  5044.         or      a               ; Test abort
  5045.         jr      z,l14ff         ; $C- - so ignore
  5046.         ld      ix,(l00e4)
  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      ; Set top pointer
  5099.         ret
  5100. ;
  5101. ; Get character from file or console buffer
  5102. ;
  5103. l156b:
  5104.         ld      hl,(l00e2)      ; Get FIB
  5105.         ld      a,(l00d0)
  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)
  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)      ; Get current pointer
  5182.         ld      de,(l00d6)      ; 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)      ; Get current pointer
  5190.         ld      a,(hl)
  5191.         inc     hl              ; Bump
  5192.         ld      (l00d4),hl
  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)      ; 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)      ; 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       ; 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)      ; Get FIB
  5422.         ld      c,a             ; Save character
  5423.         ld      a,(l00d0)
  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)      ; Get string pointer
  5460.         ld      a,(l00ea)       ; 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)      ; 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       ; 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)      ; 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)      ; 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)      ; 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      ; 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       ; Set mode (0=RESET)
  5722.         ld      (l00e6),de      ; Save record length
  5723.         call    l187a           ; Close file
  5724.         ld      a,(l00d0)       ; Test error
  5725.         or      a
  5726.         ret     nz              ; End if so
  5727.         call    l1430           ; Set up FIB ;opens/creates file!!!
  5728.         ld      a,(l00d0)       ; Test error
  5729.         or      a
  5730.         ret     nz              ; End if so
  5731.         ld      hl,(l00e2)      ; 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)
  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)
  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       ; 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)      ; 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      ; 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)      ; 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      ; Save caller
  5823.         ex      (sp),hl
  5824.         ld      (l00e2),hl      ; 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       ; 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)       ; 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)      ; 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)       ; 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)
  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       ; 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       ; Save code
  5907.         ex      de,hl
  5908. l190d:
  5909.         ld      hl,(l00e2)      ; 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)       ; 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)       ; 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)      ; Get back FIB
  5942. l1943:
  5943.         ld      a,(l00e9)       ; 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)      ; 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       ; 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)       ; 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      ; 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)      ; 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)      ; 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      ; 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)      ; 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)      ; 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       ; 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)      ; 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.         xor     a
  6224.         ld      (l00e8),a       ; Save mode (0=RESET)
  6225.         call    l1ab0           ; Close open file
  6226.         ld      a,(l00d0)
  6227.         or      a               ; Test error
  6228.         ret     nz              ; Exit if so
  6229.         call    l1430           ; Fix FIB
  6230.         ld      a,(l00d0)
  6231.         or      a               ; Test error
  6232.         ret     nz              ; Exit if so
  6233.         ld      hl,(l00e2)      ; Get FIB
  6234.         ld      (hl),_.in+_.out ; Set flag
  6235.         push    hl
  6236.         ld      de,FIB.FCB
  6237.         add     hl,de           ; Point to FCB
  6238.         ex      de,hl
  6239.         ld      c,_filsiz
  6240.         call    BDOS            ; Get size of file
  6241.         pop     hl
  6242.         ld      de,FIB.FCB+_rrn
  6243.         add     hl,de           ; Point to size
  6244.         xor     a
  6245.         ld      c,(hl)          ; Get size
  6246.         ld      (hl),a          ; Reset size
  6247.         inc     hl
  6248.         ld      b,(hl)
  6249.         ld      (hl),a
  6250.         ld      de,FIB.rec-FIB.FCB-_rrn-1
  6251.         add     hl,de           ; Point to recird number
  6252.         ld      (hl),c          ; Set it
  6253.         inc     hl
  6254.         ld      (hl),b
  6255.         inc     hl
  6256.         ld      (hl),RecLng     ; Set standard record
  6257.         inc     hl
  6258.         ld      (hl),a
  6259.         inc     hl
  6260.         ld      (hl),a          ; Init current record
  6261.         inc     hl
  6262.         ld      (hl),a
  6263.         ret
  6264. ;
  6265. ; Close untyped file
  6266. ; ENTRY Reg HL holds FIB
  6267. ;
  6268. ; Procedure CLOSE(un_typed_file)
  6269. ;
  6270. l1ab0:
  6271.         ld      (l00e2),hl      ; Save FIB
  6272.         ld      a,(hl)          ; Get mode
  6273.         and     _.in+_.out      ; Test access
  6274.         ret     z               ; Nope
  6275.         jp      l1481           ; Close it
  6276. ;
  6277. ; Write block to untyped file
  6278. ; Procedure BLOCKWRITE(file,buffer,count)
  6279. ; ENTRY Reg HL holds number of records to be written
  6280. ;       On stack FIB and buffer
  6281. ;
  6282. l1aba:
  6283.         ld      a,_rndwr        ; Set function code
  6284.         jr      l1ac0
  6285. ;
  6286. ; Read block from untyped file
  6287. ; Procedure BLOCKREAD(file,buffer,count)
  6288. ; ENTRY Reg HL holds number of records to be read
  6289. ;       On stack FIB and buffer
  6290. ;
  6291. l1abe:
  6292.         ld      a,_rndrd        ; Set function code
  6293. l1ac0:
  6294.         ld      b,h             ; Copy count
  6295.         ld      c,l
  6296.         ld      hl,l00f0        ; Point to scratch
  6297.         ld      (l00e6),hl      ; Set for record
  6298.         pop     ix
  6299.         pop     de              ; Get buffer
  6300.         pop     hl              ; Get FIB
  6301.         push    ix
  6302.         push    bc
  6303.         call    l1afd           ; Execute block I/O
  6304.         pop     bc
  6305.         ld      a,(l00d0)
  6306.         or      a               ; Test error
  6307.         ret     nz              ; Exit if so
  6308.         ld      hl,(l00f0)
  6309.         sbc     hl,bc           ; Test all records processed
  6310.         ret     z               ; Yeap
  6311.         ld      a,(l00e9)       ; Get file function
  6312.         cp      _rndrd          ; Test read
  6313.         ld      a,_IllEOF
  6314.         jr      z,l1ae9
  6315.         ld      a,_WrErr
  6316. l1ae9:
  6317.         ld      (l00d0),a       ; Set error code accordingly
  6318.         ret
  6319. ;
  6320. ; Write block to untyped file
  6321. ; Procedure BLOCKWRITE(file,buffer,count,result)
  6322. ; ENTRY Reg HL points to result
  6323. ;       On stack FIB, buffer and number of records
  6324. ;
  6325. l1aed:
  6326.         ld      a,_rndwr        ; Set function
  6327.         jr      l1af3
  6328. ;
  6329. ; Read block from untyped file
  6330. ; Procedure BLOCKREAD(file,buffer,count,result)
  6331. ; ENTRY Reg HL points to result
  6332. ;       On stack FIB, buffer and number of records
  6333. ;
  6334. l1af1:
  6335.         ld      a,_rndrd        ; Set function
  6336. l1af3:
  6337.         ld      (l00e6),hl      ; Save result pointer
  6338.         pop     ix
  6339.         pop     bc              ; Get count
  6340.         pop     de              ; Get buffer
  6341.         pop     hl              ; Get FIB
  6342.         push    ix
  6343. ;
  6344. ; Perform block IO
  6345. ; ENTRY Accu holds file function
  6346. ;       Reg HL holds FIB
  6347. ;       Reg DE holds buffer
  6348. ;
  6349. l1afd:
  6350.         ld      (l00e9),a       ; Save function
  6351.         ld      (l00e2),hl      ; Save FIB
  6352.         ld      a,(hl)          ; Get mode
  6353.         and     _.in+_.out      ; Test IO allowed
  6354.         jp      z,l18b0         ; Nope
  6355.         ld      hl,(l00e6)      ; Get record address
  6356.         xor     a
  6357.         ld      (hl),a          ; Clear record
  6358.         inc     hl
  6359.         ld      (hl),a
  6360. l1b10:
  6361.         ld      a,b
  6362.         or      c               ; Test all done
  6363.         jr      z,l1b4d         ; Yeap
  6364.         push    bc
  6365.         push    de
  6366.         ld      c,_setdma
  6367.         call    BDOS            ; Set disk buffer
  6368.         ld      hl,(l00e2)      ; Get back FIB
  6369.         ld      de,FIB.FCB
  6370.         add     hl,de           ; Point to FCB
  6371.         ex      de,hl
  6372.         ld      a,(l00e9)       ; Get file function
  6373.         ld      c,a
  6374.         call    BDOS            ; Execute I/O
  6375.         pop     de
  6376.         pop     bc
  6377.         or      a               ; Test result
  6378.         jr      nz,l1b4d        ; Not good
  6379.         push    de
  6380.         ld      hl,(l00e2)      ; Get FIB again
  6381.         ld      de,FIB.FCB+_rrn
  6382.         add     hl,de           ; Point to record
  6383.         inc     (hl)            ; Advance record
  6384.         jr      nz,l1b3c
  6385.         inc     hl
  6386.         inc     (hl)
  6387. l1b3c:
  6388.         pop     de
  6389.         ld      hl,RecLng
  6390.         add     hl,de           ; Advance buffer
  6391.         ex      de,hl
  6392.         ld      hl,(l00e6)
  6393.         inc     (hl)            ; Advance record count
  6394.         jr      nz,l1b4a
  6395.         inc     hl
  6396.         inc     (hl)
  6397. l1b4a:
  6398.         dec     bc              ; Count down requested length
  6399.         jr      l1b10
  6400. l1b4d:
  6401.         ld      hl,(l00e2)      ; Get FIB
  6402.         ld      de,FIB.FCB+_rrn
  6403.         add     hl,de           ; Point to last record
  6404.         ld      c,(hl)
  6405.         inc     hl
  6406.         ld      b,(hl)
  6407.         ld      de,FIB.cur-FIB.FCB-_rrn-1
  6408.         add     hl,de           ; Point to FIB record
  6409.         ld      (hl),c          ; Save record number
  6410.         inc     hl
  6411.         ld      (hl),b
  6412.         ld      de,-FIB.rec
  6413.         add     hl,de           ; Point to record
  6414.         ld      d,(hl)
  6415.         dec     hl
  6416.         ld      e,(hl)
  6417.         ex      de,hl
  6418.         or      a
  6419.         sbc     hl,bc           ; Test against last record
  6420.         ret     nc
  6421.         ex      de,hl
  6422.         ld      (hl),c          ; Save new max record
  6423.         inc     hl
  6424.         ld      (hl),b
  6425.         ret
  6426. ;
  6427. ; Procedure SEEK(file,record)
  6428. ; ENTRY Reg HL holds record seeked for
  6429. ;       FIB pushed onto stack
  6430. ;
  6431. l1b6f:
  6432.         pop     bc
  6433.         pop     de
  6434.         ld      (l00e2),de      ; Save FIB
  6435.         push    bc
  6436.         push    hl
  6437.         call    l1a5a           ; Get record data
  6438.         pop     de
  6439.         or      a
  6440.         sbc     hl,de           ; Test position
  6441.         jp      c,l1a26         ; Error if overflow
  6442.         ld      hl,(l00e2)      ; Get FIB
  6443.         ld      bc,FIB.cur
  6444.         add     hl,bc
  6445.         ld      (hl),e          ; Save new position
  6446.         inc     hl
  6447.         ld      (hl),d
  6448.         ld      bc,FIB.FCB+_rrn-FIB.cur-1
  6449.         add     hl,bc
  6450.         ld      (hl),e          ; Save in FCB, too
  6451.         inc     hl
  6452.         ld      (hl),d
  6453.         ret
  6454. ;
  6455. ; Delete file
  6456. ; Procedure ERASE(file)
  6457. ; ENTRY Reg HL holds FIB
  6458. ;
  6459. l1b93:
  6460.         call    l1c4c           ; Check legal FIB
  6461.         ret     nz              ; Nope
  6462.         ld      de,FIB.FCB
  6463.         add     hl,de           ; Point to FCB
  6464.         ex      de,hl
  6465.         ld      c,_delete
  6466.         call    BDOS            ; Delete file
  6467.         inc     a
  6468.         ret     nz
  6469.         jr      l1be4           ; Set error if unknown
  6470. ;
  6471. ; Rename file
  6472. ; Procedure RENAME(file,newname)
  6473. ; ENTRY FIB and name on stack
  6474. ;
  6475. l1ba5:
  6476.         pop     iy
  6477.         ld      hl,(l00d2)      ; Get top of memory for buffer
  6478.         ld      b,16            ; Set max
  6479.         call    l05e2           ; Assign string from stack
  6480.         xor     a
  6481.         ld      (de),a
  6482.         pop     hl              ; Load FIB
  6483.         push    iy
  6484.         call    l1c4c           ; Check legal FIB
  6485.         ret     nz              ; Nope
  6486.         push    hl
  6487.         call    l03f2           ; Parse file
  6488.         pop     hl
  6489.         push    hl
  6490.         ld      de,FIB.FCB+DIRlen
  6491.         add     hl,de           ; Point to 2nd FCB
  6492.         ex      de,hl
  6493.         ld      hl,l005c
  6494.         ld      bc,Fdrv+Fname+Fext
  6495.         ldir                    ; move new name
  6496.         pop     hl
  6497.         ld      de,FIB.FCB
  6498.         add     hl,de           ; Point to FCB
  6499.         push    hl
  6500.         ex      de,hl
  6501.         ld      c,_rename
  6502.         call    BDOS            ; Rename
  6503.         pop     de
  6504.         inc     a               ; Test success
  6505.         jr      z,l1be4         ; Nope
  6506.         ld      hl,l005c
  6507.         ld      bc,FCBlen
  6508.         ldir                    ; Unpack new file
  6509.         ret
  6510. l1be4:
  6511.         ld      a,_NoFile       ; Set error
  6512. l1be6:
  6513.         ld      (l00d0),a
  6514.         ret
  6515. ;
  6516. ; Perform executing new programs
  6517. ; Procedure EXECUTE(File)
  6518. ; ENTRY Reg HL points to FIB
  6519. ;
  6520. l1bea:
  6521.         db      skip
  6522. ;
  6523. ; Procedure CHAIN(File)
  6524. ;
  6525. l1beb:
  6526.         xor     a
  6527.         ld      (l00e8),a       ; Set mode (0=CHAIN)
  6528.         call    l1c4c           ; Test device ok
  6529.         ret     nz              ; Nope
  6530.         ld      a,(l00d8)       ; Test run mode
  6531.         or      a
  6532.         ld      a,_DirErr
  6533.         jr      z,l1be6         ; Must *NOT* be direct mode
  6534.         ld      hl,(l00e2)      ; Get FIB
  6535.         ld      de,FIB.FCB
  6536.         add     hl,de           ; Point to FCB
  6537.         ld      de,l005c
  6538.         ld      bc,FCBlen
  6539.         ldir                    ; move to standard FCB
  6540.         ld      de,l005c
  6541.         ld      c,_open
  6542.         call    BDOS            ; Open file ;WHERE IS CLOSE???
  6543.         inc     a
  6544.         jr      z,l1be4         ; File not found
  6545.         ld      hl,l1c33        ; Point to loader
  6546.         ld      de,l00b0
  6547.         ld      bc,l0019
  6548.         ldir                    ; move loader to temporry location
  6549.         ld      de,0x0100;TPA           ; Init loader address
  6550.         ld      a,(l00e8)       ; Test mode
  6551.         or      a
  6552.         jr      nz,l1c2d
  6553.         ld      de,(progstartaddr);(TPA+1)      ; Change address for CHAIN
  6554. l1c2d:
  6555.         ld      sp,0x0100;TPA           ; Get local stack
  6556.         jp      l00b0           ; Go load
  6557. ;
  6558. ; ############### Start of loader ###############
  6559. ;
  6560. ; Loader will be moved into 00B0H temporary location
  6561. ;
  6562. l1c33:
  6563.         disp    l00b0
  6564. _l1c33:
  6565.         push    de
  6566.         ld      c,_setdma
  6567.         call    BDOS            ; Set disk buffer
  6568.         ld      de,l005c
  6569.         ld      c,_rdseq
  6570.         call    BDOS            ; Read a code record
  6571.         pop     de
  6572.         ld      hl,RecLng
  6573.         add     hl,de           ; Bump address
  6574.         ex      de,hl
  6575.         ;or     a               ; Test more
  6576.         ;jr     z,_l1c33
  6577.          cp 128 ;EOF in NedoOS
  6578.          jr nz,_l1c33           ; Read was successfull
  6579.          ;jr $
  6580.         jr      0x0100;TPA              ; Start after loading
  6581. l0019   equ     $-_l1c33
  6582.         ent
  6583. ;
  6584. ; ################ End of loader ################
  6585. ;
  6586. ; Check legal device for file operation
  6587. ; ENTRY Reg HL points to FIB
  6588. ; EXIT  Zero flag set if legal device
  6589. ;       If illegal, IOerror 20H will be set
  6590. ;
  6591. l1c4c:
  6592.         ld      (l00e2),hl      ; Save FIB
  6593.         ld      a,(hl)          ; Get flag
  6594.         and     FIBtype         ; Mask it
  6595.         ret     z               ; 0000 menas file
  6596.         ld      a,_IllIO
  6597.         ld      (l00d0),a       ; Set error
  6598.         ret
  6599. ;
  6600. ; Load overlay file
  6601. ; ENTRY Reg HL holds record procedure starts with
  6602. ;       Reg DE holds number of records to be read
  6603. ;
  6604. ; Overlay call follows:
  6605. ;           2 Bytes hold last sector read
  6606. ;          11 Bytes NAME.EXT of file
  6607. ;       n*128 Bytes record(s)
  6608. ;
  6609. l1c59:
  6610.         ld      (l00e6),hl      ; Save record
  6611.         ld      (l00e8),de      ; Save record count
  6612.         ex      de,hl
  6613.         pop     hl
  6614.         ld      (l00e2),hl      ; Save caller
  6615.         ld      c,(hl)          ; Fetch last sector
  6616.         ld      (hl),e          ; Set new one
  6617.         inc     hl
  6618.         ld      b,(hl)
  6619.         ld      (hl),d
  6620.         ex      de,hl           ; Compare bew:old
  6621.         or      a
  6622.         sbc     hl,bc
  6623.         jr      z,l1cca         ; Overlay already in memory
  6624.         ex      de,hl
  6625.         inc     hl
  6626.         ld      de,l005c
  6627.         ld      a,(l00dc)       ; Get overlay drive
  6628.         ld      (de),a          ; Store into standard FCB
  6629.         inc     de
  6630.         ld      bc,Fname+Fext
  6631.         ldir                    ; move name to standard FCB
  6632.         ld      b,FCBlen-_ex
  6633.         xor     a
  6634. l1c82:
  6635.         ld      (de),a          ; Clear remainder of FCB
  6636.         inc     de
  6637.         djnz    l1c82
  6638.         push    hl              ; Save address of buffer
  6639.         ld      de,l005c
  6640.         ld      c,_open
  6641.         call    BDOS            ; Open file
  6642.         pop     de              ; Get back buffer address
  6643.         inc     a               ; Test success
  6644.         jr      z,l1cd2         ; Nope
  6645.         ld      hl,(l00e6)      ; Get start record
  6646.         ld      (l005c+_rrn),hl ; Set for random record
  6647.         ld      bc,(l00e8)      ; Get record count
  6648. l1c9d:
  6649.         push    bc
  6650.         push    de
  6651.         ld      c,_setdma
  6652.         call    BDOS            ; Set disk buffer
  6653.         ld      de,l005c
  6654.         ld      c,_rndrd
  6655.         call    BDOS            ; Read from file
  6656.         pop     de
  6657.         pop     bc
  6658.         or      a               ; Verify no error
  6659.         jr      nz,l1cd2        ; Error
  6660.         ld      hl,(l005c+_rrn)
  6661.         inc     hl              ; Bump record
  6662.         ld      (l005c+_rrn),hl
  6663.         ld      hl,RecLng
  6664.         add     hl,de           ; Get next address
  6665.         ex      de,hl
  6666.         dec     bc
  6667.         ld      a,b             ; Test done
  6668.         or      c
  6669.         jr      nz,l1c9d        ; Nope
  6670.         ld      de,l005c
  6671.         ld      c,_close
  6672.         call    BDOS            ; Close file
  6673. l1cca:
  6674.         ld      hl,(l00e2)      ; Get caller
  6675.         ld      de,2+Fname+Fext
  6676.         add     hl,de           ; Skip header
  6677.         jp      (hl)            ; Enter overlay
  6678. l1cd2:
  6679.         ld      ix,(l00e2)      ; Get caller's PC
  6680.         ld      a,_OVLerr
  6681.         jp      l2029           ; Abort
  6682. ;
  6683. ; Procedure OVRDRIVE(drive)
  6684. ; ENTRY Reg HL holds drive (1=A, 2=B, etc)
  6685. ;
  6686. l1cdb:
  6687.         call    l04c8           ; Get byte from integer
  6688.         cp      'P'-'@'+1       ; Test max
  6689.         ret     nc              ; Exit on range error
  6690.         ld      (l00dc),a       ; Set overlay drive
  6691.         ret
  6692. ;
  6693. ; Procedure NEW(pointer)
  6694. ; Procedure GETMEM(pointer,space)
  6695. ; ENTRY Reg HL holds space required
  6696. ;       Variable pointer on stack
  6697. ;
  6698. l1ce5:
  6699.         ld      (l00f0),hl      ; Save space required
  6700.         ex      de,hl
  6701.         pop     hl
  6702.         ex      (sp),hl
  6703.         ld      (l00f2),hl      ; Save address of variable
  6704.         inc     de
  6705.         inc     de
  6706.         inc     de
  6707.         ld      a,e
  6708.         and     -HeapLen        ; Get modulo 4
  6709.         ld      e,a
  6710.         ld      hl,l00de
  6711.         ld      (l00f8),hl      ; Init pointer
  6712.         ld      ix,(l00de)      ; Get pointer to 1st free address
  6713. l1cff:
  6714.         ld      l,(ix+HeapLOlen)
  6715.         ld      h,(ix+HeapHIlen)
  6716.         ld      a,l             ; Test assignment
  6717.         or      h
  6718.         jr      z,l1d51         ; Maybe free
  6719.         sbc     hl,de           ; Test gap
  6720.         jr      nc,l1d1c
  6721.         ld      l,(ix+HeapLOadr); Get next address
  6722.         ld      h,(ix+HeapHIadr)
  6723.         push    hl
  6724.         ld      (l00f8),ix      ; Save last address
  6725.         pop     ix              ; Copy chain
  6726.         jr      l1cff
  6727. l1d1c:
  6728.         jr      nz,l1d28        ; Not same gap length
  6729.         ld      e,(ix+HeapLOadr); Get address if so
  6730.         ld      d,(ix+HeapHIadr)
  6731.         push    ix
  6732.         jr      l1d43           ; Save state
  6733. l1d28:
  6734.         ld      c,l             ; Copy length
  6735.         ld      b,h
  6736.         ld      l,(ix+HeapLOadr); Get address
  6737.         ld      h,(ix+HeapHIadr)
  6738. l1d30:
  6739.         push    ix              ; Save pointer
  6740.         add     ix,de           ; Advance
  6741.         ld      (ix+HeapLOadr),l; Set start values
  6742.         ld      (ix+HeapHIadr),h
  6743.         ld      (ix+HeapLOlen),c
  6744.         ld      (ix+HeapHIlen),b
  6745.         push    ix
  6746.         pop     de              ; Copy pointer
  6747. l1d43:
  6748.         ld      hl,(l00f8)      ; Get pointer
  6749.         ld      (hl),e          ; Set new link
  6750.         inc     hl
  6751.         ld      (hl),d
  6752.         pop     de
  6753.         ld      hl,(l00f2)
  6754.         ld      (hl),e          ; Set into vriable
  6755.         inc     hl
  6756.         ld      (hl),d
  6757.         ret
  6758. l1d51:
  6759.         push    ix
  6760.         pop     hl
  6761.         add     hl,de
  6762.         ld      (l00c4),hl      ; Set new heap pointer
  6763.         ld      hl,(l00f0)      ; Get space
  6764.         ld      bc,HeapLen
  6765.         add     hl,bc           ; Get complete length
  6766.         push    ix
  6767.         pop     bc
  6768.         add     hl,bc
  6769.         jp      c,l1d75         ; Error if overlapping
  6770.         ld      bc,(l00c6)      ; Get recursion pointer
  6771.         sbc     hl,bc           ; Test against it
  6772.         ld      bc,0
  6773.         ld      hl,0
  6774.         jp      c,l1d30
  6775. ;
  6776. ; Heap error
  6777. ;
  6778. l1d75:
  6779.         ld      a,_HeapErr
  6780.         jp      l2027           ; Set error
  6781. ;
  6782. ; Procedure DISPOSE(pointer)
  6783. ; Procedure FREEMEM(pointer,space)
  6784. ; ENTRY Reg HL holds space
  6785. ;       Variable pointer on stack
  6786. ;
  6787. l1d7a:
  6788.         ex      de,hl           ; Save space
  6789.         pop     hl
  6790.         ex      (sp),hl         ; Get variable pointer
  6791.         ld      a,(hl)          ; Get dynamic pointer
  6792.         inc     hl
  6793.         ld      h,(hl)
  6794.         ld      l,a
  6795.         inc     de              ; Fix space
  6796.         inc     de
  6797.         inc     de
  6798.         ld      a,e
  6799.         and     -HeapLen        ; Get modulo 4
  6800.         ld      e,a
  6801.         ex      de,hl
  6802.         ld      (l00f0),hl      ; Save length
  6803.         ld      hl,(l00de)      ; Load pointer to free heap
  6804.         push    hl
  6805.         pop     ix
  6806.         or      a
  6807.         sbc     hl,de           ; Check pointer addresses
  6808.         jr      nc,l1de9
  6809. l1d97:
  6810.         ld      l,(ix+HeapLOadr); Get address
  6811.         ld      h,(ix+HeapHIadr)
  6812.         push    hl
  6813.         or      a
  6814.         sbc     hl,de           ; Compare
  6815.         jr      nc,l1da7
  6816.         pop     ix
  6817.         jr      l1d97
  6818. l1da7:
  6819.         pop     hl
  6820.         push    de
  6821.         pop     iy
  6822.         ld      bc,(l00f0)      ; Get length
  6823.         ld      (iy+HeapLOlen),c; Store it
  6824.         ld      (iy+HeapHIlen),b
  6825.         ld      (iy+HeapLOadr),l; Store address, too
  6826.         ld      (iy+HeapHIadr),h
  6827.         ld      (ix+HeapLOadr),e
  6828.         ld      (ix+HeapHIadr),d
  6829.         push    ix
  6830.         pop     hl
  6831.         ld      c,(ix+HeapLOlen); Get old length
  6832.         ld      b,(ix+HeapHIlen)
  6833.         call    l1e04           ; Compare
  6834.         jr      z,l1dd8         ; Match
  6835.         ld      e,(ix+HeapLOadr); Get address
  6836.         ld      d,(ix+HeapHIadr)
  6837.         push    de
  6838.         pop     ix
  6839. l1dd8:
  6840.         push    ix
  6841.         pop     hl
  6842.         ld      c,(ix+HeapLOlen)
  6843.         ld      b,(ix+HeapHIlen)
  6844.         ld      e,(ix+HeapLOadr)
  6845.         ld      d,(ix+HeapHIadr)
  6846.         jr      l1e04
  6847. l1de9:
  6848.         ld      hl,(l00de)      ; Get pointer to free heap
  6849.         ld      (l00de),de      ; Set new address
  6850.         push    de
  6851.         pop     ix
  6852.         ld      (ix+HeapLOadr),l; Set chain
  6853.         ld      (ix+HeapHIadr),h
  6854.         ld      bc,(l00f0)      ; Get length
  6855.         ld      (ix+HeapLOlen),c
  6856.         ld      (ix+HeapHIlen),b
  6857.         ex      de,hl
  6858. l1e04:
  6859.         add     hl,bc           ; Bump next
  6860.         or      a
  6861.         sbc     hl,de           ; Test same
  6862.         ret     nz
  6863.         push    de
  6864.         pop     iy              ; Copy pointer
  6865.         ld      hl,(l00c4)      ; Get heap pointer
  6866.         or      a
  6867.         sbc     hl,de           ; Test top found
  6868.         jr      z,l1e2f
  6869.         ld      a,(iy+HeapLOadr); Unpack address
  6870.         ld      (ix+HeapLOadr),a
  6871.         ld      a,(iy+HeapHIadr)
  6872.         ld      (ix+HeapHIadr),a
  6873.         ld      l,(iy+HeapLOlen)
  6874.         ld      h,(iy+HeapHIlen)
  6875.         add     hl,bc
  6876.         ld      (ix+HeapLOlen),l; Unpack new length
  6877.         ld      (ix+HeapHIlen),h
  6878.         xor     a
  6879.         ret
  6880. l1e2f:
  6881.         push    ix
  6882.         pop     hl
  6883.         ld      (l00c4),hl      ; Set new top heap pointer
  6884.         ld      b,HeapLen
  6885. l1e37:
  6886.         ld      (hl),0          ; Clear top
  6887.         inc     hl
  6888.         djnz    l1e37
  6889.         ret
  6890. ;
  6891. ; Get free memory
  6892. ; Function MEMAVAIL:integer
  6893. ; EXIT  Reg HL holds free memory in bytes
  6894. ;
  6895. l1e3d:
  6896.         call    l1e4b           ; Get memory
  6897.         ld      hl,(l00f4)      ; Get available memory
  6898.         ret
  6899. ;
  6900. ; Get max free memory
  6901. ; Function MAXAVAIL:integer
  6902. ; EXIT  Reg HL holds free memory in bytes
  6903. ;
  6904. l1e44:
  6905.         call    l1e4b           ; Get memory
  6906.         ld      hl,(l00f6)      ; Get max memory
  6907.         ret
  6908. ;
  6909. ; Get free memory
  6910. ;
  6911. l1e4b:
  6912.         ld      hl,0
  6913.         ld      (l00f4),hl      ; Init available memory
  6914.         ld      (l00f6),hl
  6915.         ld      ix,(l00de)      ; Get pointer to free heap
  6916. l1e58:
  6917.         ld      c,(ix+HeapLOlen)
  6918.         ld      b,(ix+HeapHIlen)
  6919.         ld      a,c
  6920.         or      b               ; Test end of chain
  6921.         jr      z,l1e80
  6922.         ld      hl,(l00f4)      ; Get old available memory
  6923.         add     hl,bc           ; Add length
  6924.         ld      (l00f4),hl
  6925.         ld      hl,(l00f6)      ; Get max
  6926.         or      a
  6927.         sbc     hl,bc           ; Check it
  6928.         jr      nc,l1e75
  6929.         ld      (l00f6),bc      ; Set new max
  6930. l1e75:
  6931.         ld      l,(ix+HeapLOadr); Get chain
  6932.         ld      h,(ix+HeapHIadr)
  6933.         push    hl
  6934.         pop     ix
  6935.         jr      l1e58           ; Loop
  6936. l1e80:
  6937.         ld      hl,(l00c6)      ; Get recursion pointer
  6938.         ld      bc,-5
  6939.         add     hl,bc           ; Build free address
  6940.         ld      de,(l00c4)      ; Get heap pointer
  6941.         or      a
  6942.         sbc     hl,de           ; Test any free
  6943.         ret     c
  6944.         ex      de,hl
  6945.         ld      hl,(l00f4)      ; Get available memory
  6946.         add     hl,de           ; Add gap
  6947.         ld      (l00f4),hl
  6948.         ld      hl,(l00f6)      ; Get max
  6949.         or      a
  6950.         sbc     hl,de           ; Subtract
  6951.         ret     nc
  6952.         ld      (l00f6),de      ; Set new
  6953.         ret
  6954. ;
  6955. ; Mark heap
  6956. ; Procedure MARK(pointer)
  6957. ; ENTRY Reg HL holds pointer
  6958. ;
  6959. l1ea3:
  6960.         ld      de,(l00c4)      ; Get heap pointer
  6961.         ld      (hl),e          ; Store into variable
  6962.         inc     hl
  6963.         ld      (hl),d
  6964.         ret
  6965. ;
  6966. ; Release heap
  6967. ; Procedure RELEASE(pointer)
  6968. ; ENTRY Reg HL holds pointer
  6969. ;
  6970. l1eab:
  6971.         ld      e,(hl)          ; Load heap from variable
  6972.         inc     hl
  6973.         ld      d,(hl)
  6974.         ex      de,hl
  6975. ;
  6976. ; Init heap
  6977. ; ENTRY Reg HL points to 1st free location
  6978. ;
  6979. l1eaf:
  6980.         ld      (l00c4),hl      ; Set heap pointer
  6981.         ld      (l00de),hl
  6982.         ld      b,HeapLen
  6983. l1eb7:
  6984.         ld      (hl),0          ; Clear 4 bytes
  6985.         inc     hl
  6986.         djnz    l1eb7
  6987.         ret
  6988. ;
  6989. ; Convert number to string
  6990. ; Procedure STR(real,string)
  6991. ; ENTRY Real pushed onto stack with formatting data
  6992. ;       Reg HL points to string
  6993. ;       Reg B holds length of string
  6994. ;
  6995. l1ebd:
  6996.         db      skip
  6997. ;
  6998. ; Procedure STR(integer,string)
  6999. ; ENTRY Integer pushed onto stack with digit count
  7000. ;       Reg HL points to string
  7001. ;       Reg B holds length of string
  7002. ;
  7003. l1ebe:
  7004.         xor     a
  7005.         ld      c,a             ; Save mode
  7006.         ld      (l00e8),hl      ; Save string
  7007.         xor     a
  7008.         ld      (hl),a          ; Init to empty string
  7009.         ld      (l00d0),a       ; Clear error
  7010.         ld      a,b
  7011.         ld      (l00ea),a       ; Save max length
  7012.         ld      hl,(l00e2)
  7013.         ld      (l00ed),hl      ; Save current FIB
  7014.         ld      hl,l1f46
  7015.         ld      (l00e2),hl      ; Set RAM device
  7016.         pop     hl              ; Get caller
  7017.         ld      (l00e4),hl
  7018.         pop     hl              ; Get digit count/comma places
  7019.         inc     c               ; Test mode
  7020.         dec     c
  7021.         jr      nz,l1ee6
  7022.         call    l1726           ; Get integer string
  7023.         jr      l1ee9
  7024. l1ee6:
  7025.         call    l1779           ; Get real string
  7026. l1ee9:
  7027.         ld      hl,(l00ed)
  7028.         ld      (l00e2),hl      ; Restore FIB
  7029.         ld      hl,(l00e4)      ; Get caller
  7030.         jp      (hl)
  7031. ;
  7032. ; Convert string to number
  7033. ; Procedure VAL(string,real,result)
  7034. ; ENTRY String and address of real pushed onto stack
  7035. ;       Reg HL points to result
  7036. ;
  7037. l1ef3:
  7038.         db      skip
  7039. ;
  7040. ; Procedure VAL(string,integer,result)
  7041. ; ENTRY String and address of integer pushed onto stack
  7042. ;       Reg HL points to result
  7043. ;
  7044. l1ef4:
  7045.         xor     a
  7046.         ld      (l00ec),a       ; Save mode
  7047.         ld      (l00e8),hl      ; Save result
  7048.         ld      hl,(l00e2)
  7049.         ld      (l00ed),hl      ; Save current FIB
  7050.         ld      hl,l1f46
  7051.         ld      (l00e2),hl      ; Set RAM FIB
  7052.         pop     hl
  7053.         ld      (l00e4),hl      ; Save caller
  7054.         pop     hl
  7055.         ld      (l00ea),hl      ; Save integer/real address
  7056.         ld      hl,l005c
  7057.         ld      b,1eh
  7058.         call    l05e2           ; Assign string from stack
  7059.         xor     a
  7060.         ld      (de),a
  7061.         ld      hl,(l00ea)      ; Get back variable pointer
  7062.         ld      a,(l00ec)       ; Test mode
  7063.         or      a
  7064.         jr      nz,l1f27
  7065.         call    l164e           ; Convert to integer
  7066.         jr      l1f2a
  7067. l1f27:
  7068.         call    l1672           ; Convert to real
  7069. l1f2a:
  7070.         ld      hl,l00d0
  7071.         ld      a,(hl)          ; Get IOResult
  7072.         ld      (hl),0          ; Clear
  7073.         or      a
  7074.         ld      h,a
  7075.         ld      l,a
  7076.         jr      z,l1f3d         ; Test error
  7077.         push    ix
  7078.         pop     hl              ; Get last address
  7079.         ld      de,l005c
  7080.         sbc     hl,de           ; Get relative string error
  7081. l1f3d:
  7082.         ex      de,hl
  7083.         ld      hl,(l00e8)      ; Point to result
  7084.         ld      (hl),e          ; Save error or success
  7085.         inc     hl
  7086.         ld      (hl),d
  7087.         jr      l1ee9           ; Exit
  7088. ;
  7089. ; FIB for RAM storage
  7090. ;
  7091. l1f46:
  7092.         db      _.in+_.out+RAMdevice
  7093.         db      0
  7094. ;
  7095. ; Procedure RANDOMIZE
  7096. ;
  7097. l1f48:
  7098.         ld      a,r             ; Get refresh counter
  7099.         ld      (l00c8+3),a     ; Set for random
  7100.         ret
  7101. ;
  7102. ; Fill variable with constant value
  7103. ; Procedure FILLCHAR(var,num,val)
  7104. ; ENTRY Reg HL holds value
  7105. ;       Count and variable address pushed onto stack
  7106. ;
  7107. l1f4e:
  7108.         ex      de,hl
  7109.         pop     ix
  7110.         pop     bc              ; Get count
  7111.         pop     hl              ; Get address
  7112.         ld      a,b
  7113.         or      c               ; Test count zero
  7114.         jr      z,l1f62         ; Skip if so
  7115.         ld      (hl),e          ; Store value
  7116.         dec     bc              ; Fix count
  7117.         ld      a,b
  7118.         or      c               ; Test count one
  7119.         jr      z,l1f62         ; Skip if so
  7120.         ld      d,h             ; Copy address
  7121.         ld      e,l
  7122.         inc     de
  7123. l1f60:
  7124.         ldir                    ; move value for fill
  7125. l1f62:
  7126.         jp      (ix)
  7127. ;
  7128. ; move variable to another
  7129. ; Procedure MOVE(var1,var2,len)
  7130. ; ENTRY Reg HL holds count
  7131. ;       Variables pushed onto stack
  7132. ;
  7133. l1f64:
  7134.         ld      b,h             ; Copy count
  7135.         ld      c,l
  7136.         pop     ix
  7137.         pop     de              ; Get 2nd var
  7138.         pop     hl              ; Get 1st one
  7139.         ld      a,b
  7140.         or      c
  7141.         jr      z,l1f62         ; Test zero length
  7142.         sbc     hl,de
  7143.         add     hl,de           ; Test overlapping
  7144.         jr      nc,l1f60        ; move up if so
  7145.         dec     bc
  7146.         add     hl,bc           ; Point to top
  7147.         ex      de,hl
  7148.         add     hl,bc
  7149.         ex      de,hl
  7150.         inc     bc
  7151.         lddr                    ; move down
  7152.         jp      (ix)
  7153. ;
  7154. ; Get string from OS command line
  7155. ; Function PARAMSTR(num):any_string
  7156. ; ENTRY Reg HL holds number of substring
  7157. ; EXIT  Selected string on stack
  7158. ;
  7159. l1f7d:
  7160.         ld      d,l             ; Get number
  7161.         inc     d
  7162.         dec     d
  7163.         jr      z,l1f85         ; Skip if none
  7164.         call    l1f9d
  7165. l1f85:
  7166.         pop     ix              ; Free stack
  7167.         ld      c,a             ; Get length of string
  7168.         ld      b,0
  7169.         cpl
  7170.         ld      l,a
  7171.         ld      h,-1
  7172.         add     hl,sp           ; Build address on stack
  7173.         ld      sp,hl
  7174.         ld      (hl),c          ; Store length
  7175.         inc     hl
  7176.         ex      de,hl
  7177.         inc     c               ; Test any selected
  7178.         dec     c
  7179.         jr      z,l1f99         ; Nope
  7180.         ldir                    ; Unpack it
  7181. l1f99:
  7182.         jp      (ix)
  7183. ;
  7184. ; Get number of parameters in OS command line
  7185. ; Function PARAMCOUNT:integer;
  7186. ;
  7187. l1f9b:
  7188.         ld      d,0             ; Set dummy selection
  7189. ;
  7190. ; Get parameters of OS command line
  7191. ; ENTRY Reg D holds number of substring selected
  7192. ; EXIT  Reg DE points to selected substring
  7193. ;       Accu   holds length of substring
  7194. ;       Reg HL holds index of substring
  7195. ;
  7196. l1f9d:
  7197.         ld      hl,l0080        ; Init pointer
  7198.         ;ld     a,MaxParams     ; Test parameter count
  7199.         ;ld     b,(hl)
  7200.         ;cp     b
  7201.         ;jr     nc,l1fa8
  7202.         ld      b,MaxParams     ; Truncate to max
  7203. ;l1fa8:
  7204.         ;inc    hl
  7205.         ld      c,0             ; Init count
  7206. l1fab:
  7207.         inc     b
  7208.         dec     b               ; Test end
  7209.         jr      z,l1fbc         ; Yeap
  7210.         ld      a,(hl)
  7211.         cp      ' '
  7212.         jr      z,l1fb8         ; Skip white spaces
  7213.         cp      tab
  7214.         jr      nz,l1fbc
  7215. l1fb8:
  7216.         inc     hl
  7217.         dec     b
  7218.         jr      l1fab
  7219. l1fbc:
  7220.         ld      e,l             ; Save pointer
  7221. l1fbd:
  7222.         inc     b
  7223.         dec     b               ; Test done
  7224.         jr      z,l1fce         ; Yeap
  7225.         ld      a,(hl)
  7226.         cp      ' '
  7227.         jr      z,l1fce         ; Find white space
  7228.         cp      tab
  7229.         jr      z,l1fce
  7230.         inc     hl
  7231.         dec     b
  7232.         jr      l1fbd
  7233. l1fce:
  7234.         ld      a,l
  7235.         sub     e               ; Test same position
  7236.         jr      z,l1fd6
  7237.         inc     c               ; Count up index
  7238.         dec     d               ; Test found
  7239.         jr      nz,l1fab
  7240. l1fd6:
  7241.         ld      l,c             ; Get selected or last index
  7242.         ld      h,0             ; Make pointer relative
  7243.         ld      d,h
  7244.         ret
  7245. ;
  7246. ; Procedure GOTOXY(x_val,y_val)
  7247. ; ENTRY Reg HL holds y_val
  7248. ;       x_val on stack
  7249. ;
  7250. l1fdb:
  7251.         pop     de
  7252.         pop     bc
  7253.         push    de
  7254.         dec     l               ; Fix row
  7255.         ld      h,c
  7256.         dec     h               ; Fix column
  7257.         jp      l02a2           ; Position cursor
  7258. ;
  7259. ; Function UPCASE(char):char
  7260. ; ENTRY Reg HL holds character
  7261. ; EXIT  Reg HL holds UPPER case character
  7262. ;
  7263. l1fe4:
  7264.         ld      a,l             ; Get into accu
  7265.         call    doupcase                ; Convert to upper case
  7266.         ld      l,a             ; Bring it back
  7267.         ret
  7268. ;
  7269. ; Execute BIOS function
  7270. ; Procedures    BIOS(func)
  7271. ;               BIOS(func,param)
  7272. ; Functions     BIOS(func):integer
  7273. ;               BIOS(func,param):integer
  7274. ;               BIOSHL(func,param):integer
  7275. ; ENTRY Reg DE holds BIOS function
  7276. ;       Reg BC holds optional parameter
  7277. ; EXIT  Accu and reg HL hold result
  7278. ;
  7279. l1fea:
  7280.         ld      hl,(OS+1)       ; Get base address
  7281.         add     hl,de           ; Make executable
  7282.         add     hl,de
  7283.         add     hl,de
  7284.         jp      (hl)            ; Execute
  7285. ;
  7286. ; Get IO result
  7287. ; Function IORESULT:integer
  7288. ; EXIT  Reg HL holds result
  7289. ;
  7290. l1ff1:
  7291.         ld      hl,l00d0        ; Point to result
  7292.         ld      a,(hl)          ; Get it
  7293.         ld      (hl),0          ; Clear after request
  7294.         ld      l,a
  7295.         ld      h,0
  7296.         ret
  7297. ;
  7298. ; Control C entry - entered via RST after each statement
  7299. ;
  7300. l1ffb:
  7301.         call    l0316           ; Test key pressed
  7302.         ld      a,h
  7303.         or      l
  7304.         ret     z               ; Nope
  7305.         ld      a,(l00dd)       ; Get $C mode
  7306.         push    af
  7307.         xor     a
  7308.         ld      (l00dd),a       ; Set $C-
  7309.         call    l0320           ; Read from keyboard
  7310.         pop     af
  7311.         ld      (l00dd),a       ; Reset $C mode
  7312.         ld      a,l
  7313.         cp      CtrlC           ; Test Control-C
  7314.         ret     nz              ; Nope
  7315.         pop     ix              ; Fetch PC
  7316. l2016:
  7317.         ld      de,_CBRK        ; Set CtrlC error
  7318.         jr      l202c           ; Enter error routine
  7319. ;
  7320. ; Check IOResult after IO operation
  7321. ; (May be turned off by {$I-})
  7322. ;
  7323. l201b:
  7324.         ld      a,(l00d0)       ; Test any error
  7325.         or      a
  7326.         ret     z               ; Nope
  7327.         pop     ix              ; Get caller
  7328.         ld      e,a             ; Save code
  7329.         ld      d,_IO           ; Set mode
  7330.         jr      l202c
  7331. l2027:
  7332.         pop     ix              ; Get caller
  7333. l2029:
  7334.         ld      e,a             ; Save code
  7335.         ld      d,_RT           ; Set mode
  7336. ;
  7337. ; Common error handler
  7338. ; ENTRY Reg D holds error mode
  7339. ;       Reg E holds error code
  7340. ;       Reg IX holds callers address
  7341. ;
  7342. l202c:
  7343.          ;jr $
  7344.         push    de
  7345.         call    l037a           ; Reset some things
  7346.         pop     de
  7347.         xor     a
  7348.         ld      (l00dd),a       ; Set $C- mode
  7349.         ld      hl,(l00ce)      ; Get current PC
  7350.         ld      a,h             ; Check zero
  7351.         or      l
  7352.         push    ix
  7353.         pop     hl
  7354.         ld      bc,(l00cc)      ; Get base PC
  7355.         sbc     hl,bc           ; Subtract for base
  7356.         ld      bc,TPhead
  7357.         add     hl,bc           ; Fix for 0100h start
  7358.         ld      (l00ce),hl      ; Set current PC
  7359.         or      a               ; Look for previous zero
  7360.         jr      nz,l2054        ; Nope
  7361.         push    de
  7362.         push    de
  7363.         push    hl
  7364.         call    l00d9           ; Do restart
  7365.         pop     de
  7366. l2054:
  7367.         ld      a,d
  7368.         or      a               ; Test user break
  7369.         jr      nz,l206c
  7370.         call    l0200           ; Tell control C
  7371.         db      '^C'
  7372.         db      cr,lf  
  7373.         db      'User break'
  7374.         db      null
  7375.         jr      l2097
  7376. l206c:
  7377.         dec     a               ; Test I/O error
  7378.         jr      nz,l207a
  7379.         call    l0200           ; Tell I/O error
  7380.         db      cr,lf  
  7381.         db      'I/O'
  7382.         db      null
  7383.         jr      l2088
  7384. l207a:
  7385.         call    l0200           ; Tell run time error
  7386.         db      cr,lf  
  7387.         db      'Run-time'
  7388.         db      null
  7389. l2088:
  7390.         call    l0200
  7391.         db      ' error '
  7392.         db      null
  7393.         ld      a,e
  7394.         call    l04b4           ; Print error byte
  7395. l2097:
  7396.         call    l0200           ; Tell current PC
  7397.         db      ', PC='
  7398.         db      null
  7399.         ld      hl,(l00ce)      ; Get current PC
  7400.         call    l04af           ; Print hex
  7401.         jr      l20bd           ; Abort
  7402. ;
  7403. ; Process memory error
  7404. ;
  7405. l20a8:
  7406.         call    l0200           ; Tell error
  7407.         db      'Not enough memory'
  7408.         db      null
  7409. ;
  7410. ; Error detected, tell abort and break
  7411. ;
  7412. l20bd:
  7413.         call    l0200           ; Tell it
  7414.         db      cr,lf  
  7415.         db      'Program aborted'
  7416.         db      cr,lf,null     
  7417. ;
  7418. ; Halt program
  7419. ;
  7420. l20d4:
  7421.         ld      a,(l00d8)       ; Test run mode
  7422.         or      a
  7423.         jp      z,l278e         ; Enter TP menue
  7424.         if TERM == 0
  7425.         YIELDGETKEYLOOP
  7426.         endif
  7427.         jp      OS              ; Exit .COM file
  7428. ;
  7429. ; Restart after error
  7430. ;
  7431. l20de:
  7432.         pop     hl              ; Get PC
  7433.         pop     de              ; Clean stack
  7434.         pop     de
  7435.         jp      (hl)            ; Restart
  7436. ;
  7437. ;end of runtime library
  7438.  
  7439. ; %%%%%%%%%%%%%%%%%%%
  7440. ; %%% MENUE ENTRY %%%
  7441. ; %%%%%%%%%%%%%%%%%%%
  7442. ;
  7443. ; Enter here thru cold start
  7444. ;
  7445. l20e2:
  7446.         jp      l215e           ; Go to initializer
  7447. ;
  7448. ; Set up environment
  7449. ;
  7450. l20e5:
  7451.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)     ; Get top of memory
  7452.         pop     bc
  7453.         ld      sp,hl
  7454.         push    bc
  7455.         ld      de,-StkSpc
  7456.         add     hl,de           ; Allow some space
  7457.         ld      (l4548),hl      ; Set top of memory
  7458.         ld      hl,l7ad7        ; Get top of used memory
  7459.         ld      bc,256*0+0      ; No break, no interrupt
  7460.         call    l0364           ; Init pointers
  7461.         call    l030a           ; Give lead in sequence
  7462.         call    setlowvideo             ; Set low video
  7463.         jp      setnormvideo            ; Set normal video
  7464. ;
  7465. ; Init session and load work file if defined
  7466. ;
  7467. l2104:
  7468.         call    l20e5           ; Set up environment
  7469.         ld      a,(l4542)       ; Get compile flag
  7470.         push    af
  7471.         ld      a,(l4541)       ; Test error message file read
  7472.         or      a
  7473.         call    nz,l2da4        ; Yeap, read it
  7474.         call    l2d8f           ; Init session
  7475.         call    l2d4b           ; Test work file defined
  7476.         call    nz,l2506        ; Yeap, load file
  7477.         ld      a,(l44f3)       ; Get compiler mode
  7478.         dec     a
  7479.         jr      z,l2125         ; Compile to memory
  7480.         pop     af
  7481.         ld      (l4542),a       ; Reset compile flag
  7482. l2125:
  7483.         jp      l223b           ; Enter menue
  7484. ;
  7485. ; Give delimiter line
  7486. ;
  7487. l2128:
  7488.         call    l0200
  7489.         db      '---------------------------------------'
  7490.         db      cr,lf,null
  7491.         ret
  7492. ;
  7493. ; Give B blanks
  7494. ;
  7495. l2156:
  7496.         call    l0200           ; Just do it
  7497.         db      ' ',null
  7498.         djnz    l2156
  7499.         ret
  7500. ;
  7501. ; Come here after cold start
  7502. ;
  7503. l215e:
  7504.         ;OS_HIDEFROMPARENT
  7505.         ;ld e,6 ;textmode
  7506.         ;OS_SETGFX
  7507.        
  7508.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)     ; Fetch top of memory
  7509.         ld      bc,-MEMGAP
  7510.         add     hl,bc
  7511.         ld      (l44f6),hl      ; Set for available memory
  7512.         ld      c,_retdsk
  7513.         call    BDOS            ; Get logged disk (return L=A=current drive)
  7514.         inc     a
  7515.         ld      (l44f8),a       ; Save it
  7516.         call    l20e5           ; Set up environment
  7517.         call    l023e           ; Clear screen
  7518.         call    l2128           ; Give delimiter
  7519.         call    l0200           ; Tell what we are
  7520. l217d:
  7521.         db      'TURBO'
  7522.         db      ' Pascal system',null
  7523.         call    setlowvideo             ; Set low video
  7524.         ld      b,7
  7525.         call    l2156           ; Give blanks
  7526.         call    l0200           ; Tell version
  7527. ;
  7528.         db      'Version 3.00A'
  7529.         db      cr,lf,null
  7530.         ld      b,27
  7531.         call    l2156           ; Give blanks
  7532.         call    l0200           ; Tell type and copyright
  7533. ;
  7534.         db      'CP/M-80, Z80'
  7535.         db      cr,lf,cr,lf
  7536.         db      'Copyright (C) 1983,84,85   '
  7537.         db      null
  7538.         call    setnormvideo            ; Set normal video
  7539.         call    l0200
  7540. ;
  7541.         db      'BORLAND Inc.'
  7542.         db      cr,lf,null
  7543.         call    l2128           ; Give delimiter
  7544.         call    l0200           ; Tell type of terminal
  7545. ;
  7546.         db      lf
  7547.         db      'Terminal: '
  7548.         db      null
  7549.         ld      hl,l0153
  7550.         call    l01d0           ; Give string
  7551.         call    l0200           ; Ask for error messages to be included
  7552. ;
  7553.         db      cr,lf,lf,lf,lf
  7554.         db      'Include error messages'
  7555.         db      null
  7556.         call    l2d21           ; Ask for YES or NO
  7557.         ld      (l4541),a       ; Save result
  7558.         call    nz,l2da4        ; YES, read it
  7559.         call    l2d8f           ; Init session
  7560.         call    l227a           ; Display menue
  7561. ;
  7562. ; %%%%%%%%%%%%%%%%%%%&&&&&
  7563. ; %%% TURBO WARM START %%%
  7564. ; %%%%%%%%%%%%%%%%%%%&&&&&
  7565. ;
  7566. l223b:
  7567.         nop:ld sp,NEDOOSMEMTOP;ld       sp,(TPAtop)     ; Get top of stack
  7568.         ld      hl,l223b
  7569.         push    hl              ; Set return address
  7570.         call    l01fa           ; Indicate input requested
  7571. ;
  7572.         db      cr+MSB,lf+MSB,'>'+MSB
  7573.         db      null
  7574.         call    readfromkbd             ; Read character
  7575.         call    doupcase                ; Convert to upper case
  7576.         call    l01e1           ; Give new line
  7577.         ld      hl,l2460
  7578.         ld      de,l2472
  7579.         ld      b,MainLen
  7580.         call    l2450           ; Find command
  7581.         jr      c,l227a         ; Display menue if not found
  7582.         jp      (hl)            ; Execute command
  7583. ;
  7584. ; Input option string
  7585. ; On exit ^DE points to first non blank
  7586. ;
  7587. l2261:
  7588.         call    l0200           ; Tell what we want
  7589. ;
  7590.         db      ': '
  7591.         db      null
  7592.         call    l14e8           ; Get line
  7593.         call    l01e1           ; Give new line
  7594.         ld      de,l7ad7        ; Point to start of line
  7595. l2270:
  7596.         ld      a,(de)          ; Get character
  7597.         cp      eof             ; End on end of line
  7598.         ret     z
  7599.         cp      ' '             ; Skip blanks
  7600.         ret     nz
  7601.         inc     de
  7602.         jr      l2270
  7603. ;
  7604. ; Display menue
  7605. ;
  7606. l227a:
  7607.         call    l023e           ; Clear screen
  7608.         call    l01fa           ; Give some info
  7609. ;
  7610.         db      'L'+MSB,'ogged drive:',' '+MSB
  7611.         db      null
  7612.         ld      c,_retdsk
  7613.         call    BDOS            ; Fetch disk (return L=A=current drive)
  7614.         add     a,'A'           ; Make ASCII
  7615.         call    puttoconsole_a          ; Put to console
  7616.         call    l01fa           ; Tell work file
  7617. ;
  7618.         db      cr+MSB,lf+MSB,lf+MSB
  7619.         db      'W'+MSB,'ork file:',' '+MSB
  7620.         db      null
  7621.         call    l3135           ; Type it
  7622.         call    l01fa           ; Tell main file
  7623. ;
  7624.         db      cr+MSB,lf+MSB
  7625.         db      'M'+MSB,'ain file:',' '+MSB
  7626.         db      null
  7627.         ld      de,l44f9
  7628.         call    l2df8           ; Tell name of file
  7629.         call    l01fa           ; Give selection
  7630. ;
  7631.         db      cr+MSB,lf+MSB,lf+MSB
  7632.         db      'E'+MSB,'dit     '
  7633.         db      'C'+MSB,'ompile  '
  7634.         db      'R'+MSB,'un   '
  7635.         db      'S'+MSB,'ave'
  7636.         db      cr,lf,lf
  7637.         db      'e','X'+MSB,'ecute  '
  7638.         db      'D'+MSB,'ir      '
  7639.         db      'Q'+MSB,'uit  compiler '
  7640.         db      'O'+MSB,'ptions'
  7641.         db      cr,lf,lf
  7642.         db      'Text: '
  7643.         db      null
  7644.         ld      de,(l4544)      ; Get start of text
  7645.         ld      hl,(l4546)      ; Get end of text
  7646.         dec     hl
  7647.         call    l2338           ; Tell free bytes
  7648.         ld      de,(l4546)      ; Get end of text
  7649.         ld      hl,(l4548)      ; Get top of available memory
  7650. ;
  7651. ; Tell free memory
  7652. ; ENTRY Reg HL holds  end  address
  7653. ;       Reg DE holds start address
  7654. ;
  7655. l232e:
  7656.         call    l0200           ; Tell free memory
  7657. ;
  7658.         db      'Free: '
  7659.         db      null
  7660. ;
  7661. ; Print decimal free bytes and hex addresses
  7662. ; ENTRY Reg HL holds  end  address
  7663. ;       Reg DE holds start address
  7664. ;
  7665. l2338:
  7666.         push    hl
  7667.         push    de
  7668.         or      a
  7669.         sbc     hl,de           ; Calculate difference
  7670.         call    l2e5c           ; Print it
  7671.         call    l0200           ; Tell bytes
  7672. ;
  7673.         db      ' bytes ('
  7674.         db      null
  7675.         pop     hl              ; Get start address
  7676.         call    l04af           ; Print hex
  7677.         ld      a,'-'
  7678.         call    puttoconsole_a          ; Give delimiter
  7679.         pop     hl              ; Get end address
  7680.         call    l04af           ; Print hex
  7681.         ld      a,')'
  7682.         call    puttoconsole_a          ; Give closure
  7683.         jp      l01e1           ; Give new line
  7684. ;
  7685. ; Display arrow if compile selected
  7686. ;
  7687. l2361:
  7688.         dec     a               ; Test compile selected
  7689.         jr      nz,l2374        ; Nope, erase display
  7690.         call    l01fa
  7691. a2361:
  7692.         db      'compile -> '
  7693. la2361  equ     $-a2361
  7694.         db      null
  7695.         ret
  7696. l2374:
  7697.         ld      b,la2361
  7698.         jp      l2156           ; Give blanks
  7699. ;
  7700. ; ##############################
  7701. ; ### MAIN MENUE O - Options ###
  7702. ; ##############################
  7703. ;
  7704. l2379:
  7705.         ld      hl,l2379
  7706.         push    hl              ; Set return address
  7707.         call    l023e           ; Clear screen
  7708.         ld      a,(l44f3)       ; Get compile mode
  7709.         call    l2361           ; Display arrow
  7710.         call    l01fa
  7711.         db      'M'+MSB,'emory'
  7712.         db      cr,lf,null
  7713.         call    l2361           ; Display arrow
  7714.         call    l01fa
  7715.         db      'C'+MSB,'om-file'
  7716.         db      cr,lf,null
  7717.         call    l2361           ; Display arrow
  7718.         call    l01fa
  7719.         db      'c','H'+MSB,'n-file'
  7720.         db      cr,lf,lf,null
  7721.         ld      a,(l44f3)       ; Get compile mode
  7722.         cp      1               ; Test compile to memory
  7723.         jr      z,l2419         ; Yeap
  7724.         call    l01fa
  7725.         db      'S'+MSB,'tart address:',' '+MSB
  7726.         db      null
  7727.         ld      hl,(l44f4)      ; Get start address
  7728.         call    l04af           ; Print hex
  7729.         call    l01fa
  7730.         db      ' (min '
  7731.         db      null
  7732.         ld      hl,l20e2        ; Get start address
  7733.         call    l04af           ; Print hex
  7734.         call    l01fa
  7735.         db      ')'
  7736.         db      cr,lf
  7737.         db      'E'+MSB,'nd   address:',' '+MSB
  7738.         db      null
  7739.         ld      hl,(l44f6)      ; Get top of available memory
  7740.         call    l04af           ; Print hex
  7741.         call    l01fa
  7742.         db      ' (max '
  7743.         db      null
  7744.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  7745.         call    l04af           ; Print hex
  7746.         call    l01fa
  7747.         db      ')'
  7748.         db      cr,lf,lf,null
  7749. l2419:
  7750.         call    l01fa
  7751.         db      'F'+MSB,'ind run-time error  '
  7752.         db      'Q'+MSB,'uit'
  7753.         db      cr,lf,lf
  7754.         db      '>'+MSB
  7755.         db      null
  7756.         call    readfromkbd             ; Read character
  7757.         call    doupcase                ; Convert to upper case
  7758.         call    l01e1           ; Give new line
  7759.         ld      hl,l246b
  7760.         ld      de,l2488
  7761.         ld      b,SubLen
  7762.         call    l2450           ; Find command
  7763.         ret     c               ; Not found
  7764.         jp      (hl)            ; Execute
  7765. ;
  7766. ; Find character in list ^HL of length in reg B
  7767. ; Return address from table ^DE on success
  7768. ; Set C if not found
  7769. ;
  7770. l2450:
  7771.         cp      (hl)            ; Compare
  7772.         jr      z,l245a         ; Match
  7773.         inc     hl              ; Skip character
  7774.         inc     de              ; Skip address
  7775.         inc     de
  7776.         djnz    l2450           ; Go thru table
  7777.         scf                     ; Indicate no match
  7778.         ret
  7779. l245a:
  7780.         ex      de,hl
  7781.         ld      e,(hl)          ; Fetch address
  7782.         inc     hl
  7783.         ld      d,(hl)
  7784.         ex      de,hl
  7785.         ret
  7786. ;
  7787. l2460:
  7788.         db      'LWMECRSXDQO'
  7789. MainLen equ     $-l2460
  7790. l246b:
  7791.         db      'MCHSEFQ'
  7792. SubLen  equ     $-l246b
  7793. l2472:
  7794.         dw      l2cce           ; L - Log drive
  7795.         dw      l24c9           ; W - Work file
  7796.         dw      l249a           ; M - Main file
  7797.         dw      l2af8           ; E - Edit
  7798.         dw      l2827           ; C - Compile
  7799.         dw      l2a97           ; R - Run
  7800.         dw      l2639           ; S - Save
  7801.         dw      l2b2d           ; X - eXecute
  7802.         dw      l2b93           ; D - Directory
  7803.         dw      l2b24           ; Q - Quit
  7804.         dw      l2379           ; O - Options
  7805. l2488:
  7806.         dw      l2740           ; M - Compile Memory
  7807.         dw      l2744           ; C - Compile Com-file
  7808.         dw      l2748           ; H - Compile cHn-file
  7809.         dw      l2750           ; S - Start address
  7810.         dw      l276e           ; E - End address
  7811.         dw      l279b           ; F - Find run-time error
  7812.         dw      l2496           ; Q - Quit
  7813. ;
  7814. ; ##########################
  7815. ; ### SUB MENUE Q - Quit ###
  7816. ; ##########################
  7817. ;
  7818. l2496:
  7819.         pop     hl
  7820.         jp      l227a           ; Display menue
  7821. ;
  7822. ; ################################
  7823. ; ### MAIN MENUE M - Main file ###
  7824. ; ################################
  7825. ;
  7826. l249a:
  7827.         call    l0200
  7828.         db      cr,lf
  7829.         db      'Main file name'
  7830.         db      null
  7831.         call    l2d9f           ; Init a bit
  7832.         call    l2261           ; Input string
  7833.         ld      a,0
  7834.         ld      (l44f9+Fdrv),a  ; Set default drive
  7835.         ret     z
  7836.         call    l2d2a           ; Prepare .PAS file
  7837.         ld      de,l44f9        ; Point to main file
  7838.         ld      hl,l005c
  7839.         ld      bc,FCBlen
  7840.         ldir                    ; Unpack FCB
  7841.         ret
  7842. ;
  7843. ; ################################
  7844. ; ### MAIN MENUE W - Work file ###
  7845. ; ################################
  7846. ;
  7847. l24c9:
  7848.         ld      hl,l25bc
  7849.         ld      (l259d+1),hl    ; Redirect error
  7850.         call    l2601           ; Save work file
  7851.         call    l0200
  7852.         db      cr,lf
  7853.         db      'Work file name'
  7854.         db      null
  7855.         call    l2261           ; Input string
  7856.         ld      a,0
  7857.         ld      (l451d+Fdrv),a  ; Set no work file
  7858.         jr      nz,l24f6        ; Got input
  7859.         call    l2d8f           ; Init session
  7860.         jp      l223b           ; Enter menue
  7861. l24f6:
  7862.         call    l2d2a           ; Prepare .PAS file
  7863.         ld      de,l451d
  7864.         ld      hl,l005c
  7865.         ld      bc,FCBlen
  7866.         ldir                    ; Unpack work file
  7867.         jr      l250c           ; Init and load text file
  7868. ;
  7869. ; Init a bit and load wirk file into memory
  7870. ;
  7871. l2506:
  7872.         ld      hl,l25b7
  7873.         ld      (l259d+1),hl    ; Redirect error
  7874. l250c:
  7875.         ld      hl,l25eb
  7876.         ld      (l257c+1),hl    ; Set vector for file too big
  7877.         call    l2d8f           ; Init session
  7878.         ld      de,l451d
  7879. ;
  7880. ; Load text file
  7881. ; ENTRY Reg DE points to FCB
  7882. ; EXIT  Reg HL points to  end  of memory
  7883. ;
  7884. l2518:
  7885.         ld      hl,(l4544)      ; Get start of text
  7886.         ld      (l4460),hl      ; Set block start pointer
  7887.         ld      (l4462),hl      ; Set block end pointer
  7888.         ld      (l4450),hl      ; Set current memory pointer
  7889.         ld      (l4454),hl      ; Set block pointer
  7890.         ld      (l4458),hl      ; Set edit pointer
  7891.         ld      (curstartofpage),hl     ; Set start of screen
  7892.         ld      bc,(l4548)      ; Get top of available memory
  7893.         call    l253b           ; Load file
  7894.         ld      (hl),cr         ; Close last line
  7895.         inc     hl
  7896.         ld      (l4546),hl      ; Set end of text
  7897.          push hl
  7898.          ld c,_close
  7899.          call BDOS_with_FCB1 ;WHY DOESN'T HELP???
  7900.          pop hl
  7901.         ret
  7902. ;
  7903. ; Load a file
  7904. ; ENTRY Reg BC holds last available address
  7905. ;       Reg DE holds FCB
  7906. ;       Reg HL holds start address
  7907. ; EXIT  Reg HL holds end address
  7908. ;
  7909.  
  7910. l253b: ;once
  7911.         push    hl
  7912.         push    bc
  7913.         push    de
  7914.         call    l0200           ; Tell action
  7915.         db      cr,lf
  7916.         db      'Loading '
  7917.         db      null
  7918.         call    l2df8           ; Tell name of file
  7919.         ld      de,l005c
  7920.         call    l26dc           ; Clear FCB
  7921.         pop     hl
  7922.         ld      bc,l0024
  7923.         ldir
  7924.         ld      c,_open
  7925.         call    BDOS_with_FCB1          ; Open file
  7926. l2560:
  7927.         ;push   af
  7928.         ;ld     de,TmpBuff
  7929.         ;ld     c,_setdma
  7930.         ;call   _BDOS           ; Set disk buffer
  7931.         ;pop    af
  7932.         pop     bc
  7933.         pop     hl
  7934.         inc     a               ; Test file found
  7935.         jr      z,l259d         ; Nope
  7936.         ld      (l7b6d),bc      ; Set last memory address
  7937. l2573:
  7938.         ld      bc,(l7b6d)      ; Get last memory address
  7939.         dec     b
  7940.         or      a
  7941.         sbc     hl,bc           ; Test room in memory
  7942.         add     hl,bc
  7943. l257c:
  7944.         jp      nc,a_DUMMY      ; Nope
  7945.         push    hl
  7946.          ld     de,TmpBuff
  7947.          ld     c,_setdma
  7948.          call   _BDOS           ; Set disk buffer
  7949.         ld      c,_rdseq
  7950.         call    BDOS_with_FCB1          ; Read record from file
  7951.         pop     hl
  7952.         ;or     a               ; Test end of file
  7953.         ;ret    nz              ; Yeap
  7954.          cp 128
  7955.          ret z ;EOF in NedoOS
  7956.         if 1==1
  7957. ;CP/M has eofs in the end of last sector?
  7958. ;do this by hand:
  7959.         or a
  7960.         jr z,load_noaddeofs ;full sector
  7961. ;a=128+bytes loaded
  7962.         neg
  7963. ;a=128-bytes loaded
  7964.         ld b,a
  7965.         ld de,TmpBuff+127       ; Point to buffer end
  7966.         ld a,eof;-1
  7967.         ld (de),a
  7968.         dec de
  7969.         djnz $-2
  7970. load_noaddeofs
  7971.         endif
  7972.         ld      de,TmpBuff      ; Point to buffer
  7973.         ld      b,RecLng
  7974. l258d:
  7975.          ;ld (hl),eof ;why there was not?
  7976.          ;inc hl
  7977.         ld      a,(de)          ; Scan for EOF
  7978.         cp      -1
  7979.          ;jr z,$
  7980.         ret     z
  7981.         and     NOMSB ;why???
  7982.         cp      eof
  7983.          ;jr z,$
  7984.         ret     z
  7985.          ;dec hl
  7986.         ld      (hl),a          ; Unpack data
  7987.         inc     hl
  7988.         inc     de
  7989.         djnz    l258d
  7990.         jr      l2573
  7991. l259d:
  7992.         jp      a_DUMMY         ; *** REDIRECTED ***
  7993. ;
  7994. ; Tell file not found
  7995. ;
  7996. l25a0:
  7997.         call    l0200
  7998.         db      cr,lf
  7999.         db      'File not found'
  8000.         db      null
  8001. l25b4:
  8002.         jp      l2e76           ; Get ESCape
  8003. ;
  8004. ; Redirected error if work file read error
  8005. ;
  8006. l25b7:
  8007.         call    l25a0           ; Tell file not found
  8008.         jr      l25ee
  8009. ;
  8010. ; Redirected error if work file not found
  8011. ;
  8012. l25bc:
  8013.         call    l0200
  8014.         db      cr,lf
  8015.         db      'New File'
  8016.         db      null
  8017.         inc     hl
  8018.         push    hl
  8019.         ld      hl,1000
  8020.         call    l021d           ; Delay one second
  8021.         pop     hl
  8022.         ret
  8023. ;
  8024. ; Tell file too big
  8025. ;
  8026. l25d4:
  8027.         ld      hl,(l4546)      ; Get end of text
  8028.         call    l0200
  8029.         db      cr,lf
  8030.         db      'File too big'
  8031.         db      null
  8032.         jr      l25b4
  8033. ;
  8034. ; Process file too big error
  8035. ;
  8036. l25eb:
  8037.         call    l25d4           ; Tell file too big
  8038. l25ee:
  8039.         xor     a
  8040.         ld      (l451d+Fdrv),a  ; Indicate no file
  8041.         jp      l223b           ; Enter menue
  8042. ;
  8043. ; Set extension .BAK
  8044. ;
  8045. l25f5:
  8046.         ld      hl,l005c+Fdrv+Fname
  8047.         ld      (hl),'B'
  8048.         inc     hl
  8049.         ld      (hl),'A'
  8050.         inc     hl
  8051.         ld      (hl),'K'
  8052.         ret
  8053. ;
  8054. ; Save work file on request
  8055. ;
  8056. l2601:
  8057.         db      skip
  8058. ;
  8059. ; Save work file on request
  8060. ;
  8061. l2602:
  8062.         xor     a
  8063.         ex      af,af'
  8064.         ld      a,(l447f)       ; Test text changed
  8065.         or      a
  8066.         ret     z               ; Nope
  8067.         ex      af,af'
  8068.         or      a               ; Test request
  8069.         jr      z,l2639         ; Save file if not
  8070.         call    l0200
  8071.         db      'Workfile '
  8072.         db      null
  8073.         call    l3135           ; Type name of file
  8074.         call    l0200
  8075.         db      ' not saved. Save'
  8076.         db      null
  8077.         xor     a
  8078.         ld      (l447f),a       ; Set no text changed
  8079.         call    l2d21           ; Ask for YES or NO
  8080.         ret     z               ; NO
  8081. ;
  8082. ; ###########################
  8083. ; ### MAIN MENUE S - Save ###
  8084. ; ###########################
  8085. ;
  8086. l2639:
  8087.         call    l2d50           ; Get file
  8088.         ld      hl,l451d
  8089.         push    hl
  8090.         ld      de,l005c
  8091.         ld      bc,FCBlen
  8092.         ldir                    ; Unpack file
  8093.         call    l0200           ; Tell action
  8094.         db      cr,lf
  8095.         db      'Saving '
  8096.         db      null
  8097.         ld      de,l005c
  8098.         call    l2df8           ; Tell name of file
  8099.         ld      hl,(l4546)      ; Get end of text
  8100.         dec     hl
  8101.         ld      (hl),eof        ; Close text
  8102.         call    l25f5           ; Set extension .BAK
  8103.         call    l26d9           ; Clear FCB
  8104.         ld      c,_delete
  8105.         call    _BDOS           ; Delete file
  8106.         ld      hl,l005c+Fdrv
  8107.         ld      de,l005c+DIRlen
  8108.         xor     a
  8109.         ld      (l447f),a       ; Set no text changed
  8110.         ld      (de),a
  8111.         inc     a
  8112.         ld      (l44f2),a       ; Set rename flag
  8113.         inc     de
  8114.         ld      bc,DIRlen-1
  8115.         ldir                    ; Unpack name
  8116.         pop     hl
  8117.         ld      de,l005c
  8118.         ld      bc,DIRlen
  8119.         ldir                    ; Get new file
  8120.         ld      c,_rename
  8121.         call    BDOS_with_FCB1          ; Rename it
  8122.         ld      hl,(l4544)      ; Get start of text
  8123. l2692:
  8124.         push    hl
  8125.         call    l26d9           ; Clear FCB
  8126.         ld      c,_make
  8127.         call    _BDOS           ; Create new file
  8128.         pop     hl
  8129.         inc     a
  8130.         jr      z,l26ed         ; Error creating file
  8131.         push    hl
  8132.         ld      de,TmpBuff
  8133.         push    de
  8134.         ld      c,_setdma
  8135.         call    _BDOS           ; Set disk buffer
  8136.         pop     de
  8137.         pop     hl
  8138.         ld      b,RecLng        ; Set length of buffer
  8139. l26ad:
  8140.         ld      a,(hl)          ; Get from memory
  8141.         inc     hl
  8142. l26af:
  8143.         ld      (de),a          ; Put to buffer
  8144.         inc     de
  8145.         djnz    l26c6
  8146.         ld      b,a             ; Save last character
  8147.         push    bc
  8148.         push    hl
  8149.         ld      c,_wrseq
  8150.         call    BDOS_with_FCB1          ; Write record to file
  8151.         pop     hl
  8152.         pop     bc
  8153.         or      a               ; Test success
  8154.         jr      nz,l26fe        ; Nope, write error
  8155.         ld      de,TmpBuff      ; Reset pointer
  8156.         ld      a,b             ; Get back last character
  8157.         ld      b,RecLng        ; Reset buffer length
  8158. l26c6:
  8159.         cp      eof             ; Test end of file
  8160.         jr      nz,l26ad        ; Nope, go on
  8161.         ld      a,b
  8162.         sub     RecLng          ; Test record boundary
  8163.         ld      a,eof
  8164.         jr      nz,l26af        ; Nope, write end
  8165.         ld      c,_close        ; Close file
  8166. ;
  8167. ; Do OS call with standard FCB
  8168. ;
  8169. BDOS_with_FCB1:
  8170.         ld      de,l005c
  8171.         jp      _BDOS           ; Do file call
  8172. ;
  8173. ; Clear FCB
  8174. ;
  8175. l26d9:
  8176.         ld      de,l005c
  8177. ;
  8178. ; Clear FCB ^DE
  8179. ;
  8180. l26dc:
  8181.         push    de
  8182.         ld      hl,_ex
  8183.         add     hl,de           ; Point to extent
  8184.         ld      (hl),0          ; Clear it
  8185.         ld      d,h
  8186.         ld      e,l
  8187.         inc     de
  8188.         ld      bc,FCBlen-_ex-1
  8189.         ldir                    ; Clear remainder
  8190.         pop     de
  8191.         ret
  8192. ;
  8193. ; Create file error
  8194. ;
  8195. l26ed:
  8196.         call    l0200           ; Tell error
  8197.         db      '  Directory'
  8198.         db      null
  8199.         jr      l2708
  8200. ;
  8201. ; Write file error
  8202. ;
  8203. l26fe:
  8204.         call    l0200           ; Tell error
  8205.         db      '  Disk'
  8206.         db      null
  8207. l2708:
  8208.         call    l0200
  8209.         db      ' full'
  8210.         db      null
  8211.         call    l2e76           ; Get ESCape
  8212.         call    l26d9           ; Clear FCB
  8213.         ld      c,_delete
  8214.         call    BDOS_with_FCB1          ; Delete file
  8215.         ld      a,(l44f2)       ; Test to be renamed
  8216.         or      a
  8217.         ret     z               ; Nope
  8218.         ld      (l447f),a       ; Set text changed
  8219.         ld      hl,l005c+Fdrv
  8220.         ld      de,l005c+DIRlen
  8221.         xor     a
  8222.         ld      (l44f2),a       ; Clear rename flag
  8223.         ld      (de),a          ; Clear name entry
  8224.         inc     de
  8225.         ld      bc,DIRlen-1
  8226.         ldir                    ; Unpack FCB
  8227.         call    l25f5           ; Set extension .BAK
  8228.         ld      c,_rename
  8229.         call    BDOS_with_FCB1          ; Rename file
  8230.         jp      l223b           ; Enter menue
  8231. ;
  8232. ; ####################################
  8233. ; ### SUB MENUE M - Compile Memory ###
  8234. ; ####################################
  8235. ;
  8236. l2740:
  8237.         ld      a,1             ; Set memory
  8238.         jr      l274a
  8239. ;
  8240. ; ######################################
  8241. ; ### SUB MENUE C - Compile Com-file ###
  8242. ; ######################################
  8243. ;
  8244. l2744:
  8245.         ld      a,2             ; Set .COM file
  8246.         jr      l274a
  8247. ;
  8248. ; ######################################
  8249. ; ### SUB MENUE H - Compile cHn-file ###
  8250. ; ######################################
  8251. ;
  8252. l2748:
  8253.         ld      a,3             ; Set .CHN file
  8254. l274a:
  8255.         ld      (l44f3),a       ; Set compile mode
  8256.         jp      l2d9f           ; Force compile
  8257. ;
  8258. ; ###################################
  8259. ; ### SUB MENUE S - Start address ###
  8260. ; ###################################
  8261. ;
  8262. l2750:
  8263.         call    l0200           ; Tell what we want
  8264.         db      'Start address'
  8265.         db      null
  8266.         call    l2261           ; Input string
  8267.         ld      hl,l20e2        ; Set default
  8268.         call    nz,l2dd9        ; Get new hex value
  8269.         ld      (l44f4),hl      ; Save new start address
  8270.         ret
  8271. ;
  8272. ; #################################
  8273. ; ### SUB MENUE E - End address ###
  8274. ; #################################
  8275. ;
  8276. l276e:
  8277.         call    l0200           ; Tell what we want
  8278.         db      'End address'
  8279.         db      null
  8280.         call    l2261           ; Input string
  8281.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  8282.         ld      bc,-MEMGAP
  8283.         add     hl,bc           ; Calculate default
  8284.         call    nz,l2dd9        ; Get new hex value
  8285.         ld      (l44f6),hl      ; Set top of available memory
  8286.         ret
  8287. ;
  8288. ; Exit memory resident program
  8289. ;
  8290. l278e:
  8291.         call    l20e5           ; Set up environment
  8292.         ld      hl,(l00ce)      ; Get current PC
  8293.         ld      a,h
  8294.         or      l
  8295.         jr      nz,l27b1        ; Process error
  8296.         jp      l223b           ; Enter menue
  8297. ;
  8298. ; #########################################
  8299. ; ### SUB MENUE F - Find run-time error ###
  8300. ; #########################################
  8301. ;
  8302. l279b:
  8303.         call    l0200           ; Tell what we want
  8304.         db      'Enter PC'
  8305.         db      null
  8306.         call    l2261           ; Input string
  8307.         ret     z               ; Empty
  8308.         call    l2dd9           ; Get hex PC
  8309.         ld      (l00ce),hl      ; Set current PC
  8310. l27b1:
  8311.         call    l01e1           ; Give new line
  8312.         call    l27d7           ; Load file into memory
  8313.         ld      hl,0
  8314.         ld      (l7904),hl      ; Clear address
  8315.         ld      a,2
  8316.         ld      (CmpTyp),a      ; Set searching
  8317.         call    l0200           ; Tell searching
  8318.         db      cr,lf
  8319.         db      'Searching'
  8320.         db      null
  8321.         call    l2d9f           ; Force compile
  8322.         jp      l28d0           ; Go compile
  8323. ;
  8324. ; Load file into memory
  8325. ;
  8326. l27d7:
  8327.         call    l2d4b           ; Test work file defined
  8328.         call    z,l2d50         ; Get file if not
  8329.         call    l2d7a           ; Test main file here
  8330. l27e0:
  8331.         ld      hl,l451d
  8332.         jr      nz,l27ea        ; Got any file
  8333.         call    l2d50           ; Get file
  8334.         jr      l2808
  8335. l27ea:
  8336.         call    l2d7f           ; Test same files
  8337.         jr      z,l27e0         ; Yeap, get another one
  8338.         call    l2602           ; Save work file
  8339.         ld      hl,l25eb
  8340.         ld      (l257c+1),hl    ; Set vector for file too big
  8341.         ld      hl,l25b7
  8342.         ld      (l259d+1),hl    ; Set vector for read error
  8343.         ld      de,l44f9        ; Point to main file
  8344.         push    de
  8345.         call    l2518           ; Load text file ;closes automatically
  8346.         ld      a,1
  8347.         pop     hl
  8348. l2808:
  8349.         ld      (l44f1),a       ; Re/Set file flag
  8350.         ld      de,FFCB
  8351.         ld      bc,FCBlen
  8352.         ldir                    ; Unpack file
  8353.         xor     a
  8354.         ld      (CmpTyp),a      ; Set compile to memory
  8355.         ld hl,NEDOOSMEMTOP;ld   hl,(TPAtop)
  8356.         ld      (l790a),hl      ; Set end of code
  8357. l281d:
  8358.         ld      hl,(l4546)      ; Get end of text
  8359.         ld      (hl),eof        ; Set end of file
  8360.         inc     hl
  8361.         ld      (l7904),hl      ; Set for code start address
  8362.         ret
  8363. ;
  8364. ; ##############################
  8365. ; ### MAIN MENUE C - Compile ###
  8366. ; ##############################
  8367. ;
  8368. l2827:
  8369.         call    l27d7           ; Load file into memory
  8370.         ld      a,(l44f3)       ; Get compile mode
  8371.         dec     a               ; Test compile to memory
  8372.         jp      z,l28aa         ; Yeap
  8373.         dec     a               ; Test compile to .COM file
  8374.         push    af
  8375.         jr      nz,l283c        ; Nope
  8376.         ld      a,'C'           ; Load .COM
  8377.         ld      hl,'O'+'M'*256
  8378.         jr      l2841
  8379. l283c:
  8380.         ld      a,'C'           ; Load .CHN
  8381.         ld      hl,'H'+'N'*256
  8382. l2841:
  8383.         ld      (FFCB+Fdrv+Fname),a
  8384.         ld      (FFCB+Fdrv+Fname+1),hl
  8385.         ld      a,1
  8386.         ld      (CmpTyp),a      ; Set compile to file
  8387.         ld      hl,(l44f4)      ; Get start address of compiler
  8388.         ld      (l7904),hl      ; Save
  8389.         ld      hl,(l44f6)      ; Get top of available memory
  8390.         ld      (l790a),hl      ; Save also
  8391.         ld      de,FFCB
  8392.         push    de
  8393.         call    l26dc           ; Clear FCB
  8394.         ld      c,_delete
  8395.         call    _BDOS           ; Delete file
  8396.         pop     de
  8397.         ld      c,_make
  8398.         call    _BDOS           ; Create new file
  8399.         inc     a               ; Test success
  8400.         jp      z,l2a5a         ; Nope, error
  8401.         pop     af              ; Get back .COM or .CHN
  8402.         ld      hl,0x0100;TPA
  8403.         jr      z,l2877         ; Got .COM
  8404.         ld      hl,(l7904)      ; Get code start address
  8405. l2877:
  8406.         ld      (CodePC),hl     ; Save for current PC
  8407.         ex      de,hl
  8408. l287b:
  8409.         ld      hl,(l7904)      ; Get code start address
  8410.         scf
  8411.         sbc     hl,de           ; Test end reached
  8412.         jr      c,l28a9         ; Yeap
  8413.         ld      hl,(l7904)      ; Get code start address
  8414.         ld      (progstartaddr),hl;(TPA+1),hl   ; Set as start address
  8415.         push    de
  8416.         ld      c,_setdma
  8417.         call    _BDOS           ; Set disk buffer
  8418.         ld      c,_wrseq
  8419.         ld      de,FFCB
  8420.         call    _BDOS           ; Write record to file
  8421.         pop     de
  8422.         ld      hl,l20e2
  8423.         ld      (progstartaddr),hl;(TPA+1),hl   ; Reset start address
  8424.         ;or     a               ; Test I/O success
  8425.         ;jp     nz,l2a5a        ; Error, disk full
  8426.         ld      hl,RecLng
  8427.         add     hl,de           ; Advance buffer
  8428.         ex      de,hl
  8429.         jr      l287b
  8430. l28a9:
  8431.         db      skip
  8432. l28aa:
  8433.         xor     a
  8434.         call    l0200           ; Tell compiling
  8435. ;
  8436.         db      cr,lf
  8437.         db      'Compiling '
  8438.         db      null
  8439.         ld      de,FFCB
  8440.         or      a               ; Test compile to memory
  8441.         jr      z,l28cd         ; Yeap
  8442.         call    l0200           ; Indicate file
  8443. ;
  8444.         db      ' --> '
  8445.         db      null
  8446.         call    l2df8           ; Tell name of file
  8447. l28cd:
  8448.         call    l2d9f           ; Force compile
  8449. l28d0:
  8450.         call    l01e1           ; Give new line
  8451.         call    COMPILE         ; Compile             ;must close output file!!!
  8452.         ld      a,(l7901)       ; Get error code
  8453.         cp      _ABORT          ; Test abort
  8454.         jr      nz,l28fa        ; Nope
  8455.         call    l0200           ; Tell abortion
  8456. ;
  8457.         db      cr,lf,lf
  8458.         db      'Compilation aborted'
  8459.         db      null
  8460.         jp      l223b           ; Enter menue
  8461. l28fa:
  8462.         call    l0200           ; Tell lines
  8463.         db      ' lines'
  8464.         db      cr,lf,lf,null
  8465.         ld      a,(l7901)       ; Get error code
  8466.         or      a               ; Test any error
  8467.         jp      nz,l2970        ; Yeap
  8468.         ld      a,(CmpTyp)      ; Get compile flag
  8469.         cp      2               ; Test searching
  8470.         jr      nz,l292a        ; Nope
  8471.         call    l2a7a           ; Tell error position
  8472.         call    l0200
  8473.         db      'not found'
  8474.         db      cr,lf,null
  8475.         jp      l223b           ; Re-enter menue
  8476. l292a:
  8477.         or      a               ; Test compile to memory
  8478.         jr      z,l293a         ; Yeap
  8479.         ld      hl,(l7904)      ; Get code start address
  8480.         ld      de,l20e2        ; Get start of application
  8481.         or      a
  8482.         sbc     hl,de
  8483.         add     hl,de
  8484.         call    nz,l232e        ; Tell free
  8485. l293a:
  8486.         call    l0200
  8487.         db      'Code: '
  8488.         db      null
  8489.         ld      de,(l7904)      ; Get code start address
  8490.         ld      hl,(l7906)      ; Get code end address
  8491.         push    hl
  8492.         dec     hl
  8493.         call    l2338           ; Tell free bytes
  8494.         pop     de
  8495.         ld      hl,(DataBeg)    ; Get start of data
  8496.         push    hl
  8497.         call    l232e           ; Tell free
  8498.         pop     de
  8499.         inc     de
  8500.         ld      hl,(l790a)      ; Get end of code
  8501.         call    l0200
  8502.         db      'Data: '
  8503.         db      null
  8504.         call    l2338           ; Tell free bytes
  8505.         ld      a,-1
  8506.         ld      (l4542),a       ; Set no compile
  8507.         ret
  8508. ;
  8509. ; Process compiler error
  8510. ;
  8511. l2970:
  8512.         cp      _DskFull        ; Test disk error
  8513.         jp      nc,l2a5a        ; Error, disk full
  8514.         cp      _FndRTerr       ; Test run-time error found
  8515.         jr      nc,l29ec        ; Yeap
  8516.         ld      b,a             ; Save error number
  8517.         call    l0200           ; Tell error
  8518.         db      'Error '
  8519.         db      null
  8520.         ld      h,0
  8521.         ld      l,b             ; Build 16 bit number
  8522.         push    bc
  8523.         call    l2e61           ; Print it
  8524.         pop     bc
  8525.         ld      a,(l4541)       ; Test error message file read
  8526.         or      a
  8527.         jr      z,l29f8         ; No message file
  8528.         ld      hl,(l429e)      ; Get base of message file
  8529. l2995:
  8530.         ld      a,(hl)          ; Get character
  8531.         cp      eof             ; Test end of message
  8532.         jr      z,l29f8         ; Yeap
  8533.         cp      ' '             ; Test control
  8534.         jr      c,l29ad         ; Yeap, skip it
  8535.         sub     '0'             ; Build number - always two digits
  8536.         ld      c,a
  8537.         add     a,a
  8538.         add     a,a
  8539.         add     a,c
  8540.         add     a,a
  8541.         inc     hl
  8542.         add     a,(hl)          ; Combine number
  8543.         sub     '0'             ; Fix it
  8544.         inc     hl
  8545.         cp      b               ; Test message found
  8546.         jr      z,l29b6         ; Got it
  8547. l29ad:
  8548.         ld      a,(hl)
  8549.         inc     hl
  8550.         cp      cr              ; Skip to end of line
  8551.         jr      nz,l29ad
  8552.         inc     hl
  8553.         jr      l2995           ; Try next line
  8554. l29b6:
  8555.         call    l0200           ; Tell result
  8556. ;
  8557.         db      ': '
  8558.         db      null
  8559. l29bc:
  8560.         ld      a,(hl)          ; Get character
  8561.         cp      cr              ; Test end of text
  8562.         jr      z,l29f8         ; That's all
  8563.         cp      ' '             ; Test combined message
  8564.         jr      nc,l29e6        ; Nope
  8565.         ld      de,(l429e)      ; Get base of message file
  8566. l29c9:
  8567.         ld      a,(de)          ; Get character
  8568.         inc     de
  8569.         cp      ' '             ; Test printable
  8570.         jr      nc,l29dd        ; Yeap, skip it
  8571.         cp      (hl)            ; Test extension found
  8572.         jr      nz,l29dd        ; Nope
  8573. l29d2:
  8574.         ld      a,(de)          ; Get from extended part
  8575.         cp      cr              ; Test end of line
  8576.         jr      z,l29e9         ; Yeap
  8577.         call    puttoconsole_a          ; Put substring to console
  8578.         inc     de
  8579.         jr      l29d2
  8580. l29dd:
  8581.         ld      a,(de)
  8582.         inc     de
  8583.         cp      cr              ; Skip this line
  8584.         jr      nz,l29dd
  8585.         inc     de
  8586.         jr      l29c9
  8587. l29e6:
  8588.         call    puttoconsole_a          ; Put to console
  8589. l29e9:
  8590.         inc     hl
  8591.         jr      l29bc           ; Loop on
  8592. ;
  8593. ; Got position of run-time error
  8594. ;
  8595. l29ec:
  8596.         call    l2a7a           ; Tell error position
  8597.         call    l0200
  8598.         db      'found'
  8599.         db      null
  8600. l29f8:
  8601.         xor     a
  8602.         ld      (l44f1),a       ; Clear file flag
  8603.         ld      a,(IncFlg)      ; Test read from memory
  8604.         or      a
  8605.         jr      z,l2a41         ; Nope
  8606.         ld      a,'.'
  8607.         call    puttoconsole_a          ; Put to console
  8608.         call    l2602           ; Save work file
  8609.         ld      de,l451d
  8610.         ld      hl,l790f
  8611.         ld      bc,Fdrv+Fname+Fext
  8612.         ldir                    ; Copy include file
  8613.         call    l2506           ; Load it
  8614.         call    l0200
  8615.         db      cr,lf
  8616.         db      'Error found in above include file'
  8617.         db      null
  8618.         jr      l2a51
  8619. l2a41:
  8620.         call    l2d7a           ; Test main file here
  8621.         jr      z,l2a51         ; Nope
  8622.         ld      de,l451d
  8623.         ld      hl,l44f9        ; Point to main file
  8624.         ld      bc,Fdrv+Fname+Fext
  8625.         ldir                    ; Copy file
  8626. l2a51:
  8627.         call    l2e76           ; Get ESCape
  8628.         ld      hl,(l790c)      ; Fetch current editor address
  8629.         jp      l2afe           ; And fall into edit
  8630. ;
  8631. ; Process disk full
  8632. ;
  8633. l2a5a:
  8634.         call    l0200           ; Tell error
  8635. ;
  8636.         db      'Disk or directory full'
  8637.         db      null
  8638.         call    l2e76           ; Get ESCape
  8639.         jp      l223b           ; Enter menue
  8640. ;
  8641. ; Tell error position message
  8642. ;
  8643. l2a7a:
  8644.         call    l0200
  8645.         db      'Run-time error position '
  8646.         db      null
  8647.         ret
  8648. ;
  8649. ; ##########################
  8650. ; ### MAIN MENUE R - Run ###
  8651. ; ##########################
  8652. ;
  8653. l2a97:
  8654.         ld      a,(l4542)       ; Get compile flag
  8655.         or      a
  8656.         call    z,l2827         ; Compile before run
  8657.         ld      a,(l44f3)       ; Get compile flag
  8658.         dec     a
  8659.         jr      z,l2adf         ; Got to memory
  8660.         dec     a
  8661.         ret     nz              ; Skip chain
  8662.         call    l2b33           ; Load overlay file
  8663.         ret     z               ; Not found
  8664.         call    l2d7a           ; Test main file here
  8665.         ld      hl,l451d
  8666.         jr      z,l2ab5         ; Nope
  8667.         ld      hl,l44f9        ; Point to main file
  8668. l2ab5:
  8669.         ld      de,FFCB
  8670.         ld      bc,Fdrv+Fname+Fext
  8671.         ldir                    ; Unpack FCB
  8672.         ld      a,'C'           ; Set .COM
  8673.         ld      hl,'O'+'M'*256
  8674.         ld      (FFCB+Fdrv+Fname),a
  8675.         ld      (FFCB+Fdrv+Fname+1),hl
  8676.         ld      de,FFCB
  8677.         call    l26dc           ; Clear FCB
  8678.         push    de
  8679.         ld      c,_open
  8680.         call    _BDOS           ; Open file ;WHERE IS CLOSE???
  8681.         pop     hl
  8682.         inc     a               ; Test file here
  8683.         jp      z,l2104         ; Nope, init session
  8684.         ld      de,l42a0        ; Set dummy parameter
  8685.         jp      l2b7a           ; Prepare overlay
  8686. l2adf:
  8687.         ld      (l0080),a       ; Clear parameter
  8688.         call    l281d           ; Set text and code pointer
  8689.         call    l0200           ; Tell running
  8690.         db      cr,lf
  8691.         db      'Running'
  8692.         db      cr,lf,null
  8693.         ld      hl,(l7904)      ; Get code start address
  8694.         jp      (hl)            ; And go
  8695. ;
  8696. ; ###########################
  8697. ; ### MAIN MENUE E - Edit ###
  8698. ; ###########################
  8699. ;
  8700. l2af8:
  8701.         call    l2d50           ; Get file
  8702.         ld      hl,-1           ; Set zero offset
  8703. l2afe:
  8704.         push    hl
  8705.         ld      hl,(l00a6+1)
  8706.         ld      (l421e),hl      ; Change I/O
  8707.         ld      hl,l4214
  8708.         ld      (l00a6+1),hl
  8709.         pop     hl
  8710.         jp      l2e91           ; Go edit
  8711. ;
  8712. ; Control: EXIT EDITOR
  8713. ;
  8714. l2b0f:
  8715.         call    l3e40           ; Sample character
  8716.         ld      hl,(l0169)      ; Get screen lines
  8717.         dec     l               ; Fix row
  8718.         ld      h,0             ; Set column
  8719.         call    l02a2           ; Position cursor
  8720.         ld      hl,(l421e)
  8721.         ld      (l00a6+1),hl    ; Reset I/O
  8722.         jp      l223b
  8723. ;
  8724. ; ###########################
  8725. ; ### MAIN MENUE Q - Quit ###
  8726. ; ###########################
  8727. ;
  8728. l2b24:
  8729.         call    l2601           ; Save work file
  8730.         call    l0310           ; Give lead out sequence
  8731.         jp      OS              ; Exit to OS
  8732. ;
  8733. ; ##############################
  8734. ; ### MAIN MENUE X - eXecute ###
  8735. ; ##############################
  8736. ;
  8737. l2b2d:
  8738.         call    l2b33           ; Load overlay file
  8739.         ret     z               ; Not found
  8740.         jr      l2b5a           ; Go
  8741. ;
  8742. ; Load overlay file
  8743. ; Z set says not found
  8744. ;
  8745. l2b33:
  8746.         call    l2601           ; Save work file
  8747.         ld      de,l217d        ; Set name
  8748.         ld      a,'O'
  8749.         ld      hl,'V'+'R'*256
  8750.         call    l2e20           ; Prepare .OVR file
  8751.         ret     z
  8752.         ld      de,a_OVLADR-RecLng
  8753. l2b45:
  8754.         ld      hl,RecLng
  8755.         add     hl,de           ; Build disk buffer address
  8756.         push    hl
  8757.         ex      de,hl
  8758.         ld      c,_setdma
  8759.         call    BDOS            ; Set disk buffer
  8760.         ld      c,_rdseq
  8761.         call    BDOS_with_FCB1          ; Read record
  8762.         pop     de
  8763.         ;or     a               ; Test end of file
  8764.         ;jr     z,l2b45         ; Nope, loop on
  8765.          cp 128 ;EOF in NedoOS
  8766.          jr nz,l2b45            ; Read was successfull
  8767.         ret
  8768. ;
  8769. ; Execute file
  8770. ;
  8771. l2b5a:
  8772.         call    l0200           ; Tell program
  8773.         db      cr,lf
  8774.         db      'Program'
  8775.         db      null
  8776.         call    l2261           ; Input string
  8777.         jp      z,l2104         ; No input
  8778.         ld      a,'C'
  8779.         ld      hl,'O'+'M'*256
  8780.         call    l2e20           ; Prepare .COM file
  8781.         jr      z,l2b5a         ; Not there, retry
  8782.         ld      hl,l005c
  8783. l2b7a:
  8784.         push    de              ; Set argument pointer
  8785.         push    hl              ; Set FCB
  8786.         ld      a,(l44f8)
  8787.         push    af              ; Set logged disk
  8788.         ld      hl,l03ee
  8789.         push    hl              ; Set parse file routine
  8790.         ld      hl,l00f4
  8791.         push    hl              ; Set available memory
  8792.         ld      hl,l4450
  8793.         push    hl              ; Set current memory pointer
  8794.         ld      hl,l2104
  8795.         push    hl              ; Set return address
  8796.         jp      a_OVLADR                ; Execute overlay
  8797. ;
  8798. ; ################################
  8799. ; ### MAIN MENUE D - Directory ###
  8800. ; ################################
  8801. fcbmask
  8802.         db 0
  8803.         db "???????????"
  8804.         ds FCB_sz-11-1
  8805. fcbmask_filename=fcbmask+FCB_FNAME
  8806. ;
  8807. l2b93:
  8808.         call    l0200
  8809.         db      'Dir mask'
  8810.         db      null
  8811.         call    l2261           ; Input string
  8812.         call    l03ee           ; Parse file
  8813.         ld      c,_retdsk
  8814.         call    _BDOS           ; Return current disk (return L=A=current drive)
  8815.         push    af
  8816.         push    af
  8817.         ld      a,(l005c)       ; Get disk
  8818.         or      a               ; Test default
  8819.         jr      z,l2bbb         ; Yeap
  8820.         pop     hl              ; Clean stack
  8821.         dec     a
  8822.         ld      e,a
  8823.         push    af              ; Set new disk
  8824.         ;ld     c,_seldsk
  8825.         ;call   _BDOS           ; Select disk
  8826. l2bbb:
  8827.         pop     af
  8828.         add     a,'A'           ; Make disk ASCII
  8829.         ld      (l2c8d),a       ; Save disk
  8830.         ;ld     de,TmpBuff
  8831.         ;ld     c,_setdma
  8832.         ;call   _BDOS           ; Set disk buffer
  8833.         ld      de,0            ; Clear flag and count
  8834.         ld      c,_srcfrs
  8835. l2bce:
  8836.         push    de
  8837.          push bc
  8838.          ld     de,TmpBuff
  8839.          ld     c,_setdma
  8840.          call   _BDOS           ; Set disk buffer
  8841.          pop bc
  8842.          ld de,fcbmask
  8843.         call    BDOS_with_FCB1          ; Search for file
  8844.         pop     de
  8845.         ld      c,a
  8846.         inc     a               ; Test valid one
  8847.         jr      z,l2c29         ; Nope
  8848.         ld      a,c
  8849.         add     a,a             ; Result *32
  8850.         add     a,a
  8851.         add     a,a
  8852.         add     a,a
  8853.         add     a,a
  8854.         ld      c,a
  8855.         ld      b,0
  8856.         ld      hl,TmpBuff+_SYS
  8857.         add     hl,bc           ; Point to SYS bit
  8858.         bit     7,(hl)          ; Test set
  8859.         jr      nz,l2c25        ; Yeap, skip display
  8860.         ld      d,-1            ; Set any found flag
  8861.         ld      hl,TmpBuff
  8862.         add     hl,bc           ; Point to entry
  8863.         inc     e               ; Test first file
  8864.         dec     e
  8865.         jr      nz,l2bff        ; Nope
  8866.         ld      a,(l0168)       ; Get screen columns
  8867.         dec     a
  8868.         ld      e,-1
  8869. l2bf8:
  8870.         inc     e
  8871.         sub     Dirlng          ; Calculate files per line
  8872.         jr      nc,l2bf8
  8873.         jr      l2c05
  8874. l2bff:
  8875.         call    l0200
  8876. ;
  8877.         db      ': '
  8878.         db      null
  8879. l2c05:
  8880.         ld      b,Fname+Fext    ; Set length
  8881. l2c07:
  8882.         inc     hl
  8883.         ld      a,(hl)
  8884.         and     NOMSB           ; Strip off offset
  8885.         call    puttoconsole_a          ; Put to console
  8886.         ld      a,b
  8887.         cp      Fext+1          ; Test extension
  8888.         ld      a,' '
  8889.         call    z,puttoconsole_a                ; Put blank to console if so
  8890.         djnz    l2c07
  8891.         dec     e               ; Test remainder in line
  8892.         jr      z,l2c22         ; Nope
  8893.         ld      a,' '
  8894.         call    puttoconsole_a          ; Put to console
  8895.         jr      l2c25
  8896. l2c22:
  8897.         call    l01e1           ; Give new line
  8898. l2c25:
  8899.         ld      c,_srcnxt       ; Search next
  8900.         jr      l2bce
  8901. l2c29:
  8902.         inc     e               ; Test any file left
  8903.         dec     e
  8904.         call    nz,l01e1        ; Give new line if so
  8905.         inc     d               ; Test any file found
  8906.         jr      z,l2c3e         ; Yeap
  8907.         call    l0200           ; Else tell it
  8908. ;
  8909.         db      'No file'
  8910.         db      cr,lf,null
  8911. l2c3e:
  8912.         call    l01e1           ; Give new line
  8913. ;
  8914. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8915. ; !!! FOLLOWING IS ERRONEOUS ON CP/M 3.x !!!
  8916. ; !!! USES BDOS FUNCTION 46 ON CP/M 3.x  !!!
  8917. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8918. ;
  8919.         ld      c,_getdpb
  8920.         call    BDOS            ; Fetch disk parameter block
  8921.         push    hl
  8922.         pop     ix              ; Copy it
  8923.         ld      a,(ix+3)        ; Get block mask
  8924.         inc     a               ; Fix
  8925.         rra                     ; DIV 8 (1-> 1k, 2->2k etc.)
  8926.         rra
  8927.         rra
  8928.         and     DPBMASK         ; Mask it
  8929.         ld      (l7b71),a       ; Save block size
  8930.         ld      l,(ix+5)        ; Fetch block count
  8931.         ld      h,(ix+6)
  8932.         ld      (l7b6f),hl      ; Save it
  8933.         inc     hl              ; Fix
  8934.         call    l2cc6           ; Build size in bytes
  8935.         push    hl              ; Save it
  8936. ;
  8937. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8938. ; !!! THE ALLOCATION VECTOR MAY BE FOUND IN ANOTHER !!!
  8939. ; !!! MEMORY BANK RUNNING CP/M 3.X.                 !!!
  8940. ; !!! THE NEXT CALCULATION MAY BE WRONG THEREFORE   !!!
  8941. ; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8942. ;
  8943.         ld      c,_getalv
  8944.         call    BDOS            ; Get allocation vector
  8945.         ex      de,hl
  8946.         ld      hl,(l7b6f)      ; Get block count
  8947.         ld      bc,0
  8948.         call    l2ca5           ; Get free blocks
  8949.         ld      h,b
  8950.         ld      l,c
  8951.         call    l2cc6           ; Build size in bytes
  8952.         call    l0200           ; Tell size
  8953. ;
  8954.         db      'Bytes Remaining On '
  8955. l2c8d:
  8956.         db      'X: '
  8957.         db      null
  8958.         ex      de,hl
  8959.         pop     hl              ; Get back total size
  8960.         or      a
  8961.         sbc     hl,de           ; Calculate free bytes
  8962.         call    l2e61           ; Print number
  8963.         ld      a,'k'
  8964.         call    puttoconsole_a          ; Put to console
  8965.         pop     af              ; Get back selected disk
  8966.         ld      e,a
  8967.        ret
  8968.         ;ld     c,_seldsk
  8969.         ;jp     _BDOS           ; Select disk
  8970. ;
  8971. ; BC holds resulting block count
  8972. ; DE holds allocation vector
  8973. ; HL holds block count
  8974. ;
  8975. ; BC holds free blocks
  8976. ;
  8977. l2ca5:
  8978.         push    bc
  8979.         ld      bc,-8
  8980.         add     hl,bc           ; Fix block count
  8981.         pop     bc
  8982.         ld      a,h             ; Get hi
  8983.         or      a
  8984.         ld      a,(de)
  8985.         jp      p,l2cb8
  8986. l2cb1:
  8987.         inc     l
  8988.         jr      z,l2cbd         ; Done, calculate free blocks
  8989.         or      a
  8990.         rra
  8991.         jr      l2cb1
  8992. l2cb8:
  8993.         call    l2cbd           ; Calculate free blocks from bits
  8994.         jr      l2ca5
  8995. ;
  8996. ; Calculate free blocks in reg BC from vector in Accu
  8997. ;
  8998. l2cbd:
  8999.         inc     de              ; Advance allocation vector
  9000. l2cbe:
  9001.         or      a               ; Test end of bit stream
  9002.         ret     z               ; Yeap
  9003.         rra                     ; Get resulting bit
  9004.         jr      nc,l2cbe        ; Not set
  9005.         inc     bc              ; Advance block count
  9006.         jr      l2cbe
  9007. ;
  9008. ; Build bytes in blocks
  9009. ;
  9010. l2cc6:
  9011.         ld      a,(l7b71)       ; Get block size
  9012. l2cc9:
  9013.         rra                     ; Get bit
  9014.         ret     c               ; Got it
  9015.         add     hl,hl           ; Double byte count
  9016.         jr      l2cc9
  9017. ;
  9018. ; ################################
  9019. ; ### MAIN MENUE L - Log drive ###
  9020. ; ################################
  9021. ;
  9022. l2cce:
  9023.         call    l0200           ; Tell what we expect
  9024. ;
  9025.         db      'New drive'
  9026.         db      null
  9027.         call    l2261           ; Input string
  9028.         ld      a,(de)
  9029.         cp      eof             ; Test empty input
  9030.         jr      nz,l2ce8        ; Nope
  9031.         ld      a,(DU)          ; Get from caller
  9032.         jr      l2cf1
  9033. l2ce8:
  9034.         call    doupcase                ; Convert to upper case
  9035.         sub     'A'             ; Verify in range
  9036.         ret     c
  9037.         cp      'P'-'A'+1
  9038.         ret     nc
  9039. l2cf1:
  9040.         if 1==1
  9041.         ret
  9042.         else
  9043.         push    af
  9044.         ld      c,_resdsk
  9045.         call    _BDOS           ; Reset disk system
  9046.         pop     af
  9047.         ld      (DU),a          ; Set new disk
  9048.         ld      e,a
  9049.         ld      c,_seldsk
  9050.         jp      _BDOS           ; Select disk
  9051.         endif
  9052. ;
  9053. ; Ask for YES or NO - Z set is NO
  9054. ;
  9055. l2d01:
  9056.         call    l0200           ; Tell what we does expect
  9057. ;
  9058.         db      ' (Y/N)? '
  9059.         db      null
  9060. l2d0d:
  9061.         call    readfromkbd             ; Read character
  9062.         call    doupcase                ; Convert to upper case
  9063.         cp      'Y'             ; Test YES
  9064.         jr      z,l2d1b
  9065.         cp      'N'             ; Test NO
  9066.         jr      nz,l2d0d
  9067. l2d1b:
  9068.         call    puttoconsole_a          ; Put to console
  9069.         sub     'N'
  9070.         ret
  9071. ;
  9072. ; Get response Y or N - Z set is NO
  9073. ;
  9074. l2d21:
  9075.         call    l2d01           ; Ask for YES or NO
  9076.         push    af
  9077.         call    l01e1           ; Give new line
  9078.         pop     af
  9079.         ret
  9080. ;
  9081. ; Build file <name>.PAS
  9082. ;
  9083. l2d2a:
  9084.         ld      a,'P'           ; Set .PAS
  9085.         ld      hl,'A'+'S'*256
  9086. l2d2f:
  9087.         ld      (l005c+Fdrv+Fname),a
  9088.         ld      (l005c+Fdrv+Fname+1),hl
  9089.         ld      c,0             ; Set no wild card
  9090.         call    l0406           ; Parse file
  9091.         ld      a,(l005c)       ; Test drive given
  9092.         or      a
  9093.         ret     nz              ; Yeap
  9094.         push    de
  9095.         ld      c,_retdsk
  9096.         call    _BDOS           ; Return current disk (return L=A=current drive)
  9097.         inc     a
  9098.         ld      (l005c),a       ; Set disk
  9099.         pop     de
  9100.         ret
  9101. ;
  9102. ; Test work file defined - Z set says no
  9103. ;
  9104. l2d4b:
  9105.         ld      a,(l451d+Fdrv)  ; Fetch name
  9106.         or      a
  9107.         ret
  9108. ;
  9109. ; Get file
  9110. ;
  9111. l2d50:
  9112.         call    l2d4b           ; Test work file defined
  9113.         jr      nz,l2d6f        ; Yeap
  9114.         call    l2d7a           ; Test main file defined
  9115.         jr      nz,l2d5f        ; Yeap
  9116.         call    l24c9           ; Get work file
  9117.         jr      l2d6f
  9118. l2d5f:
  9119.         ld      de,l451d
  9120.         ld      hl,l44f9        ; Point to main file
  9121.         ld      bc,l0024
  9122.         ldir
  9123.         ld      a,1
  9124.         ld      (l44f1),a       ; Set file flag
  9125. l2d6f:
  9126.         ld      a,(l44f1)       ; Test file flag
  9127.         or      a
  9128.         ret     z               ; No file
  9129.         call    l2602           ; Save work file
  9130.         jp      l2506
  9131. ;
  9132. ; Test main file defined - Z set says no
  9133. ;
  9134. l2d7a:
  9135.         ld      a,(l44f9+Fdrv)  ; Fetch name
  9136.         or      a
  9137.         ret
  9138. ;
  9139. ; Compare main and work file - Z says same
  9140. ;
  9141. l2d7f:
  9142.         ld      de,l451d        ; Point to work file
  9143.         ld      hl,l44f9        ; Point to main file
  9144.         ld      b,Fdrv+Fname+Fext
  9145. l2d87:
  9146.         ld      a,(de)
  9147.         sub     (hl)            ; Compare
  9148.         ret     nz              ; Not same
  9149.         inc     de
  9150.         inc     hl
  9151.         djnz    l2d87
  9152.         ret
  9153. ;
  9154. ; Init session
  9155. ;
  9156. l2d8f:
  9157.         ld      hl,(l4544)      ; Get start of text
  9158.         ld      (hl),' '        ; Clear it
  9159.         inc     hl
  9160.         ld      (l4546),hl      ; Save pointer
  9161.         xor     a
  9162.         ld      (l447f),a       ; Clear text change flag
  9163.         ld      (l44f1),a       ; Clear file flag
  9164. l2d9f:
  9165.         xor     a
  9166.         ld      (l4542),a       ; Force compile
  9167.         ret
  9168. ;
  9169. ; Read error message file
  9170. ;
  9171. l2da4:
  9172.         ld      hl,(l429e)      ; Get base of message file
  9173.         ld      (l4544),hl      ; Set as start of text
  9174.         ld      de,l217d        ; Point to filename
  9175.         ld      a,'M'
  9176.         ld      hl,'S'+'G'*256
  9177.         call    l2e20           ; Prepare .MSG file
  9178.         ld      (l4541),a       ; Set error message file read
  9179.         call    z,l2e76         ; Get ESCape
  9180.         jr      z,l2dcf
  9181.         ld      hl,l25a0
  9182.         ld      (l259d+1),hl    ; Set vector for file not found
  9183.         ld      hl,l25d4
  9184.         ld      (l257c+1),hl    ; Set vector for file too big
  9185.         ld      de,l005c
  9186.         call    l2518           ; Load text file ;closes automatically
  9187. l2dcf:
  9188.         ld      hl,(l4546)      ; Get end of text
  9189.         ld      (hl),eof
  9190.         inc     hl
  9191.         ld      (l4544),hl      ; Set start of text
  9192.         ret
  9193. ;
  9194. ; Convert string ^DE to hex number in reg HL
  9195. ;
  9196. l2dd9:
  9197.         ld      hl,0            ; Init result
  9198. l2ddc:
  9199.         ld      a,(de)          ; Get character
  9200.         call    doupcase                ; Convert to upper case
  9201.         sub     '0'             ; Strip off offset
  9202.         ret     c               ; Out of range
  9203.         cp      9+1             ; Test decimal
  9204.         jr      c,l2def         ; Yeap
  9205.         sub     'A'-'0'-10      ; Fix for hex
  9206.         cp      10              ; Verify correct range
  9207.         ret     c
  9208.         cp      15+1
  9209.         ret     nc
  9210. l2def:
  9211.         add     hl,hl           ; Old * 16
  9212.         add     hl,hl
  9213.         add     hl,hl
  9214.         add     hl,hl
  9215.         or      l
  9216.         ld      l,a             ; Insert digit
  9217.         inc     de
  9218.         jr      l2ddc
  9219. ;
  9220. ; Tell name of file ^DE
  9221. ;
  9222. l2df8:
  9223.         inc     de
  9224.         ld      a,(de)          ; Get name
  9225.         dec     de
  9226.         or      a               ; Test defined
  9227.         ret     z               ; Nope
  9228.         ld      a,(de)          ; Get drive
  9229.         add     a,'A'-1
  9230.         cp      'A'-1           ; Test default drive
  9231.         call    nz,puttoconsole_a       ; Put to console if not
  9232.         ld      a,':'
  9233.         call    nz,puttoconsole_a       ; Give delimiter
  9234.         ld      b,Fname+Fext    ; Set length
  9235. l2e0c:
  9236.         inc     de
  9237.         ld      a,(de)          ; Get character
  9238.         and     NOMSB           ; Strip off attribute
  9239.         cp      ' '             ; Test blank
  9240.         call    nz,puttoconsole_a       ; Put to console if not
  9241.         ld      a,b
  9242.         cp      Fext+1          ; Test extension follows
  9243.         ld      a,'.'
  9244.         call    z,puttoconsole_a                ; Put delimiter to console if so
  9245.         djnz    l2e0c
  9246.         ret
  9247. ;
  9248. ; Prepare file ^DE with extensin in A,L,H
  9249. ; Z set if file not found
  9250. ;
  9251. l2e20:
  9252.         call    l2d2f           ; Parse file and build extension
  9253.         ld      hl,l005c
  9254.         call    l2e51           ; Open file
  9255.         ret     nz              ; Got it
  9256.         ld      a,(l44f8)       ; Get logged disk
  9257.         cp      (hl)            ; Test same drive
  9258.         ld      (hl),a          ; Set logged one
  9259.         call    nz,l2e51        ; Open file if different drives
  9260.         ret     nz
  9261.         ld      a,'A'-'@'
  9262.         cp      (hl)            ; Test base drive
  9263.         ld      (hl),a          ; Force it
  9264.         call    nz,l2e51        ; Open file if not base
  9265.         ret     nz              ; Got it
  9266.         ld      (hl),0          ; Set default drive
  9267.         ex      de,hl           ; And tell error
  9268. ;
  9269. ; Tell file ^DE not found
  9270. ;
  9271. l2e3e:
  9272.         call    l2df8           ; Tell name of file
  9273.         call    l0200           ; Tell not found
  9274. ;
  9275.         db      ' not found'
  9276.         db      null
  9277.         xor     a
  9278.         ret
  9279. ;
  9280. ; Open standard file - Z set says not found
  9281. ;
  9282. l2e51:
  9283.         push    de
  9284.         push    hl
  9285.         ld      c,_open
  9286.         call    BDOS_with_FCB1          ; Open file
  9287.         pop     hl
  9288.         pop     de
  9289.         inc     a               ; Fix result
  9290.         ret
  9291. ;
  9292. ; Print integer in reg HL fixed sized
  9293. ;
  9294. l2e5c:
  9295.         ld      de,-5           ; Set size
  9296.         jr      l2e64
  9297. ;
  9298. ; Print integer number in reg HL
  9299. ;
  9300. l2e61:
  9301.         ld      de,-1           ; Set no size
  9302. l2e64:
  9303.         push    ix
  9304.         push    iy
  9305.         push    hl
  9306.         push    de
  9307.         call    l149b           ; Set standard device
  9308.         pop     hl
  9309.         call    l1726           ; Write integer
  9310.         pop     iy
  9311.         pop     ix
  9312.         ret
  9313. ;
  9314. ; Get ESCape character
  9315. ;
  9316. l2e76:
  9317.         push    af
  9318.         call    l0200           ; Tell it
  9319. ;
  9320.         db      '. Press <ESC>'
  9321.         db      null
  9322. l2e88:
  9323.         call    readfromkbd             ; Read character
  9324.         jp      l0128           ; &PATCH&: Test special keys
  9325.         nop
  9326. l2e8f:
  9327.         pop     af
  9328.         ret
  9329. ;
  9330. ; %%%%%%%%%%%%%%%%%%%%
  9331. ; %%% EDITOR PART %%%%
  9332. ; %%%%%%%%%%%%%%%%%%%%
  9333. ;
  9334. l2e91:
  9335.         push    hl
  9336.         ld      de,256*lf+cr
  9337.         ld      hl,(l4546)      ; Get end of text
  9338.         ld      (hl),d          ; Close line
  9339.         dec     hl
  9340.         ld      (hl),e
  9341.         ld      (l7b74+_LinLen),de
  9342.         xor     a
  9343.         ld      (l4474),a       ; Clear change flag
  9344.         inc     a
  9345.         ld      (l4475),a       ; Init row
  9346.         ld      hl,l43de
  9347.         ld      (l7b72),hl      ; Init pointer to all delimiters
  9348.         ld      iy,l446c
  9349.         call    l023e           ; Clear screen
  9350.         pop     de              ; Get offset
  9351.         inc     de              ; Fix it
  9352.         ld      hl,(l4544)      ; Get start of text
  9353.         add     hl,de           ; Add to offset
  9354.         call    l33a9 ;status line?
  9355. l2ebd:
  9356.         ld      a,(l4482)       ; Get control character count
  9357.         dec     a
  9358.         jr      z,l2ed5         ; Got one
  9359.         ld      hl,256*0+0
  9360.         call    l02a2           ; Set cursor to control position
  9361.         ld      a,(l4482)       ; Get control character count
  9362.         add     a,a             ; Double it
  9363.         ld      b,a             ; For count
  9364.         ld      a,' ' ;TODO speedup spaces
  9365. l2ed0:
  9366.         call    puttoconsole_a          ; Blank control characters
  9367.         djnz    l2ed0
  9368. l2ed5:
  9369.         call    l3b96 ;set edit cursor?
  9370.         call    l2ff7           ; Give status
  9371.         call    l2f3a           ; Get character
  9372.         jr      nc,l2f0e        ; No control
  9373.         jr      z,l2ebd
  9374.         ld      hl,l2ebd
  9375.         ld      a,d
  9376.         cp      (HIGH MMSB)-1   ; Test special address
  9377.         jr      c,l2ef4         ; Nope
  9378.         ld      (l447f),a       ; Set text changed
  9379.         and     NOMSB
  9380.         ld      d,a
  9381.         xor     a
  9382.         ld      (l4542),a       ; Force compile
  9383. l2ef4:
  9384.         push    hl              ; Set return address
  9385.         push    de              ; Save control address
  9386.         ld      hl,l4456+1
  9387.         ld      de,l445a+1
  9388.         ld      bc,l0008
  9389.         lddr                    ; Save a bit
  9390.         ret
  9391. ;
  9392. ; Control: CONTROL PREFIX
  9393. ;
  9394. l2f02::
  9395.         call    l2f8a           ; Get character
  9396.         ld      (iy+22),3
  9397.         call    l4271           ; Get character
  9398.         jr      l2f16
  9399. l2f0e:
  9400.         ld      (l447f),a       ; Re/Set text changed
  9401.         ld      hl,l4542
  9402.         ld      (hl),0          ; Force compile
  9403. l2f16:
  9404.         ld      hl,(l4452)      ; Get current edit pointer
  9405.         ld      de,l7b74+_LinLen-2
  9406.         call    cmp_hl_de               ; Compare HL:DE
  9407.         jr      nc,l2ebd        ; Line too long
  9408.         bit     0,(iy+6)        ; Test insert
  9409.         push    af
  9410.         call    z,l41eb         ; Yeap, so make room
  9411.         pop     af
  9412.         ld      (hl),a          ; Store character
  9413.         inc     hl              ; Bump buffer
  9414.         push    hl
  9415.         call    l4197
  9416.         pop     hl
  9417.         ld      (l4452),hl      ; Set current edit pointer
  9418.         call    l3fe7 ;set column?
  9419.         jp      l2ebd
  9420. ;
  9421. ; Get character
  9422. ; C set indicates control
  9423. ;
  9424. l2f3a:
  9425.         call    l4271           ; Get character
  9426.         cp      '~'+1           ; Test printable range
  9427.         jr      nc,l2f44        ; Nope
  9428.         cp      ' '             ; Test once again
  9429.         ret     nc
  9430. l2f44:
  9431.         ld      hl,l4482        ; Point to control character count
  9432.         ld      (hl),1          ; Init count
  9433.         inc     hl
  9434.         ld      (hl),a          ; Save control
  9435. l2f4b:
  9436.         ;push   hl
  9437.         ;ld     hl,l4482        ; Point to control character count
  9438.         ;ld     de,l42a1
  9439.         ;ld     b,11111111b
  9440.         ;call   l2fc1           ; Find control
  9441.         ;pop    hl
  9442.         ;or     a               ; Test found
  9443.         ;jr     nz,l2f6b        ; Yeap
  9444.         push    hl
  9445.         ld      hl,l4482        ; Point to control character count
  9446.         ld      de,l4369
  9447.         ;ld     b,00011111b
  9448.         ld      b,11111111b
  9449.         call    l2fc1           ; Find control
  9450.         pop     hl
  9451.         or      a               ; Test found
  9452.         scf
  9453.         ret     z               ; Nope
  9454. l2f6b:
  9455.         dec     a               ; Test all found
  9456.         jr      z,l2f78         ; Nope
  9457.         ld      hl,l43f4
  9458.         add     hl,bc           ; Go into table
  9459.         add     hl,bc
  9460.         ld      e,(hl)          ; Fetch address
  9461.         inc     hl
  9462.         ld      d,(hl)
  9463.         scf                     ; Set result
  9464.         ret
  9465. l2f78:
  9466.         call    l2f8a           ; Get character
  9467.         push    af
  9468.         call    l4271           ; Get character
  9469.         inc     (iy+22)
  9470.         inc     hl
  9471.         ld      (hl),a
  9472.         pop     af
  9473.         call    z,l2f8a         ; Get character
  9474.         jr      l2f4b
  9475. ;
  9476. ; Get character
  9477. ;
  9478. l2f8a:
  9479.         call    l4232           ; Poll character from input
  9480.         call    l428f           ; Test look ahead buffer empty
  9481.         ret     nz              ; Nope
  9482.         push    hl
  9483.         ld      hl,256*0+0
  9484.         call    l02a2           ; Position cursor
  9485.         ld      hl,l4482        ; Point to control character count
  9486.         ld      a,(hl)          ; Get length
  9487. l2f9c:
  9488.         push    af
  9489.         inc     hl
  9490.         ld      a,(hl)          ; Get character
  9491.         call    l2fa8           ; Dispaly as control
  9492.         pop     af
  9493.         dec     a
  9494.         jr      nz,l2f9c
  9495.         pop     hl
  9496.         ret
  9497. ;
  9498. ; Display character in Accu
  9499. ;
  9500. l2fa8:
  9501.         push    af
  9502.         call    l3cec           ; Make normal video
  9503.         pop     af
  9504.         cp      ' '             ; Test control
  9505.         jp      nc,puttoconsole_a       ; Put to console if not
  9506.         push    af
  9507.         push    af
  9508.         ld      a,'^'
  9509.         call    puttoconsole_a          ; Indicate control
  9510.         pop     af
  9511.         add     a,'@'
  9512.         call    puttoconsole_a          ; Put to console as ASCII
  9513.         pop     af
  9514.         ret
  9515. ;
  9516. ; ^HL points to key sequence searched for in list ^DE with mask in reg B
  9517. ; Accu= 0 says not found
  9518. ; Accu= 1 says part found
  9519. ; Accu=-1 says found
  9520. ;
  9521. l2fc1:
  9522.         ld      c,-1            ; Init index
  9523.         push    bc
  9524.         push    hl
  9525. l2fc5:
  9526.         pop     hl
  9527.         pop     bc
  9528.         ld      a,(de)          ; Get length from list
  9529.         inc     de
  9530.         or      a               ; Test end
  9531.         ret     z               ; Yeap
  9532.         inc     c               ; Advance index
  9533.         push    bc
  9534.         push    hl
  9535.         ld      c,(hl)          ; Get length from input
  9536.         sub     c               ; Get difference
  9537.         inc     hl
  9538.         jr      nc,l2fd7        ; In range
  9539.         add     a,c             ; Else fix it
  9540.         ld      c,a
  9541.         jr      l2ff0           ; Go adjust
  9542. l2fd7:
  9543.         push    af
  9544. l2fd8:
  9545.         ld      a,(de)          ; Get from list
  9546.         sub     (hl)            ; Compare
  9547.         and     b               ; Set mask
  9548.         jr      nz,l2fed        ; No match
  9549.         inc     de
  9550.         inc     hl
  9551.         dec     c
  9552.         jr      nz,l2fd8
  9553.         pop     af
  9554.         pop     hl
  9555.         pop     bc
  9556.         ld      b,0
  9557.         ld      a,-1
  9558.         ret     z               ; Got exact length
  9559.         ld      a,1             ; Fix for partial success
  9560.         ret
  9561. l2fed:
  9562.         pop     af
  9563.         add     a,c
  9564.         ld      c,a
  9565. l2ff0:
  9566.         ld      b,0
  9567.         ex      de,hl
  9568.         add     hl,bc
  9569.         ex      de,hl
  9570.         jr      l2fc5
  9571. ;
  9572. ; Give editor status
  9573. ;
  9574. l2ff7:
  9575.         call    l4232           ; Poll character from input
  9576.         call    l428f           ; Test look ahead buffer empty
  9577.         ret     nz              ; Nope
  9578.         ld      hl,l4474
  9579.         ld      a,(hl)          ; Test status changed
  9580.         or      a
  9581.         jr      nz,l3078        ; No change
  9582.         ld      (hl),-1         ; Reset it
  9583.         ld      hl,256*0+0
  9584.         ld      (l4476),hl
  9585.         xor     a
  9586.         ld      (l4478),a
  9587.         call    l02a2           ; Position cursor
  9588.         call    l3c12           ; Clear line
  9589.         call    l3cdf           ; Set low video
  9590.         ld      a,(l0168)       ; Get screen columns
  9591.         cp      MINWID          ; Test room for filename
  9592.         jr      c,l302a         ; Nope
  9593.         ld      hl,256*42+0
  9594.         call    l02a2           ; Position cursor
  9595.         call    l3135           ; Type work file
  9596. l302a:
  9597.         ld      hl,256*6+0
  9598.         call    l420e           ; Position cursor and tell line
  9599.         db      'Line '
  9600.         db      null
  9601.         ld      hl,256*16+0
  9602.         call    l420e           ; Position cursor and tell column
  9603.         db      'Col '
  9604.         db      null
  9605.         ld      hl,256*24+0
  9606.         ld      a,(l4472)       ; Get insert mode
  9607.         or      a
  9608.         jr      nz,l305a        ; Overwrite
  9609.         call    l420e           ; Position cursor and tell insert
  9610.         db      'Insert    '
  9611.         db      null
  9612.         jr      l3068
  9613. l305a:
  9614.         call    l420e           ; Position cursor and tell overwrite
  9615.         db      'Overwrite '
  9616.         db      null
  9617. l3068:
  9618.         ld      a,(l4479)       ; Get tabulate state
  9619.         or      a
  9620.         jr      nz,l3078
  9621.         call    l4211
  9622.         db      'Indent'
  9623.         db      null
  9624. l3078:
  9625.         ld      a,(l446c) ;xscroll???
  9626.         add     a,(iy+4)        ; Add column
  9627.         inc     a
  9628.         ld      hl,(l4478)
  9629.         cp      l
  9630.         jr      z,l309b
  9631.         ld      (l4478),a
  9632.         push    af
  9633.         ld      hl,256*20+0
  9634.         call    l02a2           ; Position cursor
  9635.         call    l3cdf           ; Set low video
  9636.         pop     af
  9637.         ld      l,a
  9638.         ld      h,0
  9639.         ld      a,3             ; Set number of digits
  9640.         call    l30ec           ; Give count
  9641. l309b:
  9642.         ld      de,(l4476)
  9643.         ld      hl,(l4450)      ; Get current memory pointer
  9644.         call    cmp_hl_de               ; Compare HL:DE
  9645.         jp      z,l37a4         ; Same, set edit cursor
  9646.         call    l37a4           ; Set edit cursor
  9647.         ld      de,(l4544)      ; Get start of text
  9648.         ld      hl,(l4450)      ; Get current memory pointer
  9649.         or      a
  9650.         sbc     hl,de           ; Get relative position
  9651.         ld      c,l
  9652.         ld      b,h
  9653.         ex      de,hl
  9654.         ld      de,1
  9655.         ld      a,c
  9656.         or      b               ; Test any
  9657.         jr      z,l30d3         ; Nope
  9658. l30bf:
  9659.         ld      a,lf
  9660.         inc     de
  9661.         cpir                    ; Find new line
  9662.         jp      po,l30d3        ; Got it
  9663.         dec     e
  9664.         inc     e
  9665.         call    z,l4232         ; Poll character from input
  9666.         call    l428f           ; Test look ahead buffer empty
  9667.         jr      nz,l30e9        ; Nope
  9668.         jr      l30bf
  9669. l30d3:
  9670.         ld      hl,256*11+0
  9671.         push    de
  9672.         call    l02a2           ; Position cursor
  9673.         call    l3cdf           ; Set low video
  9674.         pop     hl
  9675.         ld      a,5             ; Set number of digits
  9676.         call    l30ec           ; Give count
  9677.         ld      hl,(l4450)      ; Get current memory pointer
  9678.         ld      (l4476),hl
  9679. l30e9:
  9680.         jp      l37a4           ; Set edit cursor
  9681. ;
  9682. ; Print fixed format integer
  9683. ; ENTRY Reg HL holds number to be printed
  9684. ;       Accu holds decimal places
  9685. ;
  9686. l30ec:
  9687.         push    af
  9688.         ld      b,0             ; Clear count
  9689.         call    l30fe           ; Print number
  9690.         pop     af
  9691.         add     a,b             ; Test all digits typed
  9692.         ret     z               ; Yeap
  9693.         ld      b,a
  9694.         ld      a,' '
  9695. l30f8:
  9696.         call    puttoconsole_a          ; Fill remainder with blanks
  9697.         djnz    l30f8
  9698.         ret
  9699. ;
  9700. ; Print decimal number
  9701. ; ENTRY Reg HL holds number
  9702. ;       Reg B  holds places
  9703. ;
  9704. l30fe:
  9705.         ld      a,h
  9706.         or      l               ; Test zero output
  9707.         ld      a,'0'
  9708.         jr      z,l3131         ; Yeap, print it
  9709.         ld      de,10000
  9710.         call    l311f           ; Get ten thousands
  9711.         ld      de,1000
  9712.         call    l311f           ; Get thousands
  9713.         ld      de,100
  9714.         call    l311f           ; Get hundreds
  9715.         ld      de,10
  9716.         call    l311f           ; Get tens
  9717.         ld      de,1            ; Finally units
  9718. ;
  9719. ; Print modulo
  9720. ; ENTRY Reg HL holds number
  9721. ;       Reg DE holds divisor
  9722. ;       Reg B  holds places
  9723. ; EXIT  Reg HL fixed
  9724. ;       Reg B  decremented if digit is printed
  9725. ;
  9726. l311f:
  9727.         xor     a               ; Clear digit
  9728. l3120:
  9729.         sbc     hl,de           ; Divide
  9730.         jr      c,l3127
  9731.         inc     a               ; Bump digit
  9732.         jr      l3120
  9733. l3127:
  9734.         add     hl,de           ; Make remainder positive
  9735.         add     a,'0'           ; Make ASCII
  9736.         cp      '0'             ; Test zero
  9737.         jr      nz,l3131
  9738.         inc     b               ; Test leading zero
  9739.         dec     b
  9740.         ret     z               ; Suppress it
  9741. l3131:
  9742.         dec     b               ; Fix count
  9743.         jp      puttoconsole_a          ; Put to console
  9744. ;
  9745. ; Type work file
  9746. ;
  9747. l3135:
  9748.         ld      de,l451d
  9749.         jp      l2df8           ; Tell name of file
  9750. ;
  9751. ; Get string for search and file function
  9752. ; ENTRY Reg DE points to line buffer
  9753. ;       Byte 0 holds max characters
  9754. ;       Byte 1 holds resulting length
  9755. ;
  9756. l313b:
  9757.         call    l0200           ; Indicate input
  9758. ;
  9759.         db      ': '
  9760.         db      null
  9761.         ex      de,hl
  9762.         push    hl
  9763.         pop     ix              ; Copy buffer
  9764.         inc     hl
  9765.         ld      d,(hl)
  9766.         ld      (hl),0
  9767.         inc     hl
  9768. l314a:
  9769.         res     _LB,(iy+_Video) ; Disable video
  9770.         push    de
  9771.         push    hl
  9772.         call    l2f3a           ; Get character
  9773.         pop     hl
  9774.         pop     de
  9775.         set     _LB,(iy+_Video) ; Allow video
  9776.         jr      nc,l31b9        ; No control
  9777.         jr      nz,l3165
  9778.         ld      a,(l4483)       ; Get character
  9779.         call    l3ef6           ; Test function cancelled
  9780.         jr      l314a
  9781. l3165:
  9782.         ld      a,c
  9783.         cp      0
  9784.         jr      nz,l316d
  9785.         ld      (hl),1ah
  9786.         ret
  9787. l316d:
  9788.         cp      3
  9789.         jr      nz,l317c
  9790.         ld      a,(ix+1)
  9791.         cp      d
  9792.         jr      nc,l314a
  9793.         inc     (ix+1)
  9794.         jr      l31c6
  9795. l317c:
  9796.         cp      5
  9797.         jr      nz,l3190
  9798. l3180:
  9799.         ld      a,(ix+1)
  9800.         cp      d
  9801.         jr      z,l314a
  9802.         ld      a,(hl)          ; Get character
  9803.         call    l2fa8           ; Display as control
  9804.         inc     hl
  9805.         inc     (ix+1)
  9806.         jr      l3180
  9807. l3190:
  9808.         cp      4
  9809.         jr      nz,l319b
  9810. l3194:
  9811.         call    l31d7
  9812.         jr      nz,l3194
  9813.         jr      l314a
  9814. l319b:
  9815.         cp      '-'
  9816.         jr      nz,l31a4
  9817.         call    l4271           ; Get character
  9818.         jr      l31b9
  9819. l31a4:
  9820.         cp      1bh
  9821.         jr      z,l31b4
  9822.         cp      1ch
  9823.         jr      z,l31b4
  9824.         cp      1
  9825.         jr      z,l31b4
  9826.         cp      2
  9827.         jr      nz,l314a
  9828. l31b4:
  9829.         call    l31d7
  9830. l31b7:
  9831.         jr      l314a
  9832. l31b9:
  9833.         ld      e,a
  9834.         ld      a,(ix+1)
  9835.         cp      (ix+0)
  9836.         jr      nc,l314a
  9837.         inc     (ix+1)
  9838.         ld      (hl),e
  9839. l31c6:
  9840.         ld      a,(hl)          ; Get character
  9841.         inc     hl
  9842.         call    l2fa8           ; Display as control
  9843.         ld      a,(ix+1)
  9844.         cp      d
  9845.         jr      c,l31b7
  9846.         ld      d,(ix+1)
  9847.         jp      l31b7
  9848. l31d7:
  9849.         ld      a,(ix+1)
  9850.         or      a
  9851.         ret     z
  9852.         dec     (ix+1)
  9853.         dec     hl
  9854.         ld      a,(hl)
  9855.         cp      ' '
  9856.         call    c,l31e6
  9857. l31e6:
  9858.         call    l4211
  9859.         db      bs+MSB,' '+MSB,bs+MSB
  9860.         db      null
  9861.         ld      a,0ffh
  9862.         or      a
  9863.         ret
  9864. ;
  9865. ; Control: FIND STRING
  9866. ;
  9867. l31f1:
  9868.         xor     a
  9869.         ld      (l447e),a       ; Set find flag
  9870.         call    l31fd           ; Get string searched for
  9871.         call    l3220           ; Get options
  9872.         jr      l3252           ; Enter process
  9873. ;
  9874. ; Get string searched for
  9875. ;
  9876. l31fd:
  9877.         call    l3e04           ; Tell what we want
  9878.         db      'Find'
  9879.         db      null
  9880.         ld      de,l4490        ; Point to buffer
  9881. l3208:
  9882.         jp      l313b           ; Get search string
  9883. ;
  9884. ; Get string to be replaced
  9885. ;
  9886. l320b:
  9887.         call    l3e07           ; Tell what we want
  9888.         db      'Replace with'
  9889.         db      null
  9890.         ld      de,l44b1        ; Point to buffer
  9891.         jr      l3208           ; Get replace string
  9892. ;
  9893. ; Get options
  9894. ;
  9895. l3220:
  9896.         call    l3e07           ; Tell what we want
  9897.         db      'Options'
  9898.         db      null
  9899.         ld      de,l44d2        ; Get buffer
  9900.         call    l313b           ; Get search string
  9901.         ld      a,(l0168)       ; Get screen columns
  9902.         ld      h,a
  9903.         dec     h               ; Fix column
  9904.         ld      l,0             ; Set row
  9905.         jp      l02a2           ; Position cursor
  9906. ;
  9907. ; Control: FIND AND REPLACE STRING
  9908. ;
  9909. l323b:
  9910.         ld      a,-1
  9911.         ld      (l447e),a       ; Set replace flag
  9912.         call    l31fd           ; Get string searched for
  9913.         call    l320b           ; Get replace string
  9914.         call    l3220           ; Get options
  9915.         jr      l3252           ; Enter process
  9916. ;
  9917. ; Control: REPEAT LAST SEARCH
  9918. ;
  9919. l324b:
  9920.         call    l2f8a           ; Get character
  9921.         ld      (iy+22),3       ; Init count
  9922. l3252:
  9923.         call    l3e40           ; Sample character
  9924.         call    l3e23           ; Find last non blank
  9925.         inc     hl
  9926.         ld      de,(l4452)      ; Get current edit pointer
  9927.         call    l4191           ; Find min
  9928.         ld      de,l7b74
  9929.         or      a
  9930.         sbc     hl,de           ; Subtract base
  9931.         ld      de,(l4450)      ; Get current memory pointer
  9932.         add     hl,de           ; Add for real address
  9933.         ld      (l4488),hl      ; Set end
  9934.         ld      de,0            ; Clear counter
  9935.         ld      hl,l44d2+1      ; Init buffer
  9936.         ld      b,(hl)          ; Fetch length
  9937.         ld      (iy+17),0       ; Clear flag
  9938.         inc     b               ; Test any in buffer
  9939.         dec     b
  9940.         jr      z,l32c0         ; Nope
  9941. l327d:
  9942.         inc     hl
  9943.         ld      a,(hl)          ; Get character
  9944.         cp      '0'             ; Test possible count
  9945.         jr      c,l3293         ; Nope
  9946.         cp      '9'+1
  9947.         jr      nc,l3293
  9948.         call    l3426
  9949.         sub     '0'
  9950.         add     a,e             ; Add digit to count
  9951.         ld      e,a
  9952.         jr      nc,l32be
  9953.         inc     d               ; Remember carry
  9954.         jr      l32be
  9955. l3293:
  9956.         call    doupcase                ; Convert to upper case
  9957.         cp      'W'             ; Test whole word search
  9958.         jr      nz,l329e
  9959.         set     _W,(iy+17)
  9960. l329e:
  9961.         cp      'U'             ; Test ignore case
  9962.         jr      nz,l32a6
  9963.         set     _U,(iy+17)
  9964. l32a6:
  9965.         cp      'N'             ; Test no request
  9966.         jr      nz,l32ae
  9967.         set     _N,(iy+17)
  9968. l32ae:
  9969.         cp      'G'             ; Test global
  9970.         jr      nz,l32b6
  9971.         set     _G,(iy+17)
  9972. l32b6:
  9973.         cp      'B'             ; Test backwards
  9974.         jr      nz,l32be
  9975.         set     _B,(iy+17)
  9976. l32be:
  9977.         djnz    l327d
  9978. l32c0:
  9979.         ld      a,e             ; Test loop count
  9980.         or      d
  9981.         jr      nz,l32c7        ; Yeap
  9982.         ld      de,1            ; Set default
  9983. l32c7:
  9984.         ld      (l448a),de      ; Save loop count
  9985.         ld      hl,(l4544)      ; Get start of text
  9986.         ld      a,(l447d)       ; Get option flags
  9987.         bit     _B,a            ; Test backwards
  9988.         jr      z,l32d8         ; Nope
  9989.         ld      hl,(l4546)      ; Get end of text
  9990. l32d8:
  9991.         bit     _G,a            ; Test global search
  9992.         jr      nz,l32df        ; Yeap
  9993.         ld      hl,(l4488)      ; Get end of search pointer
  9994. l32df:
  9995.         ld      (l4488),hl      ; Set end of search pointer
  9996.         bit     _B,(iy+17)      ; Test backwards
  9997.         jr      nz,l32f5        ; Yeap
  9998.         ld      de,(l4546)      ; Get end of text
  9999.         dec     de
  10000.         call    cmp_hl_de               ; Compare HL:DE
  10001.         jp      nc,l3380
  10002.         jr      l32fb
  10003. l32f5:
  10004.         call    l3bee           ; Fix to start of line
  10005.         jp      c,l3380
  10006. l32fb:
  10007.         ld      de,l4492
  10008.         ld      a,(l4491)
  10009.         ld      b,a
  10010.         bit     _B,(iy+17)      ; Test backwards
  10011.         jr      z,l330e         ; Nope
  10012.         dec     a
  10013.         add     a,e
  10014.         ld      e,a
  10015.         jr      nc,l330e
  10016.         inc     d
  10017. l330e:
  10018.         bit     _W,(iy+17)      ; Test whole word search
  10019.         jr      z,l3323         ; Nope
  10020.         push    de
  10021.         push    hl
  10022.         call    l33fb
  10023.         ld      a,(hl)
  10024.         pop     hl
  10025.         pop     de
  10026.         jr      c,l3323
  10027.         call    l33e4
  10028.         jr      c,l3377
  10029. l3323:
  10030.         dec     b
  10031.         inc     b
  10032.         jr      z,l332e
  10033. l3327:
  10034.         call    l340f
  10035.         jr      nz,l3377
  10036.         djnz    l3364
  10037. l332e:
  10038.         bit     _W,(iy+17)      ; Test whole word search
  10039.         jr      z,l3341         ; Nope
  10040.         push    hl
  10041.         call    l3406
  10042.         ld      a,(hl)
  10043.         pop     hl
  10044.         jr      c,l3341
  10045.         call    l33e4
  10046.         jr      c,l3377
  10047. l3341:
  10048.         bit     _B,(iy+17)      ; Test backwards
  10049.         call    z,l3bdd         ; Nope
  10050.         ld      a,(l447e)       ; Get find flag
  10051.         or      a
  10052.         call    nz,l3430        ; Replace selected
  10053.         bit     _G,(iy+17)      ; Test global search
  10054. l3353:
  10055.         jr      nz,l32df
  10056.         ld      bc,(l448a)      ; Get loop count
  10057.         dec     bc              ; Decrement
  10058.         ld      (l448a),bc
  10059.         ld      a,b
  10060.         or      c
  10061.         jr      nz,l3353
  10062.         jr      l33a9
  10063. l3364:
  10064.         push    de
  10065.         call    l3406
  10066.         pop     de
  10067.         jr      c,l3380
  10068.         bit     _B,(iy+17)      ; Test backwards
  10069.         jr      z,l3374         ; Nope
  10070.         dec     de
  10071.         jr      l3327
  10072. l3374:
  10073.         inc     de
  10074.         jr      l3327
  10075. l3377:
  10076.         ld      hl,(l4488)      ; Get end of search pointer
  10077.         call    l3406
  10078.         jp      nc,l32df
  10079. l3380:
  10080.         call    l33d6
  10081.         call    l33a9
  10082.         bit     _G,(iy+17)      ; Test global search
  10083.         ret     nz
  10084.         call    l3e04
  10085.         db      'Search string not found'
  10086.         db      null
  10087.         jp      l3f12
  10088. ;status line???
  10089. l33a9:
  10090.         call    l33af
  10091.         jp      l3d2c           ; Restore line
  10092. l33af:
  10093.         ld      de,(l4546)      ; Get end of text
  10094.         dec     de
  10095.         call    cmp_hl_de               ; Compare HL:DE
  10096.         jr      c,l33ba ;hl<de
  10097.         ex      de,hl
  10098. l33ba:
  10099.         push    hl
  10100.         push    hl
  10101.         call    l3bf5           ; Get previous EOL
  10102.         ld      (l4450),hl      ; Set current memory pointer
  10103.         or      a
  10104.         ex      de,hl
  10105.         pop     hl
  10106.         sbc     hl,de
  10107.         ld      de,l7b74
  10108.         add     hl,de
  10109.         ld      (l4452),hl      ; Set current edit pointer
  10110.         call    l3fe7 ;set column?
  10111.         call    l401f
  10112.         pop     hl
  10113.         ret
  10114. l33d6:
  10115.         ld      de,(l4544)      ; Get start of text
  10116.         call    l4191           ; Find min
  10117.         ld      hl,(l4546)      ; Get end of text
  10118.         dec     hl
  10119.         jp      l4191           ; Find min
  10120. l33e4:
  10121.         cp      '0'
  10122.         jr      c,l33f9
  10123.         cp      ':'
  10124.         ret     c
  10125.         cp      'A'
  10126.         jr      c,l33f9
  10127.         cp      5bh
  10128.         ret     c
  10129.         cp      61h
  10130.         jr      c,l33f9
  10131.         cp      7bh
  10132.         ret     c
  10133. l33f9:
  10134.         or      a
  10135.         ret
  10136. l33fb:
  10137.         bit     _B,(iy+17)      ; Test backwards
  10138.         jr      z,l340c         ; Nope
  10139. l3401:
  10140.         call    l3bdd
  10141.         ccf
  10142.         ret
  10143. l3406:
  10144.         bit     _B,(iy+17)      ; Test backwards
  10145.         jr      z,l3401         ; Nope
  10146. l340c:
  10147.         jp      l3bee           ; Fix to start of line
  10148. l340f:
  10149.         ld      a,(de)
  10150.         cp      1
  10151.         ret     z
  10152.         cp      (hl)
  10153.         ret     z
  10154.         bit     _U,(iy+17)      ; Test ignore case
  10155.         jr      z,l3424         ; Yeap
  10156.         call    l33e4
  10157.         jr      nc,l3424
  10158.         xor     (hl)
  10159.         and     0dfh
  10160.         ret
  10161. l3424:
  10162.         cp      (hl)
  10163.         ret
  10164. l3426:
  10165.         push    hl
  10166.         ld      l,e
  10167.         ld      h,d
  10168.         add     hl,hl
  10169.         add     hl,hl
  10170.         add     hl,de
  10171.         add     hl,hl
  10172.         ex      de,hl
  10173.         pop     hl
  10174.         ret
  10175. l3430:
  10176.         push    hl
  10177.         call    l428f           ; Test look ahead buffer empty
  10178.         jr      z,l343c         ; Yeap
  10179.         bit     _N,(iy+17)      ; Test no request
  10180.         jr      nz,l349d        ; Yeap
  10181. l343c:
  10182.         call    l33a9
  10183.         call    l3b96
  10184.         bit     _N,(iy+17)      ; Test no request
  10185.         jr      nz,l349d        ; Yeap
  10186.         call    l3e07
  10187.         db      'Replace (','Y'+MSB,'/','N'+MSB,'): '
  10188.         db      null
  10189. l345b:
  10190.         ld      l,(iy+5)        ; Get row
  10191.         ld      h,(iy+4)        ; Get column
  10192.         call    l02a2           ; Position cursor
  10193.         ld      bc,l07d0
  10194. l3467:
  10195.         call    l4232           ; Poll character from input
  10196.         call    l428f           ; Test look ahead buffer empty
  10197.         jr      nz,l348c        ; Nope
  10198.         dec     bc
  10199.         ld      a,c
  10200.         or      b
  10201.         jr      nz,l3467
  10202.         ld      hl,256*15+0
  10203.         call    l02a2           ; Position cursor
  10204.         ld      bc,l07d0
  10205. l347d:
  10206.         call    l4232           ; Poll character from input
  10207.         call    l428f           ; Test look ahead buffer empty
  10208.         jr      nz,l348c        ; Nope
  10209.         dec     bc
  10210.         ld      a,c
  10211.         or      b
  10212.         jr      nz,l347d
  10213.         jr      l345b
  10214. l348c:
  10215.         call    l4271           ; Get character
  10216.         call    l3ef6           ; Test function cancelled
  10217.         call    doupcase                ; Convert to upper case
  10218.         cp      'Y'
  10219.         jr      z,l349d
  10220.         cp      19h
  10221.         jr      nz,l34eb
  10222. l349d:
  10223.         set     0,(iy+19)
  10224.         xor     a
  10225.         ld      (l4542),a       ; Force compile
  10226.         ld      a,(l44b2)
  10227.         ld      c,a
  10228.         ld      b,0
  10229.         pop     hl
  10230.         push    hl
  10231.         push    bc
  10232.         ld      a,(l4491)
  10233.         sub     c
  10234.         ld      c,a
  10235.         push    af
  10236.         jr      nc,l34b7
  10237.         dec     b
  10238. l34b7:
  10239.         bit     _B,(iy+17)      ; Test backwards
  10240.         jr      nz,l34c0        ; Yeap
  10241.         ld      hl,(l4488)      ; Get end of search pointer
  10242. l34c0:
  10243.         pop     af
  10244.         push    hl
  10245.         call    nz,l3f18
  10246.         pop     de
  10247.         pop     bc
  10248.         ld      a,b
  10249.         or      c
  10250.         jr      z,l34d0
  10251.         ld      hl,l44b3
  10252.         ldir
  10253. l34d0:
  10254.         call    l428f           ; Test look ahead buffer empty
  10255.         push    af
  10256.         call    nz,l4147        ; Nope, so reset row
  10257.         pop     af
  10258.         jr      nz,l34e2        ; Eas not empty
  10259.         push    de
  10260.         call    l3d2c           ; Restore line
  10261.         call    l4139
  10262.         pop     de
  10263. l34e2:
  10264.         bit     _B,(iy+17)      ; Test backwards
  10265.         jr      nz,l34eb        ; Yeap
  10266.         pop     hl
  10267.         ex      de,hl
  10268.         ret
  10269. l34eb:
  10270.         pop     hl
  10271.         ret
  10272. ;
  10273. ; Control: WRITE BLOCK TO FILE
  10274. ;
  10275. l34ed:
  10276.         bit     0,(iy+20)       ; Test block set
  10277.         ret     nz              ; Nope
  10278.         call    l3e40           ; Sample character
  10279.         call    l3d2c           ; Restore line
  10280.         ld      hl,(l4460)      ; Get block start pointer
  10281.         ld      de,(l4462)      ; Get block end pointer
  10282.         call    cmp_hl_de               ; Compare HL:DE
  10283.         ret     nc              ; Start >= end
  10284.         call    l363c
  10285.         call    l3d2c           ; Restore line
  10286. l3509:
  10287.         call    l3e04           ; Tell what we want
  10288.         db      'Write block to file'
  10289.         db      null
  10290.         call    l3566           ; Get name of file
  10291.         ret     z
  10292.         call    l2d2a           ; Prepare .PAS file
  10293.         ld      c,_open
  10294.         call    BDOS_with_FCB1          ; Open file ;WHERE IS CLOSE???
  10295.         inc     a               ; Test file already exist
  10296.         jr      z,l3551         ; Nope
  10297.         call    l3e07
  10298.         db      'Overwrite old '
  10299.         db      null
  10300.         ld      de,l005c
  10301.         call    l2df8           ; Tell name of file
  10302.         call    l2d01           ; Ask for YES or NO
  10303.         jr      z,l3509         ; No
  10304.         ld      c,_delete
  10305.         call    BDOS_with_FCB1          ; Delete file
  10306. l3551:
  10307.         ld      hl,(l4462)      ; Get block end pointer
  10308.         ld      a,(hl)          ; Save character
  10309.         push    af
  10310.         push    hl
  10311.         ld      (hl),eof        ; Set end of file
  10312.         call    l3e0d           ; Set cursor
  10313.         ld      hl,(l4460)      ; Get block start pointer
  10314.         call    l2692           ; Save block to file
  10315.          ld     c,_close
  10316.          call   BDOS_with_FCB1
  10317.         pop     hl
  10318.         pop     af
  10319.         ld      (hl),a          ; Restore character
  10320.         ret
  10321. ;
  10322. ; Get name of file
  10323. ;
  10324. l3566:
  10325.         ld      de,l44df
  10326.         call    l313b           ; Get filename
  10327.         ld      de,l44df+2
  10328.         ld      a,(de)
  10329.         cp      eof             ; Test empty name
  10330.         ret
  10331. ;
  10332. ; Control: READ BLOCK FROM FILE
  10333. ;
  10334. l3573:
  10335.         call    l3e04           ; Tell what we want
  10336.         db      'Read block from file'
  10337.         db      null
  10338.         call    l3566           ; Get name of file
  10339.         ret     z
  10340.         call    l2d2a           ; Prepare .PAS file
  10341.         ld      c,_open
  10342.         call    BDOS_with_FCB1          ; Open file ;WHERE IS CLOSE???
  10343.         inc     a               ; Test success
  10344.         jr      nz,l35a8        ; Yeap
  10345.         call    l3e0d           ; Set cursor
  10346.         ld      de,l005c
  10347.         call    l2e3e           ; Tell not found
  10348.         call    l3f12
  10349.         jr      l3573
  10350. l35a8:
  10351.         res     0,(iy+20)       ; Mark block
  10352.         call    l363c
  10353.         ld      hl,(l4546)      ; Get end of text
  10354.         ld      de,(l4548)      ; Get top of available memory
  10355.         ld      bc,l00fe
  10356.         add     hl,bc           ; Build top
  10357.         or      a
  10358.         sbc     hl,de           ; Calculate size
  10359.         push    hl
  10360.         ld      b,h
  10361.         ld      c,l
  10362.         ld      hl,(l448c)
  10363.         scf
  10364.         call    l3f18
  10365.          ld     c,_close
  10366.          call   BDOS_with_FCB1
  10367.         pop     de
  10368.         ld      hl,l35dd        ; Set return address
  10369.         push    hl
  10370.         ld      hl,(l448c)
  10371.         push    hl
  10372.         xor     a
  10373.         sbc     hl,de
  10374.         push    hl
  10375.         ld      hl,l35f1
  10376.         ld      (l257c+1),hl    ; Redirect load error
  10377.         jp      l2560           ; Load the block
  10378. ;
  10379. ; Process end of read
  10380. ;
  10381. l35dd:
  10382.         ld      (l4462),hl      ; Set block end pointer
  10383.         ex      de,hl
  10384.         ld      hl,(l448c)
  10385.         ld      (l4460),hl      ; Set block start pointer
  10386. l35e7:
  10387.         ld      hl,(l7b6d)      ; Get last memory address
  10388.         or      a
  10389.         sbc     hl,de           ; Build difference
  10390.         ld      b,h
  10391.         ld      c,l
  10392.         jr      l3612
  10393. ;
  10394. ; Redirected load error
  10395. ;
  10396. l35f1:
  10397.         ld      de,(l448c)
  10398.         call    l35e7
  10399.         jp      l3ed9
  10400. ;
  10401. ; Control: MOVE BLOCK
  10402. ;
  10403. l35fb:
  10404.         call    l363c
  10405.         jp      nc,l3d2c        ; Restore line
  10406.         call    l3687
  10407.         ld      hl,(l448c)
  10408.         ld      de,(l4460)      ; Get block start pointer
  10409.         ld      (l4460),hl      ; Set block start pointer
  10410.         add     hl,bc
  10411.         ld      (l4462),hl      ; Set block end pointer
  10412. l3612:
  10413.         ex      de,hl
  10414.         or      a
  10415.         call    l3f18
  10416.         ld      hl,(l4460)      ; Get block start pointer
  10417.         call    l33a9
  10418.         jp      l3762
  10419. ;
  10420. ; Control: COPY BLOCK
  10421. ;
  10422. l3620:
  10423.         call    l363c
  10424.         jp      nc,l3d2c        ; Restore line
  10425.         call    l3687
  10426.         ld      hl,(l448c)
  10427.         ld      (l4460),hl      ; Set block start pointer
  10428.         add     hl,bc
  10429.         ld      (l4462),hl      ; Set block end pointer
  10430.         call    l401f
  10431.         call    l3d2c           ; Restore line
  10432.         jp      l3762
  10433. ;
  10434. ;
  10435. ;
  10436. l363c:
  10437.         bit     0,(iy+20)       ; Test block set
  10438.         jr      z,l3644         ; Yeap
  10439.         xor     a
  10440.         ret
  10441. l3644:
  10442.         call    l3e23           ; Find last non blank
  10443.         inc     hl
  10444.         ld      de,(l4452)      ; Get current edit pointer
  10445.         push    de
  10446.         call    l4191           ; Find min
  10447.         ex      de,hl
  10448.         call    l3e44           ; Sample character
  10449.         pop     hl
  10450.         ld      de,l7b74
  10451.         or      a
  10452.         sbc     hl,de           ; Subtract base
  10453.         ld      de,(l4450)      ; Get current memory pointer
  10454.         add     hl,de           ; Build real pointer
  10455.         ld      (l448c),hl
  10456.         push    hl
  10457.         ld      de,(l4460)      ; Get block start pointer
  10458.         inc     de
  10459.         call    cmp_hl_de               ; Compare HL:DE
  10460.         ld      de,(l4462)      ; Get block end pointer
  10461.         jr      c,l367a         ; HL < Start_Of_Block
  10462.         call    cmp_hl_de               ; Compare HL:DE
  10463.         jr      nc,l367a        ; HL >= End_Of_Block
  10464.         or      a
  10465.         jr      l3685
  10466. l367a:
  10467.         ld      hl,(l4460)      ; Get block start pointer
  10468.         or      a
  10469.         sbc     hl,de
  10470.         ld      (l448e),hl
  10471.         ld      c,l
  10472.         ld      b,h
  10473. l3685:
  10474.         pop     hl
  10475.         ret
  10476. ;
  10477. ;
  10478. ;
  10479. l3687:
  10480.         call    l3f18
  10481.         ld      bc,(l448e)
  10482.         ld      a,c             ; Negate value
  10483.         cpl
  10484.         ld      c,a
  10485.         ld      a,b
  10486.         cpl
  10487.         ld      b,a
  10488.         inc     bc
  10489.         ld      de,(l448c)
  10490.         ld      hl,(l4460)      ; Get block start pointer
  10491.         push    bc
  10492.         ldir
  10493.         pop     bc
  10494.         ret
  10495. ;
  10496. ; Control: DELETE BLOCK
  10497. ;
  10498. l36a1:
  10499.         bit     0,(iy+20)       ; Test block set
  10500.         ret     nz              ; Nope
  10501.         call    l3e40           ; Sample character
  10502.         ld      hl,(l4460)      ; Get block start pointer
  10503.         call    l3bf5           ; Get previous EOL
  10504.         ld      (l4450),hl      ; Set current memory pointer
  10505.         ld      hl,(l4454)      ; Get block pointer
  10506.         ld      de,(l4460)      ; Get block start pointer
  10507.         inc     de
  10508.         call    cmp_hl_de               ; Compare HL:DE
  10509.         jr      c,l36ce         ; HL < Start_Of_Block
  10510.         ld      de,(l4462)      ; Get block end pointer
  10511.         call    cmp_hl_de               ; Compare HL:DE
  10512.         jr      nc,l36ce        ; HL >= End_Of_Block
  10513.         ld      hl,(l4450)      ; Get current memory pointer
  10514.         ld      (l4454),hl      ; Set block pointer
  10515. l36ce:
  10516.         ld      hl,(l4462)      ; Get block end pointer
  10517.         ld      de,(l4460)      ; Get block start pointer
  10518.         or      a
  10519.         sbc     hl,de
  10520.         jp      c,l3d2c         ; Restore line if End < Start
  10521.         ld      c,l
  10522.         ld      b,h
  10523.         ex      de,hl
  10524.         push    hl
  10525.         push    bc
  10526.         push    af
  10527.         call    l401f
  10528.         pop     af
  10529.         pop     bc
  10530.         pop     hl
  10531.         call    l3f18
  10532.         ld      hl,(l4450)      ; Get current memory pointer
  10533.         ld      (l4460),hl      ; Set block start pointer
  10534.         ld      (l4462),hl      ; Set block end pointer
  10535.         call    l3d2c           ; Restore line
  10536.         jp      l3762
  10537. ;
  10538. ; Control: TOGGLE BLOCK DISPLAY
  10539. ;
  10540. l36f9:
  10541.         ld      hl,l4480        ; Point to block mark
  10542.         call    l3796           ; Toggle block bit
  10543.         jp      l3762
  10544. ;
  10545. ; Control: MARK END OF BLOCK
  10546. ;
  10547. l3702:
  10548.         ld      hl,(l4452)      ; Get current edit pointer
  10549.         ld      (l4466),hl      ; Set for end of block
  10550.         ld      hl,(l4450)      ; Get current memory pointer
  10551.         ld      (l4462),hl      ; Set block end pointer
  10552.         bit     1,(iy+1)        ; Test end block
  10553.         set     1,(iy+1)
  10554. l3716:
  10555.         ex      af,af'
  10556.         bit     0,(iy+20)       ; Test previous block set
  10557.         res     0,(iy+20)       ; Set now
  10558.         jr      nz,l3762        ; Was not set
  10559.         ex      af,af'
  10560.         jr      z,l3762         ; Prevous was also not set
  10561.         jr      l374e
  10562. ;
  10563. ; Control: MARK BEGIN OF BLOCK
  10564. ;
  10565. l3726:
  10566.         ld      hl,(l4452)      ; Get current edit pointer
  10567.         ld      (l4464),hl      ; Save address
  10568.         ld      hl,(l4450)      ; Get current memory pointer
  10569.         ld      (l4460),hl      ; Set block start pointer
  10570.         bit     0,(iy+1)        ; Test start block
  10571.         set     0,(iy+1)
  10572.         jr      l3716
  10573. ;
  10574. ; Control: BEGIN OF BLOCK
  10575. ;
  10576. l373c:
  10577.         call    l3e40           ; Sample character
  10578.         ld      hl,(l4460)      ; Get block start pointer
  10579.         jp      l33a9
  10580. ;
  10581. ; Control: END OF BLOCK
  10582. ;
  10583. l3745:
  10584.         call    l3e40           ; Sample character
  10585.         ld      hl,(l4462)      ; Get block end pointer
  10586.         jp      l33a9
  10587. ;
  10588. ;
  10589. ;
  10590. l374e:
  10591.         ld      h,0             ; Set left column
  10592.         call    l37a7           ; Set editor cursor
  10593.         ld      hl,l7b74        ; Load base address
  10594.         set     0,(iy+16)
  10595.         call    l3c1a
  10596.         res     0,(iy+16)
  10597.         ret
  10598. ;
  10599. ;
  10600. ;
  10601. l3762:
  10602.         call    l374e
  10603.         jp      l4147           ; Reset row
  10604. ;
  10605. ; Control: END OF TEXT
  10606. ;
  10607. l3768:
  10608.         call    l3e40           ; Sample character
  10609.         ld      hl,(l4546)      ; Get end of text
  10610.         jp      l33a9
  10611. ;
  10612. ; Control: LINE LEFT
  10613. ;
  10614. l3771:
  10615.         ld      hl,l7b74        ; Set start of line
  10616.         ld      (l4452),hl      ; Set current edit pointer
  10617.         jp      l3fe7 ;set column?
  10618. ;
  10619. ; Control: LINE RIGHT
  10620. ;
  10621. l377a:
  10622.         call    l3e23           ; Find last non blank
  10623.         inc     hl
  10624.         ld      de,l7b74+_LinLen
  10625.         call    cmp_hl_de               ; Compare HL:DE
  10626.         jr      c,l3789
  10627.         ld      hl,l7b74+_LinLen-1
  10628. l3789:
  10629.         ld      (l4452),hl      ; Set current edit pointer
  10630.         jp      l3fe7 ;set column?
  10631. ;
  10632. ; Control: TOGGLE INSERT/OVERWRITE
  10633. ;
  10634. l378f:
  10635.         ld      (iy+8),0        ; Set no change
  10636.         ld      hl,l4472        ; Point to insert mode
  10637. ;
  10638. ; Toggle status bit ^HL
  10639. ;
  10640. l3796:
  10641.         ld      a,(hl)          ; Get value
  10642.         xor     1               ; Toggle bit
  10643.         ld      (hl),a
  10644.         ret
  10645. ;
  10646. ; Control: TOGGLE TABULATE
  10647. ;
  10648. l379b:
  10649.         ld      (iy+8),0        ; Set no change
  10650.         ld      hl,l4479
  10651.         jr      l3796           ; Toggle tabulate bit
  10652. ;
  10653. ; Set current edit cursor
  10654. ;
  10655. l37a4:
  10656.         ld      h,(iy+4)        ; Get column
  10657. ;
  10658. ; Set editor cursor to current row
  10659. ; ENTRY Reg H holds column position
  10660. ;
  10661. l37a7:
  10662.         ld      l,(iy+5)        ; Get row
  10663.         jp      l02a2           ; Position cursor
  10664. ;
  10665. ; Control: LINE DOWN
  10666. ;
  10667. l37ad:
  10668.         ld      hl,(l4450)      ; Get current memory pointer
  10669.         call    findnexteol             ; Find next end of line
  10670.         ret     c               ; Out of text
  10671.         call    l3e40           ; Sample character
  10672.         ld      hl,(l4450)      ; Get current memory pointer
  10673.         call    findnexteol             ; Find next end of line
  10674. l37bd:
  10675.         ld      (l4450),hl      ; Set current memory pointer
  10676.         res     0,(iy+14)
  10677.         set     0,(iy+21)
  10678.         call    l401f
  10679.         res     0,(iy+21)
  10680.         jp      l3d2c           ; Restore line
  10681. ;
  10682. ; Control: LINE UP
  10683. ;
  10684. l37d2:
  10685.         ld      hl,(l4450)      ; Get current memory pointer
  10686.         call    findprevline            ; Find previous line
  10687.         ret     c               ; Below start of text
  10688.         push    hl
  10689.         call    l3e40           ; Sample character
  10690.         pop     hl
  10691.         jr      l37bd
  10692. ;
  10693. ; Control: SCROLL UP
  10694. ;
  10695. l37e0:
  10696.         ld      hl,(curstartofpage)     ; Get start of screen
  10697.         ld      de,(l4544)      ; Get start of text
  10698.         call    cmp_hl_de               ; Compare HL:DE
  10699.         ret     z
  10700.         call    l3e40           ; Sample character
  10701.         ld      b,0
  10702.         ld      hl,(l4450)      ; Get current memory pointer
  10703. l37f3:
  10704.         ld      de,(curstartofpage)     ; Get start of screen
  10705.         call    cmp_hl_de               ; Compare HL:DE
  10706.         jr      z,l3802         ; Match
  10707.         call    findprevline            ; Find previous line
  10708.         inc     b
  10709.         jr      l37f3
  10710. l3802:
  10711.         ld      de,(l4450)      ; Get current memory pointer
  10712.         ld      (l4450),hl      ; Set current memory pointer
  10713.         ex      de,hl
  10714.         ld      a,(l0169)       ; Get screen lines
  10715.         sub     3               ; Less status
  10716.         cp      b
  10717.         jr      nz,l3815
  10718.         call    findprevline            ; Find previous line
  10719. l3815:
  10720.         push    hl
  10721.         ld      hl,(l4450)      ; Get current memory pointer
  10722.         call    findprevline            ; Find previous line
  10723.         call    l37bd
  10724.         pop     hl
  10725. l3820:
  10726.         jr      l37bd
  10727. ;
  10728. ; Control: SCROLL DOWN
  10729. ;
  10730. l3822:
  10731.         call    l3e40           ; Sample character
  10732.         ld      hl,(l4450)      ; Get current memory pointer
  10733.         push    hl
  10734.         ld      hl,(curstartofpage)     ; Get start of screen
  10735.         ld      a,(l0169)       ; Get screen lines
  10736.         sub     2               ; Less status
  10737.         ld      b,a
  10738. l3832:
  10739.         call    findnexteol             ; Find next end of line
  10740.         djnz    l3832
  10741.         push    af
  10742.         call    l37bd
  10743.         pop     af
  10744.         pop     hl
  10745.         jr      c,l3820
  10746.         ld      de,(curstartofpage)     ; Get start of screen
  10747.         call    cmp_hl_de               ; Compare HL:DE
  10748.         jr      nc,l3820        ; HL >= Start_Of_Screen
  10749.         call    findnexteol             ; Find next end of line
  10750.         jr      l3820
  10751. ;
  10752. ; Control: BOTTOM OF SCREEN
  10753. ;
  10754. l384d:
  10755.         ld      hl,(curstartofpage)     ; Get start of screen
  10756.         ld      de,(l4450)      ; Get current memory pointer
  10757.         call    cmp_hl_de               ; Compare HL:DE
  10758.         ret     z               ; Same
  10759.         push    hl
  10760.         call    l3e40           ; Sample character
  10761.         pop     hl
  10762.         jr      l3820
  10763. ;
  10764. ; Control: TOP OF SCREEN
  10765. ;
  10766. l385f:
  10767.         call    l3e40           ; Sample character
  10768.         ld      hl,(curstartofpage)     ; Get start of screen
  10769.         ld      a,(l0169)       ; Get screen lines
  10770.         sub     3               ; Less status
  10771.         ld      b,a
  10772. l386b:
  10773.         call    findnexteol             ; Find next end of line
  10774.         djnz    l386b
  10775.         jr      l3820
  10776. ;
  10777. ; Control: PAGE DOWN
  10778. ;
  10779. l3872:
  10780.         call    l3e40           ; Sample character
  10781.         ld      a,(l0169)       ; Get screen lines
  10782.         sub     2               ; Less status
  10783.         ld      c,a
  10784.         ld      b,a
  10785.         ld      hl,(curstartofpage)     ; Get start of screen
  10786. l387f:
  10787.         call    findnexteol             ; Find next end of line
  10788.         djnz    l387f
  10789.         ld      (curstartofpage),hl     ; Set start of screen
  10790.         ld      b,c
  10791.         ld      hl,(l4450)      ; Get current memory pointer
  10792. l388b:
  10793.         call    findnexteol             ; Find next end of line
  10794.         djnz    l388b
  10795. l3890:
  10796.         ld      (l4450),hl      ; Set current memory pointer
  10797.         call    l401f
  10798.         call    l4147           ; Reset row
  10799.         jp      l3d2c           ; Restore line
  10800. ;
  10801. ; Control: PAGE UP
  10802. ;
  10803. l389c:
  10804.         call    l3e40           ; Sample character
  10805.         ld      a,(l0169)       ; Get screen lines
  10806.         sub     2               ; Less status
  10807.         ld      b,a
  10808.         ld      c,a
  10809.         ld      hl,(curstartofpage)     ; Get start of screen
  10810. l38a9:
  10811.         call    findprevline            ; Find previous line
  10812.         djnz    l38a9
  10813.         ld      (curstartofpage),hl     ; Set start of screen
  10814.         ld      b,c
  10815.         ld      hl,(l4450)      ; Get current memory pointer
  10816. l38b5:
  10817.         call    findprevline            ; Find previous line n-times
  10818.         djnz    l38b5
  10819.         jr      l3890
  10820. ;
  10821. ; Control: BEGIN OF TEXT
  10822. ;
  10823. l38bc:
  10824.         ld      hl,(curstartofpage)     ; Get start of screen
  10825.         ld      de,(l4544)      ; Get start of text
  10826.         call    cmp_hl_de               ; Compare HL:DE
  10827.         jr      z,l38cb         ; Same
  10828.         call    l4147           ; Reset row
  10829. l38cb:
  10830.         call    l3e40           ; Sample character
  10831.         ld      hl,(l4544)      ; Get start of text
  10832.         ld      (l4450),hl      ; Set current memory pointer
  10833.         ld      (curstartofpage),hl     ; Set start of screen
  10834.         call    l401f
  10835.         call    l3d2c           ; Restore line
  10836.         ld      hl,l7b74
  10837.         ld      (l4452),hl      ; Init edit pointer
  10838.         jp      l3fe7 ;set column?
  10839. ;
  10840. ; Control: NEW LINE
  10841. ;
  10842. l38e6:
  10843.         bit     0,(iy+6)        ; Test insert
  10844.         jr      z,l38f2         ; New line
  10845.         call    l37ad           ; Line down
  10846.         jp      l3771           ; Goto start of line
  10847. l38f2:
  10848.         set     0,(iy+19)
  10849.         xor     a
  10850.         ld      (l4542),a       ; Force compile
  10851.         ld      a,lf
  10852.         call    puttoconsole_a          ; Put new line to console
  10853.         call    l3918
  10854.         call    l37a4           ; Set edit cursor
  10855.         bit     0,(iy+13)       ; Test auto tab
  10856.         ret     nz              ; Yeap
  10857.         call    l3a6b           ; Position to previous line
  10858.         ret     c               ; Below start of text
  10859.         ld      de,l43f2
  10860.         call    l412e           ; Find blank
  10861.         jp      c,l3a72         ; Yeap, insert tab
  10862.         ret
  10863. ;
  10864. ;
  10865. ;
  10866. l3918:
  10867.         call    l3950
  10868.         ld      hl,(l4450)      ; Get current memory pointer
  10869.         push    hl
  10870.         call    l3d2c           ; Restore line
  10871.         call    l3e40           ; Sample character
  10872.         pop     hl
  10873.         call    findnexteol             ; Find next end of line
  10874.         ld      (l4450),hl      ; Set current memory pointer
  10875.         ld      hl,l7b74
  10876. l392f:
  10877.         ld      (l4452),hl      ; Set current edit pointer
  10878.         call    l3fe7 ;set column?
  10879.         call    l401f
  10880.         jp      l3d2c           ; Restore line
  10881. ;
  10882. ; Control: INSERT LINE
  10883. ;
  10884. l393b::
  10885.         call    l3950
  10886.         call    l0200
  10887.         db      cr,lf,null
  10888.         ld      hl,(l4450)      ; Get current memory pointer
  10889.         call    findnexteol             ; Find next end of line
  10890.         call    l3c1a
  10891.         jp      l3d2c           ; Restore line
  10892. ;
  10893. ;
  10894. ;
  10895. l3950:
  10896.         call    l3e40           ; Sample character
  10897.         ld      a,(l01ae)       ; Test insert line implemented
  10898.         or      a
  10899.         push    af
  10900.         call    nz,l0262        ; Yeap: insert line
  10901.         pop     af
  10902.         call    z,l4139         ; Nope
  10903.         call    l3e23           ; Find last non blank
  10904.         inc     hl              ; Skip
  10905.         ld      de,(l4452)      ; Get current edit pointer
  10906.         call    l4191           ; Find min
  10907.         ld      de,l7b74
  10908.         or      a
  10909.         sbc     hl,de           ; Subtract base
  10910. l3970:
  10911.         ex      de,hl
  10912.         ld      hl,(l4450)      ; Get current memory pointer
  10913.         add     hl,de           ; Add offset
  10914.         push    hl
  10915.         scf
  10916.         ld      bc,-2
  10917.         call    l3f18
  10918.         pop     hl
  10919.         ld      (hl),cr         ; Close line
  10920.         inc     hl
  10921.         ld      (hl),lf
  10922.         ret
  10923. ;
  10924. ; Control: CURSOR LEFT
  10925. ;
  10926. l3984:
  10927.         ld      hl,(l4452)      ; Get current edit pointer
  10928.         call    l3c02           ; move character left
  10929.         ret     c               ; Not possible
  10930. l398b:
  10931.         ld      (l4452),hl      ; Set current edit pointer
  10932.         jp      l3fe7 ;set column?
  10933. ;
  10934. ; Control: CURSOR RIGHT
  10935. ;
  10936. l3991:
  10937.         ld      hl,(l4452)      ; Get current edit pointer
  10938.         call    l3be8           ; move character right
  10939.         ret     nc              ; Out off limit
  10940.         jr      l398b           ; Save new position
  10941. ;
  10942. ; Control: LAST CURSOR POSITION
  10943. ;
  10944. l399a:
  10945.         call    l3e40           ; Sample character
  10946.         ld      hl,(l4458)      ; Get edit pointer
  10947.         call    l3bf5           ; Get previous EOL
  10948.         ld      (l4450),hl      ; Set current memory pointer
  10949.         ld      hl,(l445a)
  10950.         jp      l392f
  10951. ;
  10952. ; Control: MARK SINGLE WORD
  10953. ;
  10954. l39ac:
  10955.         call    l3a0b           ; Word right
  10956.         call    l39ea           ; Word left
  10957.         ld      hl,(l4452)      ; Get current edit pointer
  10958. l39b5:
  10959.         call    l412a           ; Find delimiter
  10960.         jr      c,l39bf         ; Yeap
  10961.         call    l3be8           ; move character right
  10962.         jr      c,l39b5         ; Still in limit
  10963. l39bf:
  10964.         ld      (l4452),hl      ; Set current edit pointer
  10965.         call    l3702           ; Mark end
  10966.         call    l39ea           ; Word left
  10967.         jp      l3726           ; Mark start
  10968. ;
  10969. ;
  10970. ;
  10971. l39cb:
  10972.         ld      hl,(l4450)      ; Get current memory pointer
  10973.         call    findprevline            ; Find previous line
  10974.         jr      c,l3a05         ; Below start
  10975.         push    hl
  10976.         call    l3e40           ; Sample character
  10977.         pop     hl
  10978.         ld      (l4450),hl      ; Set current memory pointer
  10979.         res     0,(iy+14)
  10980.         call    l401f
  10981.         call    l3d2c           ; Restore line
  10982.         call    l3e23           ; Find last non blank
  10983.         jr      l3a01
  10984. ;
  10985. ; Control: WORD LEFT
  10986. ;
  10987. l39ea:
  10988.         ld      hl,(l4452)      ; Get current edit pointer
  10989. l39ed:
  10990.         call    l3c02           ; move character left
  10991.         jr      c,l39cb         ; At beginning of line
  10992.         call    l412a           ; Find delimiter
  10993.         jr      c,l39ed         ; Yeap
  10994. l39f7:
  10995.         call    l3c02           ; move character left
  10996.         jr      c,l3a01         ; At beginning of line
  10997.         call    l412a           ; Find delimiter
  10998.         jr      nc,l39f7        ; Nope
  10999. l3a01:
  11000.         inc     hl
  11001. l3a02:
  11002.         ld      (l4452),hl      ; Set current edit pointer
  11003. l3a05:
  11004.         ld      hl,(l4452)      ; Get current edit pointer
  11005.         jp      l3fe7 ;set column?
  11006. ;
  11007. ; Control: WORD RIGHT
  11008. ;
  11009. l3a0b:
  11010.         call    l3e23           ; Find last non blank
  11011.         ld      de,(l4452)      ; Get current edit pointer
  11012.         push    de
  11013.         xor     a
  11014.         sbc     hl,de
  11015.         jr      nc,l3a19
  11016.         inc     a
  11017. l3a19:
  11018.         ld      (l7b71),a       ; Set direction flag
  11019.         pop     hl
  11020. l3a1d:
  11021.         dec     hl
  11022. l3a1e:
  11023.         call    l3be8           ; move character right
  11024.         jr      c,l3a4e         ; Still in limit
  11025. l3a23:
  11026.         ld      hl,(l4450)      ; Get current memory pointer
  11027.         call    findnexteol             ; Find next end of line
  11028.         ret     c               ; Out of text
  11029.         call    l3e40           ; Sample character
  11030.         ld      hl,(l4450)      ; Get current memory pointer
  11031.         call    findnexteol             ; Find next end of line
  11032.         ld      (l4450),hl      ; Set current memory pointer
  11033.         res     0,(iy+14)
  11034.         call    l401f
  11035.         call    l3d2c           ; Restore line
  11036.         ld      hl,l7b74
  11037.         ld      (l4452),hl      ; Init current edit pointer
  11038.         call    l412a           ; Find delimiter
  11039.         jr      c,l3a1d         ; Yeap
  11040.         jp      l3fe7 ;set column?
  11041. l3a4e:
  11042.         call    l412a           ; Find delimiter
  11043.         jr      nc,l3a1e        ; Nope
  11044. l3a53:
  11045.         call    l3be8           ; move character right
  11046.         jr      c,l3a64         ; Still in limit
  11047.         ld      a,(l7b71)       ; Get direction
  11048.         or      a
  11049.         jr      nz,l3a23
  11050.         call    l3e23           ; Find last non blank
  11051.         inc     hl              ; Skip
  11052.         jr      l3a02
  11053. l3a64:
  11054.         call    l412a           ; Find delimiter
  11055.         jr      c,l3a53         ; Yeap
  11056.         jr      l3a02
  11057. ;
  11058. ; Position to previous line
  11059. ; EXIT  Reg HL points to line
  11060. ;       Carry set if below start of text
  11061. ;
  11062. l3a6b:
  11063.         ld      hl,(l4450)      ; Get current memory pointer
  11064.         call    findprevline            ; Find previous line
  11065.         ret
  11066. ;
  11067. ; Control: TABULATE
  11068. ;
  11069. l3a72:
  11070.         call    l3a6b           ; Position to previous line
  11071.         ret     c               ; Below start of text
  11072.         ld      a,(l4471)       ; Get row
  11073.         push    af              ; Save it
  11074.         ld      hl,(l4452)      ; Get current edit pointer
  11075.         ld      (l4468),hl      ; Save it
  11076.         res     0,(iy+7)        ; Disable video
  11077.         call    l3e40           ; Sample character
  11078.         ld      hl,(l4450)      ; Get current memory pointer
  11079.         push    hl
  11080.         call    findprevline            ; Find previous line
  11081.         ld      (l4450),hl      ; Set current memory pointer
  11082.         call    l3d2c           ; Restore line
  11083.         ld      hl,l43f2
  11084.         ld      (l7b72),hl      ; Set pointer to reduced delimiters
  11085.         call    l3a0b           ; Word right
  11086.         ld      hl,l43de
  11087.         ld      (l7b72),hl      ; Reset pointer to delimiters
  11088.         pop     hl
  11089.         pop     af
  11090.         ld      (l4471),a       ; Reset row
  11091.         ld      (l4450),hl      ; Reset current memory pointer
  11092.         call    l3d2c           ; Restore line
  11093.         set     0,(iy+7)        ; Enable video
  11094.         bit     0,(iy+6)        ; Test insert
  11095.         jp      nz,l374e        ; Nope
  11096.         ld      hl,(l4452)      ; Get current edit pointer
  11097.         ld      de,(l4468)      ; Get back previous pointer
  11098.         sbc     hl,de           ; Get difference
  11099.         ret     c               ; Nothing to clear
  11100.         ret     z
  11101.         ex      de,hl           ; Get length
  11102. l3ac5:
  11103.         push    de
  11104.         call    l41eb           ; Make room
  11105.         ld      (hl),' '        ; Insert blank
  11106.         pop     de
  11107.         dec     e
  11108.         jr      nz,l3ac5
  11109.         jp      l374e
  11110. ;
  11111. ; Control: DELETE TO END OF LINE
  11112. ;
  11113. l3ad2:
  11114.         ld      hl,(l4452)      ; Get current edit pointer
  11115.         push    hl
  11116.         call    l3fc5
  11117.         pop     hl
  11118.         push    hl
  11119.         ld      de,l7b74+_LinLen-1
  11120. l3ade:
  11121.         ld      (hl),' '        ; Clear character
  11122.         call    cmp_hl_de               ; Compare HL:DE
  11123.         jr      z,l3ae8         ; Match
  11124.         inc     hl              ; Advance
  11125.         jr      l3ade
  11126. l3ae8:
  11127.         pop     hl
  11128.         jp      l4197
  11129. ;
  11130. ; Control: DELETE LINE
  11131. ;
  11132. l3aec::
  11133.         ld      hl,l7b74
  11134.         ld      (l4452),hl      ; Set current edit pointer
  11135.         call    l3fe7 ;set column?
  11136.         call    l3ad2           ; Delete to end of line
  11137.         call    l3e40           ; Sample character
  11138.         ld      hl,(l4450)      ; Get current memory pointer
  11139.         push    hl
  11140.         push    hl
  11141.         call    findnexteol             ; Find next end of line
  11142.         pop     de
  11143.         jr      c,l3b10         ; Out of text
  11144.         or      a
  11145.         sbc     hl,de           ; Fet length
  11146.         ld      c,l
  11147.         ld      b,h
  11148.         pop     hl
  11149.         jp      nz,l3b26
  11150.         ret
  11151. l3b10:
  11152.         pop     hl
  11153.         jp      l3d2c           ; Restore line
  11154. l3b14:
  11155.         call    l3e44           ; Sample character
  11156.         ld      hl,(l4450)      ; Get current memory pointer
  11157.         call    findnexteol             ; Find next end of line
  11158.         jp      c,l3d2c         ; Restore line if out of text
  11159.         dec     hl
  11160.         dec     hl
  11161.         ld      bc,2
  11162.         or      a
  11163. l3b26:
  11164.         call    l3f18
  11165.         ld      a,(l01b4)       ; Test delete line implemented
  11166.         or      a
  11167.         jr      z,l3b3c         ; Nope
  11168.         call    l0259           ; Delete line
  11169.         ld      a,(l0169)       ; Get screen lines
  11170.         dec     a
  11171.         call    l3bbc
  11172.         jp      l3d2c           ; Restore line
  11173. l3b3c:
  11174.         call    l4139
  11175.         jp      l3d2c           ; Restore line
  11176. ;
  11177. ; Control: DELETE RIGHT WORD
  11178. ;
  11179. l3b42:
  11180.         call    l3e23           ; Find last non blank
  11181.         ld      de,(l4452)      ; Get current edit pointer
  11182.         call    cmp_hl_de               ; Compare HL:DE
  11183.         ex      de,hl
  11184.         jr      c,l3b14         ; HL<DE
  11185.         ld      a,(hl)
  11186.         cp      ' '             ; Test blank
  11187.         jr      z,l3b8c
  11188.         call    l412a           ; Find delimiter
  11189.         jr      c,l3b83         ; Yeap
  11190. l3b59:
  11191.         call    l4173
  11192.         call    l412a           ; Find delimiter
  11193.         jr      c,l3b86         ; Yeap
  11194.         jr      l3b59
  11195. ;
  11196. ;
  11197. ;
  11198. l3b63:
  11199.         ld      hl,(l4450)      ; Get current memory pointer
  11200.         call    findprevline            ; Find previous line
  11201.         ret     c               ; Below start of text
  11202.         call    l37d2           ; Line up
  11203.         call    l377a           ; Line right
  11204.         jp      l3b42           ; Delete right word
  11205. ;
  11206. ; Control: DELETE RIGHT CHARACTER
  11207. ;
  11208. l3b73:
  11209.         ld      hl,(l4452)      ; Get current edit pointer
  11210.         jr      l3b83           ; Go delete
  11211. ;
  11212. ; Control: DELETE LEFT CHARACTER
  11213. ;
  11214. l3b78:
  11215.         ld      hl,(l4452)      ; Get current edit pointer
  11216.         call    l3c02           ; move character left
  11217.         jr      c,l3b63         ; Beginning of line
  11218.         ld      (l4452),hl      ; Set current edit pointer
  11219. l3b83:
  11220.         call    l4173
  11221. l3b86:
  11222.         call    l3fe7 ;set column?
  11223.         jp      l4197
  11224. l3b8c:
  11225.         call    l4173
  11226.         ld      a,(hl)
  11227.         cp      ' '             ; Test blank
  11228.         jr      z,l3b8c         ; Skip them
  11229.         jr      l3b86
  11230. ;
  11231. ;
  11232. ;
  11233. l3b96:
  11234.         call    l428f           ; Test look ahead buffer empty
  11235.         jp      nz,l37a4        ; Nope, set edit cursor
  11236.         call    l3bac
  11237.         jr      nc,l3b96
  11238.         jp      l37a4           ; Set edit cursor
  11239. ;
  11240. ;
  11241. ;
  11242. l3ba4:
  11243.         call    l3bac
  11244.         jr      nc,l3ba4
  11245.         jp      l37a4           ; Set edit cursor
  11246. ;
  11247. ; ????????????????????????????????????????????
  11248. ; EXIT  Carry set if row same as screen height
  11249. ;
  11250. l3bac:
  11251.         ld      a,(l4475)       ; Get current row
  11252.         ld      hl,l0169        ; Get screen lines
  11253.         cp      (hl)            ; Compare
  11254.         scf
  11255.         ret     z               ; Same, so exit
  11256.         inc     (iy+9)          ; Bump row
  11257.         cp      (iy+5)          ; Test aginst row
  11258.         ret     z
  11259. ;
  11260. ;
  11261. ;
  11262. l3bbc:
  11263.         ld      h,0             ; Set column
  11264.         ld      l,a             ; Get row
  11265.         push    af
  11266.         call    l02a2           ; Position cursor
  11267.         pop     af
  11268.         ld      hl,(curstartofpage)     ; Get start of screen
  11269.         ld      b,a
  11270. l3bc8:
  11271.         dec     b
  11272.         jr      z,l3bd8
  11273.         call    findnexteol             ; Find next end of line
  11274.         jr      nc,l3bc8
  11275.         call    l3cec           ; Make normal video
  11276.         call    l3c12           ; Clear line
  11277.         xor     a
  11278.         ret
  11279. l3bd8:
  11280.         call    l3c1a
  11281.         xor     a
  11282.         ret
  11283. ;
  11284. ;
  11285. ;
  11286. l3bdd:
  11287. ;gotonextchar,check eof
  11288.         inc     hl
  11289.         ld      de,(l4546)      ; Get end of text
  11290. ;
  11291. ; Compare addresses
  11292. ; ENTRY Regs HL and DE hold addresses
  11293. ; EXIT  Zero  set if HL=DE
  11294. ;       Carry set if HL<DE
  11295. ;
  11296. cmp_hl_de:
  11297.         push    hl
  11298.         or      a
  11299.         sbc     hl,de           ; Compare
  11300.         pop     hl
  11301.         ret
  11302. ;
  11303. ; move pointer right
  11304. ; ENTRY Reg HL holds pointer
  11305. ; EXIT  Carry reset if pointer ou of limit
  11306. ;
  11307. l3be8:
  11308.         inc     hl              ; Point to next
  11309.         ld      de,l7b74+_LinLen-2
  11310.         jr      cmp_hl_de               ; Compare HL:DE
  11311. ;
  11312. ; Fix to start of line
  11313. ; ENTRY Reg HL holds text pointer
  11314. ; EXIT  Reg HL decremented by 1
  11315. ;       Carry set if HL < Start_of_Text
  11316. ;
  11317. l3bee:
  11318.         dec     hl
  11319.         ld      de,(l4544)      ; Get start of text
  11320.         jr      cmp_hl_de               ; Compare HL:DE
  11321. ;
  11322. ; Find EOL of previous line
  11323. ; ENTRY Reg HL holds current pointer
  11324. ; EXIT  Reg HL points to previous end
  11325. ;
  11326. l3bf5:
  11327.         ld      a,lf
  11328. l3bf7:
  11329.         call    l3bee           ; Fix to start of line
  11330.         ret     z               ; Got it
  11331.         jr      c,l3c00         ; Here before start
  11332.         cp      (hl)            ; Find new line
  11333.         jr      nz,l3bf7        ; Nope
  11334. l3c00:
  11335.         inc     hl              ; Adjust pointer
  11336.         ret
  11337. ;
  11338. ; move pointer left
  11339. ; ENTRY Reg HL holds pointer
  11340. ; EXIT  Carry set if pointer out of limit
  11341. ;
  11342. l3c02:
  11343.         dec     hl              ; Get previous
  11344.         ld      de,l7b74        ; Init pointer
  11345.         jr      cmp_hl_de               ; Compare HL:DE
  11346. ;
  11347. ;
  11348. ;
  11349. l3c08:
  11350. ;nextline
  11351.         cp      cr              ; Test return
  11352.         ret     nz              ; Nope
  11353.         ld      a,(hl)
  11354.         call    l3bdd ;gotonextchar,check eof
  11355.         ret     nc ;eof
  11356.         jr      l3c08
  11357. ;
  11358. ; Clear line
  11359. ;
  11360. l3c12:
  11361.         ld      a,(l0168)       ; Get screen columns
  11362.         dec     a
  11363.         ld      b,a
  11364. l3c17:
  11365.         jp      l3cf9           ; Clear to end of line
  11366. ;
  11367. ;
  11368. ;
  11369. l3c1a:
  11370.         call    l3ca1
  11371.         call    l3cc0
  11372.         ld      a,(l446c) ;xscroll???
  11373.         ld      b,a
  11374.         or      a
  11375.         jr      z,l3c36
  11376. l3c27:
  11377.         ld      a,(hl)
  11378.         call    l3bdd
  11379.         jr      nc,l3c12        ; Clear line
  11380.         call    l3c08 ;nextline (hl after cr)
  11381.         cp      lf              ; Test new line
  11382.         jr      z,l3c12         ; Clear line if so
  11383.         djnz    l3c27 ;skip xscroll chars???
  11384. l3c36:
  11385.         ld      a,(l0168)       ; Get screen columns
  11386.         dec     a
  11387.         ld      b,a
  11388.         bit     0,(iy+16)
  11389.         jr      z,l3c5e
  11390. l3c41:
  11391.         call    l3ca1
  11392.         call    l3cc0
  11393.         push    hl
  11394.         call    l3e23           ; Find last non blank
  11395.         ld      de,(l4452)      ; Get current edit pointer
  11396.         call    l4191           ; Find min
  11397.         ex      de,hl           ; Change to max
  11398.         inc     hl
  11399.         ld      (l4486),hl
  11400.         ex      de,hl
  11401.         pop     hl
  11402.         call    cmp_hl_de               ; Compare HL:DE
  11403.         jr      nc,l3c89        ; Clear if HL>=DE
  11404. l3c5e:
  11405.         call    l3ca1
  11406.         call    l3cc0
  11407.         ld      de,(l4486)
  11408.         call    cmp_hl_de               ; Compare HL:DE
  11409.         jr      z,l3c89         ; Clear if same
  11410.         ld      a,(hl)
  11411.         call    l3bdd ;gotonextchar,check eof
  11412.         jr      nc,l3c17        ; Clear line
  11413.         call    l3c08 ;nextline (hl after cr)
  11414.         cp      lf              ; Test end of line
  11415.         jr      z,l3c17         ; Clear on new line
  11416.         call    l3c8b           ; Process control character
  11417.         djnz    l3c5e
  11418. l3c7f:
  11419.         ld      a,(hl)
  11420.         call    l3bdd
  11421.         jr      nc,l3c89        ; Clear line
  11422.         cp      lf              ; Test new line
  11423.         jr      nz,l3c7f
  11424. l3c89:
  11425.         jr      l3c17           ; Clear line
  11426. ;
  11427. ; Process control character
  11428. ;
  11429. l3c8b:
  11430.         cp      ' '             ; Test control character
  11431.         jr      nc,l3c96        ; Nope
  11432.         add     a,'@'           ; Make ASCII
  11433.         push    af
  11434.         call    l3c99           ; Select video
  11435.         pop     af
  11436. l3c96:
  11437.         jp      puttoconsole_a          ; Put to console ;TODO speedup
  11438. ;
  11439. ; Select video
  11440. ;
  11441. l3c99:
  11442.         ld      a,(l00e0)       ; Get video mode
  11443.         or      a
  11444.         jr      z,l3cec         ; Make normal video
  11445.         jr      l3cdf           ; Set low video
  11446. ;
  11447. ;
  11448. ;
  11449. l3ca1:
  11450.         bit     0,(iy+16)
  11451.         ret     z
  11452.         bit     0,(iy+20)       ; Test block set
  11453.         jr      nz,l3cec        ; Nope, make normal video
  11454.         ld      de,(l4464)      ; Get block start address
  11455.         call    cmp_hl_de               ; Compare HL:DE
  11456.         jr      c,l3cec         ; Make normal video
  11457.         ld      de,(l4466)      ; Get end of block pointer
  11458.         call    cmp_hl_de               ; Compare HL:DE
  11459.         jr      c,l3cdf         ; Set low video
  11460.         jr      l3cec           ; Make normal video
  11461. ;
  11462. ;
  11463. ;
  11464. l3cc0:
  11465.         bit     0,(iy+16)
  11466.         ret     nz
  11467.         bit     0,(iy+20)       ; Test block set
  11468.         jr      nz,l3cec        ; Nope, make normal video
  11469.         ld      de,(l4460)      ; Get block start pointer
  11470.         call    cmp_hl_de               ; Compare HL:DE
  11471.         jr      c,l3cec         ; Make normal video
  11472.         ld      de,(l4462)      ; Get block end pointer
  11473.         call    cmp_hl_de               ; Compare HL:DE
  11474.         jr      z,l3cec         ; Make normal video
  11475.         jr      nc,l3cec        ; Make normal video
  11476. ;
  11477. ; Set low video
  11478. ;
  11479. l3cdf:
  11480.         ld      a,(l00e0)       ; Get video mode
  11481.         or      a               ; Test enabled
  11482.         ret     z               ; Nope
  11483.         bit     0,(iy+7)        ; Test selected
  11484.         ret     z               ; Nope
  11485.         jp      setlowvideo             ; Set low video
  11486. ;
  11487. ; Set normal video
  11488. ;
  11489. l3cec:
  11490.         ld      a,(l00e0)       ; Get video mode
  11491.         or      a               ; Test enabled
  11492.         ret     nz              ; Yeap
  11493.         bit     0,(iy+7)        ; Test selected
  11494.         ret     z               ; Nope
  11495.         jp      setnormvideo            ; Set normal video
  11496. ;
  11497. ; Clear to end of line
  11498. ; ENTRY Reg B holds column position
  11499. ;
  11500. l3cf9:
  11501.         inc     b               ; Test position
  11502.         dec     b
  11503.         ret     z               ; Ignore left margin
  11504.         ld      a,(l01bc)       ; Test clear to end of line implemented
  11505.         or      a
  11506.         jp      nz,l0299        ; Yeap
  11507. l3d03:
  11508.         ld      a,' '
  11509.         call    puttoconsole_a          ; Put blanks to console
  11510.         djnz    l3d03
  11511.         ret
  11512. ;
  11513. ; Delete current line
  11514. ;
  11515. l3d0b:
  11516.         ld      a,(l01b4)       ; Test delete line implemented
  11517.         or      a
  11518.         jr      nz,l3d23        ; Yeap
  11519.         ld      (l4474),a       ; Set no change
  11520.         ld      a,(l0169)       ; Get screen lines
  11521.         dec     a
  11522.         ld      l,a             ; Set row
  11523.         ld      h,0             ; Set column
  11524.         call    l02a2           ; Position cursor
  11525.         ld      a,lf
  11526.         jp      puttoconsole_a          ; Put new line to console
  11527. l3d23:
  11528.         ld      hl,256*0+1
  11529.         call    l02a2           ; Position cursor
  11530.         jp      l0259           ; Delete line
  11531. ;
  11532. ; Control: RESTORE DELETED LINE
  11533. ;
  11534. l3d2c:
  11535.         ld      hl,(l4450)      ; Get current memory pointer
  11536.         ld      de,0
  11537.         ld      (l4464),de      ; Reset start of block pointer
  11538.         ld      (l4466),de      ; Reset end of block pointer
  11539.         ld      b,_LinLen       ; Set max length
  11540.         ld      ix,l7b74        ; Set base address
  11541.         ld      (iy+1),0        ; Clear block state
  11542. l3d44: ;;;;;;
  11543.         ld      a,(hl)
  11544.         ld      de,(l4460)      ; Get block start pointer
  11545.         call    cmp_hl_de               ; Compare HL:DE
  11546.         jr      nz,l3d56        ; Not same addresses
  11547.         ld      (l4464),ix      ; Set start of block pointer
  11548.         set     0,(iy+1)        ; Set start block
  11549. l3d56:
  11550.         ld      de,(l4462)      ; Get block end pointer
  11551.         call    cmp_hl_de               ; Compare HL:DE
  11552.         jr      nz,l3d67        ; Not same addresses
  11553.         ld      (l4466),ix      ; Set end of block pointer
  11554.         set     1,(iy+1)        ; Set end block
  11555. l3d67:
  11556.         cp      cr              ; Test end of line
  11557.         jr      nz,l3dc3        ; Nope
  11558.         ld      (ix+0),' '      ; Fill with blank
  11559.         inc     ix
  11560.         dec     b
  11561.         jr      z,l3dd9
  11562.         call    l3bdd
  11563.         jr      nc,l3d44
  11564. l3d79:
  11565.         ld      de,(l4462)      ; Get block end pointer
  11566.         call    cmp_hl_de               ; Compare HL:DE
  11567.         jr      nc,l3d8a        ; HL>= Start_Of_Block
  11568.         push    hl
  11569.         ld      hl,-1
  11570.         ld      (l4466),hl      ; Set end of block pointer
  11571.         pop     hl
  11572. l3d8a:
  11573.         ld      de,(l4460)      ; Get block start pointer
  11574.         call    cmp_hl_de               ; Compare HL:DE
  11575.         jr      nc,l3d99        ; HL>= End_Of_Block
  11576.         ld      hl,-1
  11577.         ld      (l4464),hl      ; Set start of block pointer
  11578. l3d99: ;;;;;
  11579.         ld      a,_LinLen
  11580.         sub     b               ; Calculate remaining length
  11581.         ld      (l446f),a       ; Save relative column
  11582. l3d9f:
  11583.         ld      (ix+0),' '      ; Fill with blanks
  11584.         inc     ix
  11585.         djnz    l3d9f
  11586.         ld      hl,(l4452)      ; Get current edit pointer
  11587.         call    l3fe7 ;set column?
  11588.         bit     0,(iy+14)
  11589.         set     0,(iy+14)
  11590.         jp      nz,l374e
  11591.         ld      a,(l4475)       ; Get current row
  11592.         dec     a
  11593.         cp      (iy+5)          ; Test against row
  11594.         ret     nc
  11595.         jp      l374e
  11596. l3dc3:
  11597.         cp      lf              ; Test end of line
  11598.         jr      z,l3d79         ; Yeap
  11599.         ld      (ix+0),a        ; Store character
  11600.         inc     ix
  11601.         dec     b               ; Test still room
  11602.         jr      nz,l3dd1        ; Yeap
  11603.         jr      l3dd9           ; Line too long
  11604. l3dd1:
  11605.         call    l3bdd
  11606.         jr      nc,l3d79
  11607.         jp      l3d44
  11608. l3dd9:
  11609.         call    l3e04           ; Tell error
  11610.         db      'Line too long - CR inserted'
  11611.         db      null
  11612.         call    l3f12
  11613.         ld      hl,_LinLen-2
  11614.         call    l3970
  11615.         jp      l3d2c           ; Restore line
  11616. ;
  11617. ;
  11618. ;
  11619. l3e04:
  11620.         call    l3ba4
  11621. l3e07:
  11622.         call    l3e0d           ; Set cursor
  11623.         jp      l4211
  11624. ;
  11625. ; Set cursor home
  11626. ;
  11627. l3e0d:
  11628.         ld      (iy+8),0        ; Set no change
  11629.         ld      hl,256*0+0
  11630.         call    l02a2           ; Position cursor
  11631.         call    l3c12           ; Clear line
  11632.         ld      hl,256*0+0
  11633.         call    l02a2           ; Position cursor
  11634.         jp      l3cdf           ; Set low video
  11635. ;
  11636. ; Find last non blank in current line
  11637. ; EXIT  Reg HL holds pointer to non blank
  11638. ;
  11639. l3e23:
  11640.         ld      a,' '           ; Set what we are looking for
  11641.         ld      hl,l7b74+_LinLen-1
  11642.         ld      de,l7b74-1      ; Init pointers
  11643. l3e2b:
  11644.         cp      (hl)            ; Test match
  11645.         ret     nz              ; Nope, got it
  11646.         dec     hl
  11647.         call    cmp_hl_de               ; Test beginning
  11648.         jr      nz,l3e2b        ; Nope
  11649.         ret
  11650. ;
  11651. ; Get pointer within limits
  11652. ; ENTRY Reg HL holds 1st pointer
  11653. ;       Reg BC holds 2nd pointer
  11654. ; EXIT  Reg HL unchanged if out of line
  11655. ;       Reg HL holds MIN(HL,BC) else
  11656. ;
  11657. l3e34:
  11658.         ld      de,l7b74+_LinLen
  11659.         call    cmp_hl_de               ; Compare HL:DE
  11660.         ret     nc              ; End found
  11661.         ld      d,b
  11662.         ld      e,c
  11663.         jp      l4191           ; Find min
  11664. ;
  11665. ; Poll character, insert at end of line
  11666. ;
  11667. l3e40:
  11668.         call    l3e23           ; Find last non blank
  11669.         inc     hl              ; Skip over
  11670. ;
  11671. ; Poll character, insert at current position
  11672. ; ENTRY Reg HL holds current text address
  11673. ;
  11674. l3e44:
  11675.         ld      c,l             ; Copy pointer
  11676.         ld      b,h
  11677.         ld      hl,(l4464)      ; Get start of block pointer
  11678.         call    l3e34           ; Fix it
  11679.         ld      (l4464),hl      ; Set start of block pointer
  11680.         ld      hl,(l4466)      ; Get end of block pointer
  11681.         call    l3e34           ; Fix it
  11682.         ld      (l4466),hl      ; Set end of block pointer
  11683.         ld      l,c
  11684.         ld      h,b
  11685.         inc     hl
  11686.         ld      de,l7b74
  11687.         or      a
  11688.         sbc     hl,de           ; Get relative position
  11689.         push    hl
  11690.         ld      a,(l446f)       ; Get relative column
  11691.         sub     l               ; Subtract it
  11692.         ld      c,a
  11693.         ld      b,0             ; Expand for 16 bits
  11694.         jr      nc,l3e6d
  11695.         ld      b,-1            ; Signed expansion
  11696. l3e6d:
  11697.         ld      hl,(l4450)      ; Get current memory pointer
  11698.         call    nz,l3f18
  11699.         pop     bc
  11700.         ld      ix,(l4450)      ; Get current memory pointer
  11701.         ld      hl,l7b74        ; Load base
  11702.         ld      b,c             ; Copy position
  11703.         dec     b               ; Test any
  11704.         inc     b
  11705.         jr      z,l3ea5         ; Nope
  11706. l3e80:
  11707.         ld      a,(hl)          ; Get character
  11708.         ld      de,(l4464)      ; Get start of block pointer
  11709.         call    cmp_hl_de               ; Compare HL:DE
  11710.         jr      nz,l3e8e        ; Not the same
  11711.         ld      (l4460),ix      ; Set block start pointer
  11712. l3e8e:
  11713.         ld      de,(l4466)      ; Get end of block pointer
  11714.         call    cmp_hl_de               ; Compare HL:DE
  11715.         jr      nz,l3e9b        ; Not the same
  11716.         ld      (l4462),ix      ; Set block end pointer
  11717. l3e9b:
  11718.         ld      (ix+0),a        ; Unpack character
  11719.         inc     hl
  11720.         inc     ix
  11721.         djnz    l3e80
  11722.         dec     ix
  11723. l3ea5:
  11724.         ld      a,cr
  11725.         ld      (ix+0),a        ; Set end of line
  11726.         ret
  11727. ;
  11728. ; Display characters left and check enough memory
  11729. ;
  11730. l3eab:
  11731.         ld      hl,(l4548)      ; Get top of available memory
  11732.         or      a
  11733.         sbc     hl,de           ; Test remainder
  11734.         jr      c,l3ed9         ; Nope
  11735.         ld      bc,l00fe
  11736.         sbc     hl,bc           ; Test min
  11737.         ret     nc              ; Yeap
  11738.         add     hl,bc
  11739.         push    hl
  11740.         call    l3e0d           ; Set cursor
  11741.         pop     hl
  11742.         ld      b,0
  11743.         call    l30fe           ; Tell bytes left
  11744.         call    l4211
  11745.         db      ' byte(s) left'
  11746.         db      null
  11747.         call    l3f12           ; Wait for quit
  11748.         ret
  11749. l3ed9:
  11750.         call    l3e04
  11751.         db      'ERROR: Out of space'
  11752.         db      null
  11753.         call    l3f12           ; Wait for quit
  11754.         jp      l2ebd
  11755. ;
  11756. ; Test editor function cancelled
  11757. ;
  11758. l3ef6:
  11759.         cp      a_CAN           ; Test cancel
  11760.         ret     nz              ; Nope
  11761.         call    l3e04
  11762.         db      '*** INTERRUPTED'
  11763.         db      null
  11764.         call    l3f12           ; Wait for quit
  11765.         jp      l2ebd
  11766. ;
  11767. ; Clear ahaed buffer and wait for user quit
  11768. ;
  11769. l3f12:
  11770.         call    l422b           ; Clear look ahead buffer
  11771.         jp      l2e76           ; Get ESCape
  11772. ;
  11773. ;
  11774. ;
  11775. l3f18:
  11776.         push    hl
  11777.         push    bc
  11778.         jr      nc,l3f96
  11779.         ld      de,(l4546)      ; Get end of text
  11780.         push    de
  11781.         push    de
  11782.         ex      de,hl
  11783.         or      a
  11784.         sbc     hl,de
  11785.         ex      (sp),hl
  11786.         or      a
  11787.         sbc     hl,bc
  11788.         jp      nc,l3ed9
  11789.         ld      e,l
  11790.         ld      d,h
  11791.         push    de
  11792.         call    l3eab           ; Test enough room
  11793.         pop     de
  11794.         pop     bc
  11795.         inc     bc
  11796.         pop     hl
  11797.         ld      (l4546),de      ; Set end of text
  11798.         ld      a,b
  11799. l3f3c:
  11800.         sub     HIGH _SavLen
  11801.         jr      c,l3f4d
  11802.         ld      b,a
  11803.         push    bc
  11804.         ld      bc,_SavLen
  11805.         lddr                    ; move down
  11806.         pop     bc
  11807.         call    l4232           ; Poll character from input
  11808.         jr      l3f3c
  11809. l3f4d:
  11810.         ld      a,c
  11811.         or      b
  11812.         jr      z,l3f53
  11813.         lddr
  11814. l3f53:
  11815.         pop     bc
  11816.         pop     hl
  11817.         ex      de,hl
  11818.         inc     de
  11819.         ld      hl,(l4460)      ; Get block start pointer
  11820.         call    l3f8e
  11821.         ld      (l4460),hl      ; Set block start pointer
  11822.         ld      hl,(l4462)      ; Get block end pointer
  11823.         call    l3f8e
  11824.         ld      (l4462),hl      ; Set block end pointer
  11825.         ld      hl,(curstartofpage)     ; Get start of screen
  11826.         call    l3f8e
  11827.         ld      (curstartofpage),hl     ; Set start of screen
  11828.         ld      hl,(l4450)      ; Get current memory pointer
  11829.         call    l3f8e
  11830.         ld      (l4450),hl      ; Set current memory pointer
  11831.         ld      hl,(l4454)      ; Get block pointer
  11832.         call    l3f8e
  11833.         ld      (l4454),hl      ; Set block pointer
  11834.         ld      hl,(l4458)      ; Get edit pointer
  11835.         call    l3f8e
  11836.         ld      (l4458),hl      ; Set edit pointer
  11837.         ret
  11838. ;
  11839. ;
  11840. ;
  11841. l3f8e:
  11842.         call    cmp_hl_de               ; Compare HL:DE
  11843.         ret     c
  11844.         or      a
  11845.         sbc     hl,bc
  11846.         ret
  11847. ;
  11848. ;
  11849. ;
  11850. l3f96:
  11851.         push    hl
  11852.         add     hl,bc
  11853.         push    hl
  11854.         ld      de,(l4546)      ; Get end of text
  11855.         inc     de
  11856.         ex      de,hl
  11857.         or      a
  11858.         sbc     hl,de
  11859.         ld      c,l
  11860.         ld      b,h
  11861.         pop     hl
  11862.         pop     de
  11863.         ld      a,b
  11864. l3fa7:
  11865.         sub     HIGH _SavLen
  11866.         jr      c,l3fb8
  11867.         ld      b,a
  11868.         push    bc
  11869.         ld      bc,_SavLen
  11870.         ldir                    ; move up
  11871.         pop     bc
  11872.         call    l4232           ; Poll character from input
  11873.         jr      l3fa7
  11874. l3fb8:
  11875.         ld      a,c
  11876.         or      b
  11877.         jr      z,l3fbf
  11878.         ldir
  11879.         dec     de
  11880. l3fbf:
  11881.         ld      (l4546),de      ; Set end of text
  11882.         jr      l3f53
  11883. ;
  11884. ;
  11885. ;
  11886. l3fc5:
  11887.         push    hl
  11888.         ld      de,(l4464)      ; Get start of block pointer
  11889.         call    l4191           ; Find min
  11890.         bit     0,(iy+1)        ; Test start block
  11891.         jr      z,l3fd6         ; Nope
  11892.         ld      (l4464),hl      ; Set start of block pointer
  11893. l3fd6:
  11894.         pop     hl
  11895.         bit     1,(iy+1)        ; Test end block
  11896.         ret     z               ; Nope
  11897.         ld      de,(l4466)      ; Get end of block pointer
  11898.         call    l4191           ; Find min
  11899.         ld      (l4466),hl      ; Set end of block pointer
  11900.         ret
  11901. ;
  11902. ;
  11903. ;set column?
  11904. l3fe7:
  11905.         ld      de,l7b74        ; Get base address
  11906.         ld      a,(l0168)       ; Get screen columns
  11907.         dec     a
  11908.         ld      c,a
  11909.         or      a
  11910.         sbc     hl,de
  11911.         ld      a,l
  11912.         sub     (iy+0)
  11913.         jr      c,l4012
  11914.         cp      c
  11915.         jr      c,l400e
  11916.         sub     c
  11917.         inc     a
  11918.         add     a,(iy+0)
  11919.         ld      (l446c),a ;xscroll???
  11920.         ld      a,(l0168)       ; Get screen columns
  11921.         dec     a
  11922.         dec     a
  11923.         ld      (l4470),a       ; Set column to end
  11924.         jp      l3762
  11925. l400e:
  11926.         ld      (l4470),a       ; Set column
  11927.         ret
  11928. l4012:
  11929.         add     a,(iy+0)
  11930.         ld      (l446c),a ;xscroll???
  11931.         ld      (iy+4),0        ; Clear column
  11932.         jp      l3762
  11933. ;
  11934. ;
  11935. ;
  11936. l401f:
  11937.         bit     0,(iy+7)
  11938.         ret     z
  11939.         ld      hl,(curstartofpage)     ; Get start of screen
  11940.         ld      de,(l4544)      ; Get start of text
  11941.         call    l4191           ; Find min
  11942.         ex      de,hl
  11943.         ld      (curstartofpage),hl     ; Set max for start of screen
  11944.         ld      bc,1
  11945.         ld      de,(l4450)      ; Get current memory pointer
  11946.         call    cmp_hl_de               ; Compare HL:DE
  11947.         jp      z,l40da         ; Same
  11948.         jr      c,l4086         ; HL < Current_Pointer
  11949. l4041:
  11950.         ld      de,(l4450)      ; Get current memory pointer
  11951.         call    cmp_hl_de               ; Compare HL:DE
  11952.         jr      z,l4055         ; Same
  11953.         call    findprevline            ; Find previous line
  11954.         inc     bc
  11955.         ld      a,c
  11956.         or      a
  11957.         call    z,l4232         ; Poll character from input
  11958.         jr      l4041
  11959. l4055:
  11960.         ld      (curstartofpage),hl     ; Set start of screen
  11961.         ld      (iy+5),1        ; Init row
  11962.         set     0,(iy+14)
  11963.         ld      a,b
  11964.         or      a
  11965.         jr      nz,l4083        ; Test row
  11966.         ld      a,(l01ae)       ; Test insert line implemented
  11967.         or      a
  11968.         jr      z,l4083         ; Nope
  11969.         ld      a,(l0169)       ; Get screen lines
  11970.         dec     a
  11971.         cp      c
  11972.         jr      c,l4083
  11973.         dec     c
  11974.         ld      hl,256*0+1
  11975.         call    l02a2           ; Position cursor
  11976.         dec     c
  11977.         push    af
  11978.         inc     c
  11979. l407b:
  11980.         call    l0262           ; Insert line
  11981.         dec     c
  11982.         jr      nz,l407b
  11983.         pop     af
  11984.         ret     z
  11985. l4083:
  11986.         jp      l4147           ; Reset row
  11987. l4086:
  11988.         ld      de,(l4450)      ; Get current memory pointer
  11989.         call    cmp_hl_de               ; Compare HL:DE
  11990.         jr      z,l409a         ; Same
  11991.         call    findnexteol             ; Find next end of line
  11992.         inc     bc
  11993.         ld      a,c
  11994.         or      a
  11995.         call    z,l4232         ; Poll character from input
  11996.         jr      l4086
  11997. l409a:
  11998.         ld      a,b
  11999.         or      a
  12000.         jr      nz,l40de
  12001.         ld      a,(l0169)       ; Get screen lines
  12002.         dec     a
  12003.         ld      e,a
  12004.         ld      a,c
  12005.         sub     e
  12006.         ld      d,a
  12007.         inc     d
  12008.         jr      c,l40da
  12009.         dec     d
  12010.         jr      nz,l40b3
  12011.         bit     0,(iy+21)
  12012.         jp      nz,l4103
  12013. l40b3:
  12014.         inc     d
  12015.         sub     e
  12016.         jr      nc,l40de
  12017.         ld      a,(l4475)       ; Get current row
  12018.         sub     d               ; Test row
  12019.         jr      c,l40de
  12020.         jr      z,l40de
  12021.         ld      (l4475),a       ; Set row
  12022.         ld      hl,(curstartofpage)     ; Get start of screen
  12023.         ld      b,d
  12024.         push    de
  12025. l40c7:
  12026.         call    findnexteol             ; Find next end of line
  12027.         push    hl
  12028.         call    l3d0b           ; Delete current line
  12029.         pop     hl
  12030.         djnz    l40c7
  12031.         ld      (curstartofpage),hl     ; Set start of screen
  12032.         pop     de
  12033. l40d5:
  12034.         dec     e
  12035.         ld      (iy+5),e        ; Set row
  12036.         ret
  12037. l40da:
  12038.         ld      (iy+5),c        ; Set row
  12039.         ret
  12040. l40de:
  12041.         ld      hl,(curstartofpage)     ; Get start of screen
  12042.         dec     bc
  12043.         ld      a,(l0169)       ; Get screen lines
  12044.         sub     3
  12045.         ld      e,a
  12046.         ld      a,c
  12047.         sub     e
  12048.         ld      c,a
  12049.         jr      nc,l40ee
  12050.         dec     b
  12051. l40ee:
  12052.         call    findnexteol             ; Find next end of line
  12053.         dec     bc
  12054.         ld      a,c
  12055.         or      b
  12056.         jr      nz,l40ee
  12057.         ld      (curstartofpage),hl     ; Set start of screen
  12058.         call    l4147           ; Reset row
  12059.         set     0,(iy+14)
  12060.         jp      l401f
  12061. l4103:
  12062.         call    l40d5
  12063.         ld      a,(l4475)       ; Get current row
  12064.         ld      l,a
  12065.         ld      a,(l0169)       ; Get screen lines
  12066.         cp      l
  12067.         ld      a,l
  12068.         jr      z,l4117
  12069.         dec     a
  12070.         jr      z,l4117
  12071.         ld      (l4475),a       ; Set row
  12072. l4117:
  12073.         ld      hl,(curstartofpage)     ; Get start of screen
  12074.         call    findnexteol             ; Find next end of line
  12075.         ld      (curstartofpage),hl     ; Set start of screen
  12076.         call    l3d0b           ; Delete current line
  12077.         ld      a,(l0169)       ; Get screen lines
  12078.         dec     a
  12079.         jp      l3bbc
  12080. ;
  12081. ; Find delimiter
  12082. ; ENTRY Reg HL points to current text
  12083. ; EXIT  Carry set if delimiter found
  12084. ;
  12085. l412a:
  12086.         ld      de,(l7b72)      ; Get pointer to delimiters
  12087. l412e:
  12088.         ld      a,(de)          ; Test end of list
  12089.         or      a
  12090.         ret     z               ; Yeap
  12091.         cp      (hl)            ; Compare
  12092.         jr      z,l4137         ; Got it
  12093.         inc     de
  12094.         jr      l412e
  12095. l4137:
  12096.         scf
  12097.         ret
  12098. ;
  12099. ; Delete line if no ESC sequence present
  12100. ;
  12101. l4139:
  12102.         push    af
  12103.         ld      a,(l4471)       ; Get row
  12104.         cp      (iy+9)          ; Compare
  12105.         jr      nc,l4145
  12106.         ld      (l4475),a       ; Set row
  12107. l4145:
  12108.         pop     af
  12109.         ret
  12110. ;
  12111. ; Reset row
  12112. ;
  12113. l4147:
  12114.         ld      (iy+9),1        ; Init row
  12115.         ret
  12116. ;
  12117. ; Adjust pointer for inserting characters
  12118. ; ENTRY Reg BC holds number of characters to be inserted
  12119. ;
  12120. l414c:
  12121.         ex      de,hl
  12122.         bit     0,(iy+1)        ; Test start block
  12123.         jr      z,l415f         ; Nope
  12124.         ld      hl,(l4464)      ; Get start of block pointer
  12125.         call    cmp_hl_de               ; Compare HL:DE
  12126.         jr      c,l415f         ; Start_of_block < DE
  12127.         add     hl,bc           ; Add offset
  12128.         ld      (l4464),hl      ; Set start of block pointer
  12129. l415f:
  12130.         bit     1,(iy+1)        ; Test end block
  12131.         jr      z,l4171         ; Nope
  12132.         ld      hl,(l4466)      ; Get end of block pointer
  12133.         call    cmp_hl_de               ; Compare HL:DE
  12134.         jr      c,l4171         ; End_of_block < DE
  12135.         add     hl,bc           ; Add offset
  12136.         ld      (l4466),hl      ; Set end of block pointer
  12137. l4171:
  12138.         ex      de,hl
  12139.         ret
  12140. ;
  12141. ;
  12142. ;
  12143. l4173:
  12144.         push    hl
  12145.         ld      bc,-1
  12146.         call    l414c           ; Delete one character
  12147.         ex      de,hl
  12148.         ld      hl,l7b74+_LinLen-1
  12149.         or      a
  12150.         sbc     hl,de
  12151.         jr      z,l418a         ; Same
  12152.         ld      c,l
  12153.         ld      b,h
  12154.         ld      l,e
  12155.         ld      h,d
  12156.         inc     hl
  12157.         ldir                    ; Unpack
  12158. l418a:
  12159.         ld      hl,l7b74+_LinLen-1
  12160.         ld      (hl),' '        ; Clear last entry
  12161.         pop     hl
  12162.         ret
  12163. ;
  12164. ; Get minimum of two addresses
  12165. ; ENTRY Reg HL holds 1st address
  12166. ;       Reg DE holds 2nd address
  12167. ; EXIT  Regs swapped if 1st >= 2nd
  12168. ;
  12169. l4191:
  12170.         call    cmp_hl_de               ; Compare HL:DE
  12171.         ret     c               ; HL < DE
  12172.         ex      de,hl           ; Swap
  12173.         ret
  12174. ;
  12175. ;
  12176. ;
  12177. l4197:
  12178.         call    l37a4           ; Set edit cursor
  12179.         ld      a,(l0168)       ; Get screen columns
  12180.         dec     a
  12181.         sub     (iy+4)          ; Subtract from column
  12182.         ld      hl,(l4452)      ; Get current edit pointer
  12183.         ld      b,a
  12184.         set     0,(iy+16)
  12185.         call    l3c41
  12186.         res     0,(iy+16)
  12187.         ret
  12188. ;
  12189. ; Adjust for next end of line
  12190. ; ENTRY Reg HL holds current pointer
  12191. ; EXIT  Reg HL holds pointer to next line
  12192. ;       Carry set if pointer behind end address
  12193. ;
  12194. findnexteol:
  12195.         push    bc
  12196.         ex      de,hl
  12197.         ld      hl,(l4546)      ; Get end of text
  12198.         dec     hl
  12199.         or      a
  12200.         sbc     hl,de           ; Build difference
  12201.         ld      b,h
  12202.         ld      c,l
  12203.         inc     bc
  12204.         ex      de,hl
  12205.         ld      d,h
  12206.         ld      e,l
  12207.         jr      c,l41cc         ; Out of text
  12208.         ld      a,lf
  12209.         cpir                    ; Find new line
  12210.         jp      po,l41cc
  12211.         or      a
  12212.         pop     bc
  12213.         ret
  12214. l41cc:
  12215.         scf                     ; Set out of text
  12216.         ex      de,hl
  12217.         pop     bc
  12218.         ret
  12219. ;
  12220. ; Adjust for previous end of line
  12221. ; ENTRY Reg HL holds current pointer
  12222. ; EXIT  Reg HL holds pointer to previous line
  12223. ;       Carry set if pointer below start address
  12224. ;
  12225. findprevline:
  12226.         push    bc
  12227.         ld      c,l             ; Save pointer
  12228.         ld      b,h
  12229.         ld      a,lf
  12230.         call    l3bee           ; Fix to start of line
  12231.         jr      c,l41e7         ; Below
  12232. l41da:
  12233.         call    l3bee           ; Fix to start of line
  12234.         jr      z,l41e5         ; Got start
  12235.         jr      c,l41e7         ; It's below start
  12236.         cp      (hl)            ; Find line feed
  12237.         jr      nz,l41da        ; Nope
  12238.         inc     hl
  12239. l41e5:
  12240.         pop     bc
  12241.         ret
  12242. l41e7:
  12243.         ld      h,b             ; Restore pointer
  12244.         ld      l,c
  12245.         pop     bc
  12246.         ret
  12247. ;
  12248. ; Adjust pointer for inserting one character
  12249. ;
  12250. l41eb:
  12251.         push    hl
  12252.         ld      bc,1
  12253.         call    l414c           ; Adjust pointer for inserting one character
  12254.         ld      de,l7b74+_LinLen-1
  12255.         ex      de,hl
  12256.         or      a
  12257.         sbc     hl,de           ; Get difference
  12258.         dec     hl
  12259.         ld      c,l
  12260.         ld      b,h
  12261.         ld      de,l7b74+_LinLen-2
  12262.         ld      l,e
  12263.         ld      h,d
  12264.         dec     hl
  12265.         ld      a,c
  12266.         or      b               ; Test any
  12267.         jr      z,l420c         ; Nope
  12268.         push    de
  12269.         lddr                    ; move characters
  12270.         pop     hl
  12271.         ld      (hl),' '        ; Clear character
  12272. l420c:
  12273.         pop     hl
  12274.         ret
  12275. ;
  12276. ; Position cursor and give immediate string
  12277. ; ENTRY Reg H holds column
  12278. ;       Reg L holds row
  12279. ;
  12280. l420e:
  12281.         call    l02a2           ; Position cursor
  12282. l4211:
  12283.         jp      l01fa           ; Give string
  12284. ;
  12285. ; #####################################################
  12286. ; >>> Redirected console output during edit session <<<
  12287. ; #####################################################
  12288. ;
  12289. l4214:
  12290.         pop     hl
  12291.         ex      (sp),hl
  12292.         bit     0,(iy+7)
  12293.         jr      z,l4220
  12294.         push    hl
  12295. l421e   equ     $+1
  12296.         call    a_DUMMY         ; *** REDIRECTED ***
  12297. l4220:
  12298.         ld      a,(l4543)
  12299.         sub     2
  12300.         ld      (l4543),a
  12301.         ret     nz
  12302.         jr      l423e           ; Poll character from input
  12303. ;
  12304. ; Clear look ahead buffer
  12305. ;
  12306. l422b:
  12307.         ld      hl,(l445c)      ; Get input queue pointer
  12308.         ld      (l445e),hl      ; Set for output queue pointer
  12309.         ret
  12310. ;
  12311. ; Poll character from input
  12312. ;
  12313. l4232:
  12314.         push    af
  12315.         push    bc
  12316.         push    de
  12317.         push    hl
  12318.         call    l423e           ; Poll character from input
  12319.         pop     hl
  12320.         pop     de
  12321.         pop     bc
  12322.         pop     af
  12323.         ret
  12324. ;
  12325. ; Poll character from input without register preserving
  12326. ;
  12327. l423e:
  12328.         ld      hl,(l445e)      ; Get output queue pointer
  12329.         call    l4263           ; Bump it
  12330.         ld      de,(l445c)      ; Get input queue pointer
  12331.         ex      de,hl
  12332.         sbc     hl,de           ; Test room in output queue
  12333.         ex      de,hl
  12334.         ret     z               ; Nope
  12335.         push    hl
  12336.         push    ix
  12337.         push    iy
  12338.         YIELD
  12339.         if TERM
  12340.         GETKEY_ ;call   l00a0           ; Test key pressed
  12341.         else
  12342.         GET_KEY ;call   l00a0           ; Test key pressed
  12343.         endif
  12344.         pop     iy
  12345.         pop     ix
  12346.         pop     hl
  12347.          or a
  12348.         ret     z               ; No character available
  12349.         ;call   readfromkbd             ; Read character
  12350.         ld      (hl),a          ; Store it
  12351.         ld      (l445e),hl      ; Set output queue pointer
  12352.         ret
  12353. ;
  12354. ; Bump and check ahead pointer
  12355. ; ENTRY Reg HL holds current pointer
  12356. ; EXIT  Reg HL holds position within the queue
  12357. ;
  12358. l4263:
  12359.         inc     hl              ; Bump pointer
  12360.         ld      de,l7b59+_Ahead
  12361.         or      a
  12362.         ex      de,hl
  12363.         sbc     hl,de           ; Test end of queue
  12364.         ex      de,hl
  12365.         ret     nz              ; Nope
  12366.         ld      hl,l7b59        ; Set start of queue
  12367.         ret
  12368. ;
  12369. ; Get character from console or ahead buffer
  12370. ;
  12371. l4271:
  12372.         push    hl
  12373.         push    de
  12374.         ld      de,(l445c)      ; Get input queue pointer
  12375.         ld      hl,(l445e)      ; Get output queue pointer
  12376.         or      a
  12377.         sbc     hl,de           ; Test any in buffer
  12378.         ex      de,hl
  12379.         jr      z,l4289         ; Nope, buffer is empty
  12380.         call    l4263           ; Bump queue pointer
  12381.         ld      a,(hl)          ; Get character
  12382.         ld      (l445c),hl      ; Set input queue pointer
  12383.         jr      l428c
  12384. l4289:
  12385.         call    readfromkbd             ; Read character
  12386. l428c:
  12387.         pop     de
  12388.         pop     hl
  12389.         ret
  12390. ;
  12391. ; Test look ahead buffer empty - Z set says yes
  12392. ;
  12393. l428f:
  12394.         push    hl
  12395.         push    de
  12396.         ld      de,(l445c)      ; Get input queue pointer
  12397.         ld      hl,(l445e)      ; Get output queue pointer
  12398.         or      a
  12399.         sbc     hl,de
  12400.         pop     de
  12401.         pop     hl
  12402.         ret
  12403. ;
  12404. l429e:
  12405.         dw      l7bf5           ; Base of message file
  12406. l42a0:
  12407.         db      eof
  12408.        
  12409.         if 1==0
  12410. ;default key codes
  12411. l42a1::
  12412. ; Basic movement
  12413.         db      1,0dh
  12414.         db      1,1
  12415.         db      1,0ffh
  12416.         db      1,6
  12417.         db      1,0fah
  12418.         db      1,0fbh
  12419.         db      1,1fh
  12420.         db      1,1eh
  12421.         db      1,0f5h
  12422.         db      1,0f4h
  12423.         db      1,0f8h
  12424.         db      1,0f9h
  12425. ; Extended movement
  12426.         db      1,0f6h
  12427.         db      1,0f7h
  12428.         db      1,0ffh
  12429.         db      1,0ffh
  12430.         db      1,0ffh
  12431.         db      1,0ffh
  12432.         db      1,0ffh
  12433.         db      1,0ffh
  12434.         db      1,0ffh
  12435. ; Insert and delete commands
  12436.         db      1,0e0h
  12437.         db      1,0ffh
  12438.         db      1,0ffh
  12439.         db      1,0ffh
  12440.         db      1,0ffh
  12441.         db      1,0ffh
  12442.         db      1,0ffh
  12443.         db      1,0ffh
  12444. ; Block commands
  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.         db      1,0ffh
  12452.         db      1,0ffh
  12453.         db      1,0ffh
  12454. ; More commands
  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.         db      1,0ffh
  12462.         db      1,0ffh
  12463. ;
  12464.         db      0,0ffh
  12465.         db      1,0ffh
  12466. ;
  12467.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12468.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12469.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12470.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12471.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12472.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12473.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12474.         db      0,0,0,0,0,0
  12475.         endif
  12476. l4369::
  12477. ;
  12478. ; Basic movement
  12479. ;
  12480.         db      1,'M'-'@'
  12481.         db      1,key_left;'S'-'@'
  12482.         db      1,key_left;'H'-'@'
  12483.         db      1,key_right;'D'-'@'
  12484.         db      1,'A'-'@'
  12485.         db      1,'F'-'@'
  12486.         db      1,key_up;'E'-'@'
  12487.         db      1,key_down;'X'-'@'
  12488.         db      1,'W'-'@'
  12489.         db      1,'Z'-'@'
  12490.         db      1,key_pgup;'R'-'@' ;pgup
  12491.         db      1,key_pgdown;'C'-'@' ;pgdn
  12492. ;
  12493. ; Extended movement
  12494. ;
  12495.         db      1,key_home;2,'Q'-'@','S'-'@' ; LINE LEFT (home)
  12496.         db      1,key_end;2,'Q'-'@','D'-'@' ; LINE RIGHT (end)
  12497.         db      2,'Q'-'@','E'-'@' ; BOTTOM OF SCREEN
  12498.         db      2,'Q'-'@','X'-'@' ; TOP OF SCREEN
  12499.         db      2,'Q'-'@','R'-'@' ; BEGIN OF TEXT
  12500.         db      2,'Q'-'@','C'-'@' ; END OF TEXT
  12501.         db      2,'Q'-'@','B'-'@' ;to begin of block
  12502.         db      2,'Q'-'@','K'-'@' ;to end of block
  12503.         db      2,'Q'-'@','P'-'@' ;last cursor position
  12504. ;
  12505. ; Insert and delete commands
  12506. ;
  12507.         db      1,key_ins;'V'-'@' ;insert mode on/off
  12508.         db      1,'N'-'@' ;insert line
  12509.         db      1,'Y'-'@' ;delete line
  12510.         db      2,'Q'-'@','Y'-'@' ;delete to end of line
  12511.         db      1,'T'-'@' ;delete right word
  12512.         db      1,key_del;'G'-'@'
  12513.         db      1,key_backspace;DEL
  12514.         db      1,key_backspace;0ffh
  12515. ;
  12516. ; Block commands
  12517. ;
  12518.         db      2,'K'-'@','B'-'@'
  12519.         db      2,'K'-'@','K'-'@'
  12520.         db      2,'K'-'@','T'-'@'
  12521.         db      2,'K'-'@','H'-'@'
  12522.         db      2,'K'-'@','C'-'@'
  12523.         db      2,'K'-'@','V'-'@'
  12524.         db      2,'K'-'@','Y'-'@'
  12525.         db      2,'K'-'@','R'-'@'
  12526.         db      2,'K'-'@','W'-'@'
  12527. ;
  12528. ; More commands
  12529. ;
  12530.         db 1,key_esc;db 2,'K'-'@','D'-'@'
  12531.         db      1,'I'-'@'
  12532.         db      2,'Q'-'@','I'-'@'
  12533.         db      2,'Q'-'@','L'-'@'
  12534.         db      2,'Q'-'@','F'-'@'
  12535.         db      2,'Q'-'@','A'-'@'
  12536.         db      1,'L'-'@'
  12537.         db      1,'P'-'@'
  12538.         db      0
  12539. l43de::
  12540.         db      '<>,[].*+-/$:=(){}^#'''
  12541. l43f2::
  12542.         db      ' ',null
  12543. l43f4::
  12544. ;
  12545. ; Basic movement
  12546. ;
  12547.         dw      l38e6           ; NEW LINE
  12548.         dw      l3984           ; CURSOR LEFT
  12549.         dw      l3984           ; CURSOR LEFT
  12550.         dw      l3991           ; CURSOR RIGHT
  12551.         dw      l39ea           ; WORD LEFT
  12552.         dw      l3a0b           ; WORD RIGHT
  12553.         dw      l37d2           ; LINE UP
  12554.         dw      l37ad           ; LINE DOWN
  12555.         dw      l37e0           ; SCROLL UP
  12556.         dw      l3822           ; SCROLL DOWN
  12557.         dw      l389c           ; PAGE UP
  12558.         dw      l3872           ; PAGE DOWN
  12559. ;
  12560. ; Extended movement
  12561. ;
  12562.         dw      l3771           ; LINE LEFT (home)
  12563.         dw      l377a           ; LINE RIGHT (end)
  12564.         dw      l384d           ; BOTTOM OF SCREEN
  12565.         dw      l385f           ; TOP OF SCREEN
  12566.         dw      l38bc           ; BEGIN OF TEXT
  12567.         dw      l3768           ; END OF TEXT
  12568.         dw      l373c           ; BEGIN OF BLOCK
  12569.         dw      l3745           ; END OF BLOCK
  12570.         dw      l399a           ; LAST CURSOR POSITION
  12571. ;
  12572. ; Insert and delete commands
  12573. ;
  12574.         dw      l378f           ; TOGGLE INSERT/OVERWRITE
  12575.         dw      MMSB+l393b      ; INSERT LINE
  12576.         dw      MMSB+l3aec      ; DELETE LINE
  12577.         dw      MMSB+l3ad2      ; DELETE TO END OF LINE
  12578.         dw      MMSB+l3b42      ; DELETE RIGHT WORD
  12579.         dw      MMSB+l3b73      ; DELETE RIGHT CHARACTER
  12580.         dw      MMSB+l3b78      ; DELETE LEFT CHARACTER
  12581.         dw      MMSB+l3b78      ; DELETE LEFT CHARACTER
  12582. ;
  12583. ; Block commands
  12584. ;
  12585.         dw      l3726           ; MARK BEGIN OF BLOCK
  12586.         dw      l3702           ; MARK END OF BLOCK
  12587.         dw      l39ac           ; MARK SINGLE WORD
  12588.         dw      l36f9           ; TOGGLE BLOCK DISPLAY
  12589.         dw      MMSB+l3620      ; COPY BLOCK
  12590.         dw      MMSB+l35fb      ; MOVE BLOCK
  12591.         dw      MMSB+l36a1      ; DELETE BLOCK
  12592.         dw      MMSB+l3573      ; READ BLOCK FROM FILE
  12593.         dw      l34ed           ; WRITE BLOCK TO FILE
  12594. ;
  12595. ; More commands
  12596. ;
  12597.         dw      l2b0f           ; EXIT EDITOR
  12598.         dw      MMSB+l3a72      ; TABULATE
  12599.         dw      l379b           ; TOGGLE TABULATE
  12600.         dw      MMSB+l3d2c      ; RESTORE DELETED LINE
  12601.         dw      l31f1           ; FIND STRING
  12602.         dw      l323b           ; FIND AND REPLACE STRING
  12603.         dw      l324b           ; REPEAT LAST SEARCH
  12604.         dw      MMSB+l2f02      ; CONTROL PREFIX
  12605. l4450::
  12606.         dw      0               ; Current memory pointer
  12607. l4452:
  12608.         dw      l7b74           ; Current edit pointer
  12609. l4454:
  12610.         dw      0               ; Block pointer
  12611. l4456:
  12612.         dw      l7b74
  12613. l4458:
  12614.         dw      0               ; Edit pointer
  12615. l445a:
  12616.         dw      l7b74
  12617. l445c:
  12618.         dw      l7b59           ; Input queue pointer
  12619. l445e:
  12620.         dw      l7b59           ; Output queue pointer
  12621. l4460:
  12622.         dw      0               ; Block start pointer
  12623. l4462:
  12624.         dw      0               ; Block end pointer
  12625. l4464:
  12626.         dw      2               ; Block start pointer
  12627. l4466:
  12628.         dw      2               ; Block end pointer
  12629. l4468:
  12630.         dw      0               ; Temporry edit pointer
  12631. curstartofpage:
  12632.         dw      0               ; Start of screen
  12633. ;
  12634. ; The editor status block
  12635. ;
  12636. l446c:
  12637.         db      0               ; + 0 xscroll???
  12638.         db      0               ; + 1: Block state
  12639.                                 ; xxxxxxx1: Start set)
  12640.                                 ; xxxxxx1x: End set)
  12641.         db      1               ; + 2
  12642. l446f:
  12643.         db      1               ; + 3: Relative column
  12644. l4470:
  12645.         db      0               ; + 4: Editor column
  12646. l4471:
  12647.         db      1               ; + 5: Editor row
  12648. l4472:
  12649.         db      0               ; + 6: Insert flag (Bit 0=0)
  12650.         db      1               ; + 7: Video flag (1 is reverse)
  12651. l4474:
  12652.         db      0               ; + 8: Change flag
  12653. l4475:
  12654.         db      1               ; + 9: Editor row
  12655. l4476:
  12656.         db      0               ; +10
  12657.         db      0               ; +11
  12658. l4478:
  12659.         db      0               ; +12
  12660. l4479:
  12661.         db      0               ; +13: Auto tabulate flag
  12662.         db      1               ; +14
  12663.         db      1               ; +15
  12664.         db      0               ; +16
  12665. l447d:
  12666.         db      0               ; +17: Option flags for search/replace
  12667.                                 ; 00000001: W: Whole word search
  12668.                                 ; 00000010: N: No request
  12669.                                 ; 00000100: U: Ignore case
  12670.                                 ; 00001000: G: Global search
  12671.                                 ; 00010000: B: Backwards
  12672. l447e:
  12673.         db      0               ; +18: Find (0) or replace (-1) flag
  12674. l447f:
  12675.         db      0               ; +19: Text change flag
  12676. l4480:
  12677.         db      0               ; +20: Block marker (1: Not set)
  12678.         db      0               ; +21
  12679. l4482:
  12680.         db      3               ; +22
  12681. l4483:
  12682.         db      0,0,0
  12683. l4486:
  12684.         db      0,0
  12685. l4488:
  12686.         dw      0               ; End of search pointer
  12687. l448a:
  12688.         dw      0               ; Search loop count
  12689. l448c:
  12690.         dw      0
  12691. l448e:
  12692.         dw      0
  12693. ;
  12694. ; Search buffer
  12695. ;
  12696. l4490:
  12697.         db      1eh
  12698. l4491:
  12699.         db      0
  12700. l4492:
  12701.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12702.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12703.         db      0,0,0
  12704. ;
  12705. ; Replace buffer
  12706. ;
  12707. l44b1:
  12708.         db      1eh
  12709. l44b2:
  12710.         db      0
  12711. l44b3:
  12712.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12713.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12714.         db      0,0,0
  12715. ;
  12716. ; Option buffer
  12717. ;
  12718. l44d2:
  12719.         db      0ah
  12720.         db      0,0,0,0,0,0,0,0,0,0,0,0
  12721. ;
  12722. ; Block file name
  12723. ;
  12724. l44df:
  12725.         db      0fh
  12726.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  12727. l44f1:
  12728.         db      0               ; File flag
  12729. l44f2:
  12730.         db      0               ; Rename flag (1 is rename)
  12731. l44f3:
  12732.         db      1               ; Compile flag:
  12733.                                 ; 1: Compile to memory
  12734.                                 ; 2: Compile to COM-file
  12735.                                 ; 3: Compile to CHN-file
  12736. l44f4:
  12737.         dw      l20e2           ; Start address of compiler
  12738. l44f6:
  12739.         dw      0               ; Top of available memory
  12740. l44f8:
  12741.         db      0               ; Logged disk
  12742. l44f9:
  12743.         ds      FCBlen          ; Main file
  12744. l451d:
  12745.         ds      FCBlen
  12746. l4541:
  12747.         db      0               ; Error message file flag (0 is not read)
  12748. l4542:
  12749.         db      0               ; Compile flag
  12750. l4543:
  12751.         db      0
  12752. l4544:
  12753.         dw      l7bf5           ; Start of text
  12754. l4546:
  12755.         dw      l7bf5           ; End of text
  12756. l4548:
  12757.         dw      0               ; Top of available memory
  12758. ;
  12759. ; %%%%%%%%%%%%%%%%%%%%%%
  12760. ; %%% COMPILER ENTRY %%%
  12761. ; %%%%%%%%%%%%%%%%%%%%%%
  12762. ;
  12763. COMPILE:
  12764.         ld      (l7b71),sp      ; Save stack
  12765.         ld      hl,(l4546)      ; Get end of text
  12766.         inc     hl
  12767.         ld      (MemsTop),hl    ; Save for memory top
  12768.         inc     h               ; Allow a gap of 1024 bytes
  12769.         inc     h
  12770.         inc     h
  12771.         inc     h
  12772.         ld      (COMsTop),hl    ; Save for top of .COM file
  12773.         ld      hl,(l790a)      ; Get end of code
  12774.         ld      (DataBeg),hl    ; Save for start of data
  12775.         xor     a
  12776.         ld      h,a
  12777.         ld      l,a
  12778.         ld      (l7b91),a       ; Clear ????
  12779.         ld      (l7b92),a       ; Clear ????
  12780.         ld      (l7b94),a       ; Clear ????
  12781.         ld      (l7ba2),a       ; Clear end of file
  12782.         ld      (l7ba0),a       ; Clear end on break [option U+]
  12783.         ld      (BackLevel),a   ; Clear back fix level
  12784.         ld      (IncFlg),a      ; Enable memory read
  12785.         ld      (l7b96),a       ; Clear OVERLAY number
  12786.         ld      (RRN_stat ),a   ; Clear file access
  12787.         ld      (RRN_off),hl    ; Clear record base
  12788.         ld      (l7bef),hl      ; Clear line count
  12789.         call    l718f           ; Test abort
  12790.         dec     hl
  12791.         ld      (FFCB+_rrn),hl  ; Set highest record
  12792.         ld      a,_Char+1 ;13=element of a set???
  12793.         ld      (curtype_l7b93),a       ; Set special type
  12794.         ld      a,0xff-(__Ropt+__Uopt)
  12795.         ld      (l7b9d),a       ; Set default options
  12796.         ld      a,2*DefWITH
  12797.         ld      (l7bc7),a       ; Set depth for WITH
  12798.         ld      hl,(l4544)      ; Get start of text
  12799.         ld      (l7bd7),hl      ; Init source pointer
  12800.         ld      (l7bd9),hl
  12801.         ld      ix,l79d7        ; Init start of line
  12802.         ld      (ix+0),null     ; Set line empty
  12803.         ld      hl,(l7904)      ; Get code start address
  12804.         call    ChkChn          ; Check chaining
  12805.         ld      hl,(l4548)      ; Get top of available memory
  12806.         dec     hl
  12807.         ld      (l7b77),hl      ; Save
  12808.         ld      d,h
  12809.         ld      e,l
  12810.         ld      bc,LenLab       ; Get length of internal table
  12811.         or      a
  12812.         sbc     hl,bc
  12813.         ld      (LabPtr),hl     ; Init label pointers
  12814.         ld      (PrevLabPtr),hl
  12815.         ld      (CurLab),hl
  12816.         call    ChkOvfl         ; Check enough memory
  12817.         ld      hl,l731f+LenLab-1
  12818.         lddr                    ; Unpack symbol table
  12819.         call    l45ea           ; Go compile
  12820.         ld      a,(CmpTyp)      ; Get compile flag
  12821.         dec     a               ; Test compiling to file
  12822.         jr      nz,l45e2        ; Nope
  12823.         call    FixBack         ; Fix back level
  12824.         call    writerecord_TmpBuff             ; Write record
  12825.          ld c,_close
  12826.          ld de,FFCB
  12827.          call _BDOS             ; must close output file!!!
  12828. l45e2:
  12829.         ld      (l7906),iy      ; Save new top of code
  12830.         xor     a
  12831.         jp      l72e3           ; Set special zero error
  12832. ;
  12833. ; Do the compiler task
  12834. ;
  12835. l45ea:
  12836.         call    GetLine         ; Process line
  12837.         call    FindStr         ; Find PROGRAM
  12838.         dw      l7529
  12839.         jr      nz,l460a        ; Nope
  12840.         call    l4692           ; Build dummy label
  12841.         call    l6f1b           ; Test (
  12842.         jr      nz,l4607        ; Nope
  12843. l45fc:
  12844.         call    l4692           ; Build dummy label
  12845.         call    l6f13           ; Test ,
  12846.         jr      z,l45fc         ; Yeap, get next dummy
  12847.         call    l6f6e           ; Verify )
  12848. l4607:
  12849.         call    l6f48           ; Verify ;
  12850. l460a:
  12851.         ld      a,_LD.SP
  12852.         ld      hl,0x0100;TPA
  12853.         call    StCode          ; Set LD SP,TPA
  12854.         ld      hl,l79d7        ; Get start of source line
  12855.         ld      a,(CmpTyp)      ; Get compile flag
  12856.         or      a               ; Test compile to memory
  12857.         jr      z,l4621         ; Yeap
  12858.         ld      de,l0080
  12859.         call    VarAlloc                ; Allow space for loader
  12860. l4621:
  12861.         call    StLD.HL         ; Set LD HL,L79D7
  12862.         ld      a,(l7b9d)       ; Get options
  12863.         bit     _Copt,a         ; Test $C+
  12864.         ld      d,0
  12865.         jr      z,l462e         ; Nope
  12866.         dec     d
  12867. l462e:
  12868.         push    de              ; Save flag
  12869.         ld      a,_LD.BC
  12870.         call    writebyte_a_addriy              ; Set LD BC,FLAG
  12871.         push    iy              ; Save PC
  12872.         call    writeword_hl_addriy             ; Set dummy word
  12873.         ld      hl,l0364
  12874.         call    StCALL_         ; Set CALL INIPRG
  12875.         ld      a,_LD.HL
  12876.         call    writebyte_a_addriy              ; Set LD HL,1STFREE
  12877.         push    iy              ; Save PC
  12878.         call    writeword_hl_addriy             ; Set dummy word
  12879.         ld      a,_LD.DE
  12880.         call    writebyte_a_addriy              ; Set LD DE,LASTFREE
  12881.         push    iy              ; Save PC
  12882.         call    writeword_hl_addriy             ; Set dummy word
  12883.         ld      hl,(l790a)      ; Get end of code
  12884.         call    StLD.BC         ; Set LD BC,TOPRAM
  12885.         ld      a,(CmpTyp)      ; Get compile flag
  12886.         ld      h,a
  12887.         ld      l,_LD.A
  12888.         call    writeword_hl_addriy             ; Set LD A,FLAG
  12889.         ld      hl,l04d4
  12890.         call    StCALL_         ; Set CALL RANGCHK
  12891.         call    l469e           ; Do a block
  12892.         call    l52fc
  12893.         ld      a,(ix+0)
  12894.         cp      '.'             ; Verify closing .
  12895.         call    ErrNZ
  12896.         db      _DotExp
  12897.         ld      hl,l20d4
  12898.         call    StJP_           ; Set JP HALT
  12899.         pop     hl              ; Get back PC for LASTFREE
  12900.         ld      de,(DataBeg)    ; Get start of data
  12901.         call    storeback_de_to_addrhl          ; Store back
  12902.         pop     hl              ; Get back PC for 1STFREE
  12903.         call    storeback_iy_to_addrhl          ; Store back current PC
  12904.         pop     hl              ; Get back PC for FLAG
  12905.         pop     de              ; Get FLAG
  12906.         ld      a,(l7ba0)       ; Get end on break flag [option U+]
  12907.         ld      e,a
  12908.         jp      storeback_de_to_addrhl          ; Store it back
  12909. ;
  12910. ; Build dummy label
  12911. ;
  12912. l4692:
  12913.         ld      hl,(LabPtr)     ; Get label pointer
  12914.         push    hl              ; Save it
  12915.         call    GetLabel                ; Get label
  12916.         pop     hl
  12917.         ld      (LabPtr),hl     ; Restore label pointer
  12918.         ret
  12919. ;
  12920. ; Perform a block
  12921. ;
  12922. l469e:
  12923.         ld      a,(l7bc7)       ; Get depth for WITH
  12924.         push    af
  12925.         add     a,a             ; Double it
  12926.         ld      e,a
  12927.         ld      d,0
  12928.         call    VarAlloc                ; Allocate space for it
  12929.         push    hl
  12930.         call    StJP            ; Set JP
  12931.         push    iy              ; Save PC
  12932.         push    hl
  12933.         call    writeword_hl_addriy             ; Set dummy word
  12934. l46b3:
  12935.         call    FndTabStr               ; Find statement
  12936.         db      _Byte
  12937.         dw      l7584
  12938.         call    ErrNZ           ; Must be
  12939.         db      _BEGINexp
  12940.         ld      a,(hl)          ; Get type
  12941. l46be:
  12942.         cp      _Label          ; Test LABEL
  12943.         jr      nz,l46c7        ; Nope
  12944.         call    l488e           ; Process it
  12945.         jr      l46b3
  12946. l46c7:
  12947.         cp      _Const          ; Test CONST
  12948.         jr      nz,l46d0        ; Nope
  12949.         call    l48b7           ; Process it
  12950.         jr      l46be
  12951. l46d0:
  12952.         cp      _Type           ; Test TYPE
  12953.         jr      nz,l46d9        ; Nope
  12954.         call    l4aeb           ; Process it
  12955.         jr      l46be
  12956. l46d9:
  12957.         cp      _Var            ; Test VAR
  12958.         jr      nz,l46e6        ; Nope
  12959.         call    l4b2a           ; Process it
  12960.         ld      hl,(DataBeg)    ; Get start of data
  12961.         ex      (sp),hl
  12962.         jr      l46be
  12963. l46e6:
  12964.         cp      _Overly         ; Test OVERLAY
  12965.         jp      nz,l485e
  12966.         ld      a,(CmpTyp)      ; Get compile flag
  12967.         or      a
  12968.         call    ErrZ            ; Must not be compiled to memory
  12969.         db      _OvlDirErr
  12970.         ld      hl,FFCB+Fdrv
  12971.         ld      de,l7bb2
  12972.         ld      bc,Fname
  12973.         ldir                    ; Copy name of file
  12974.         ld      hl,l7b96        ; Point to OVERLAY number
  12975.         ld      a,(hl)          ; Get current number
  12976.         inc     (hl)            ; Advance it
  12977.         ex      de,hl           ; Get pointer to extension
  12978.         ld      (hl),'0'        ; Init extension
  12979.         inc     hl
  12980.         ld      b,'0'-1         ; Init tens
  12981. l4709:
  12982.         inc     b               ; Divide by ten
  12983.         sub     10
  12984.         jr      nc,l4709
  12985.         ld      (hl),b          ; Save tens
  12986.         inc     hl
  12987.         add     a,'9'+1         ; Calculate units
  12988.         ld      (hl),a          ; Save it
  12989.         ld      hl,l1c59
  12990.         call    StCALL_         ; Set CALL OVERLAY
  12991.         ld      hl,-1
  12992.         call    writeword_hl_addriy             ; Save word
  12993.         ld      hl,l7bb2        ; Point to name
  12994.         ld      b,Fname+Fext
  12995. l4724:
  12996.         ld      a,(hl)
  12997.         call    writebyte_a_addriy              ; Store name and extension
  12998.         inc     hl
  12999.         djnz    l4724
  13000.         ld      a,(CmpTyp)      ; Get compile flag
  13001.         dec     a               ; Test compiling to file
  13002.         jr      nz,l473b        ; Nope
  13003.         call    FixBack         ; Fix back level
  13004.         xor     a
  13005.         ld      (BackLevel),a   ; Set back fix level
  13006.         call    writerecord_TmpBuff             ; Write record
  13007. l473b:
  13008.         ld      hl,(RRN_off)    ; Get record base
  13009.         push    hl
  13010.         ld      hl,(CodePC)     ; Get code pointer
  13011.         push    hl
  13012.         ld      hl,(l7bb0)      ; Get length of overlay
  13013.         push    hl
  13014.         ld      (CodePC),iy     ; Set code pointer
  13015.         ld      hl,0
  13016.         ld      (l7bb0),hl      ; Clear length of overlay
  13017.         ld      hl,-FCBlen
  13018.         add     hl,sp           ; Let some space on stack for FCB
  13019.         ld      sp,hl
  13020.         ex      de,hl
  13021.         ld      hl,FFCB
  13022.         ld      bc,FCBlen
  13023.         ldir                    ; Unpack current FCB
  13024.         ld      a,(CmpTyp)      ; Get compile flag
  13025.         dec     a               ; Test compiling to file
  13026.         jr      nz,l478c        ; Nope
  13027.         ld      hl,l7bb2
  13028.         ld      de,FFCB+Fdrv
  13029.         ld      bc,Fname+Fext
  13030.         ldir                    ; Copy overlay FCB to .COM FCB
  13031.         ex      de,hl
  13032.         ld      b,FCBlen-Fdrv-Fname-Fext
  13033. l4773:
  13034.         ld      (hl),0          ; Clear remainder of FCB
  13035.         inc     hl
  13036.         djnz    l4773
  13037.         ld      de,FFCB
  13038.         push    de
  13039.         ld      c,_delete
  13040.         call    _BDOS           ; Delete file
  13041.         pop     de
  13042.         ld      c,_make
  13043.         call    _BDOS           ; Create new one
  13044.         inc     a
  13045.         call    ErrZ            ; Must be success
  13046.         db      _NoOvl
  13047. l478c:
  13048.         xor     a
  13049.         ld      (RRN_stat ),a   ; Clear file access
  13050.         ld      (RecPtr),a      ; Clear record pointer
  13051.         ld      hl,(DataBeg)    ; Get start of data
  13052.         ld      (l7bab),hl      ; Set for overlay
  13053. l4799:
  13054.         call    FndTabStr               ; Find PROCEDURE or FUNCTION
  13055.         db      1
  13056.         dw      l75a7
  13057.         call    ErrNZ           ; Must be either
  13058.         db      _SUBexp
  13059.         ld      a,(hl)          ; Get type
  13060.         push    iy
  13061.         ld      hl,(FFCB+_rrn)  ; Get current record
  13062.         ld      (RRN_off),hl    ; Set record base
  13063.         ld      hl,(DataBeg)    ; Get start of data
  13064.         push    hl
  13065.         ld      hl,(l7bab)      ; Get address of overlay data
  13066.         push    hl
  13067.         ld      e,-1
  13068.         call    l4b3a           ; Perform PROCEDURE/FUNCTION
  13069.         ld      b,h
  13070.         ld      c,l
  13071.         pop     de              ; Get back overlay data
  13072.         ld      hl,(DataBeg)    ; Get start of data
  13073.         or      a
  13074.         sbc     hl,de           ; Test min
  13075.         add     hl,de
  13076.         jr      c,l47c6
  13077.         ex      de,hl           ; Swap addresses
  13078. l47c6:
  13079.         ld      (l7bab),hl      ; Set address of overlay data
  13080.         pop     hl
  13081.         ld      (DataBeg),hl    ; Set start of data
  13082.         pop     de
  13083.         push    bc
  13084.         push    de
  13085.         ld      a,(CmpTyp)      ; Get compile flag
  13086.         dec     a               ; Test compiling to file
  13087.         call    z,FixBack               ; Yeap, fix back level
  13088.         xor     a
  13089.         ld      (BackLevel),a   ; Reset back fix level
  13090.         pop     de
  13091.         push    de
  13092. l47dd:
  13093.          ld     a,(CmpTyp)      ; Get compile flag
  13094.          dec    a               ; Test compiling to memory
  13095.          call z,flushunfinished ;nope
  13096.         push    iy              ; Copy code pointer
  13097.         pop     hl
  13098.         or      a
  13099.         sbc     hl,de           ; Get difference
  13100.         ld      a,l
  13101.         and     RecLng-1        ; Test record boundary
  13102.         jr      z,l47ee         ; Yeap
  13103.         xor     a
  13104.         call    writebyte_a_addriy              ; Fill remainder with zeroes
  13105.         jr      l47dd
  13106. l47ee:
  13107.         add     hl,hl           ; Calculate lenght in bytes
  13108.         ld      e,h
  13109.         ld      d,0
  13110.         rl      d
  13111.         ld      hl,(l7bb0)      ; Get length of overlay
  13112.         sbc     hl,de           ; Test max
  13113.         jr      nc,l47ff
  13114.         ld      (l7bb0),de      ; Set new length
  13115. l47ff:
  13116.         pop     iy              ; Get back PC
  13117.         pop     hl
  13118.         inc     hl
  13119.         ld      (hl),e          ; Save record
  13120.         inc     hl
  13121.         ld      (hl),d
  13122.         call    FindStr         ; Find more OVERLAY
  13123.         dw      l759f
  13124.         jr      z,l4799         ; Yeap
  13125.         ld      hl,(l7bab)      ; Get address of overlay data
  13126.         ld      (DataBeg),hl    ; Set start of data
  13127.         ld      a,(CmpTyp)      ; Get compile flag
  13128.         dec     a               ; Test compiling to file
  13129.         jr      nz,l4821        ; Nope
  13130.         ld      de,FFCB
  13131.         ld      c,_close
  13132.         call    _BDOS           ; Close file
  13133. l4821:
  13134.         ld      hl,0
  13135.         add     hl,sp           ; Copy stack
  13136.         ld      de,FFCB
  13137.         ld      bc,FCBlen
  13138.         ldir                    ; Get back original .COM FCB
  13139.         ld      sp,hl
  13140.         ld      de,(l7bb0)      ; Get length of overlay
  13141.         pop     hl
  13142.         ld      (l7bb0),hl      ; Set new length
  13143.         pop     hl
  13144.         ld      (CodePC),hl     ; Set code pointer
  13145.         pop     hl
  13146.         ld      (RRN_off),hl    ; Set record base
  13147.         xor     a
  13148.         ld      (RRN_stat ),a   ; Clear file access
  13149.         ld      hl,-1
  13150.         ld      (FFCB+_rrn),hl  ; Set highest record number
  13151.         push    iy
  13152.         pop     hl
  13153.         call    ChkChn          ; Check chaining
  13154. l484e:
  13155.         ld      b,RecLng
  13156. l4850:
  13157.         xor     a
  13158.         call    writebyte_a_addriy              ; Clear record
  13159.         djnz    l4850
  13160.         dec     de
  13161.         ld      a,d             ; Test all done
  13162.         or      e
  13163.         jr      nz,l484e
  13164.         jp      l46b3
  13165. l485e:
  13166.         cp      _Begin          ; Test BEGIN
  13167.         jr      z,l486a         ; Yeap
  13168.         ld      e,0
  13169.         call    l4b3a           ; Perform PROCEDURE/FUNCTION
  13170.         jp      l46b3
  13171. l486a:
  13172.         call    l4e8a           ; Process it
  13173.         pop     de
  13174.         pop     hl
  13175.         push    de
  13176.         push    iy              ; Copy PC
  13177.         pop     de
  13178.         dec     de              ; Fix it
  13179.         dec     de
  13180.         or      a
  13181.         sbc     hl,de           ; Calculate size
  13182.         add     hl,de
  13183.         jr      z,l4880
  13184.         call    storeback_iy_to_addrhl          ; Store back PC
  13185.         jr      l4884
  13186. l4880:
  13187.         dec     hl
  13188.         call    ChkChn          ; Check chaining
  13189. l4884:
  13190.         pop     de
  13191.         pop     hl
  13192.         ld      (l7bca),hl
  13193.         pop     af
  13194.         ld      (l7bc6),a
  13195.         ret
  13196. ;
  13197. ; Process LABEL
  13198. ;
  13199. l488e:
  13200.         ld      de,256*1+0
  13201.         call    puttolabel_d_e          ; Put to table
  13202.         ld      a,(ix+0)
  13203.         call    IsItValid               ; Test valid character
  13204.         call    SampLabel               ; Build label
  13205.         ld      a,(l7b94)       ; Get ???
  13206.         call    puttolabel              ; Put to label
  13207.         ld      b,3
  13208. l48a5:
  13209.         ld      a,-1
  13210.         call    puttolabel              ; Set end
  13211.         djnz    l48a5
  13212.         call    SetLabPtr               ; Set label pointer
  13213.         call    l6f13           ; Test ,
  13214.         jr      z,l488e         ; Yeap
  13215.         jp      l6f48           ; Verify ;
  13216. ;
  13217. ; Process CONST
  13218. ;
  13219. l48b7:
  13220.         ld      hl,(LabPtr)     ; Get label pointer
  13221.         push    hl
  13222.         ld      de,256*0+0
  13223.         call    puttolabel_d_e          ; Put to table
  13224.         call    GetLabel                ; Get label
  13225.         call    l6f23           ; Test =
  13226.         jr      nz,l4901        ; Nope, must be : then
  13227.         call    GetConst                ; Get constant
  13228.         ld      a,b             ; Get type
  13229.         call    puttolabel              ; Store into table
  13230.         ld      a,b             ; Get back type
  13231.         cp      _Real           ; Test real
  13232.         jr      nz,l48e3        ; Nope
  13233.         exx
  13234.         push    hl              ; Save reals
  13235.         push    de
  13236.         push    bc
  13237.         ld      b,3             ; Set word count
  13238. l48db:
  13239.         pop     de              ; Get part of real
  13240.         call    puttolabel_d_e          ; Put to table
  13241.         djnz    l48db
  13242.         jr      l48fa
  13243. l48e3:
  13244.         cp      _String         ; Test string
  13245.         jr      nz,l48f6        ; Nope, must be integer
  13246.         ld      hl,l7a57        ; Get buffer
  13247.         ld      a,c             ; Get length
  13248.         inc     c               ; Fix it
  13249. l48ec:
  13250.         call    puttolabel              ; Put to table
  13251.         ld      a,(hl)
  13252.         inc     hl
  13253.         dec     c
  13254.         jr      nz,l48ec
  13255.         jr      l48fa
  13256. l48f6:
  13257.         ex      de,hl           ; Get integer
  13258.         call    puttolabel_d_e          ; Put to table
  13259. l48fa:
  13260.         call    SetLabPtr               ; Set label pointer
  13261.         ld      d,2
  13262.         jr      l4928
  13263. l4901:
  13264.         call    l6f40           ; Verify :
  13265.         xor     a
  13266.         call    puttolabel              ; Store zero in table
  13267.         call    puttolabel_i_y          ; Store PC to table
  13268.         ld      hl,(LabPtr)     ; Get label pointer
  13269.         push    hl
  13270.         call    puttolabel_d_e          ; Put to table
  13271.         call    SetLabPtr               ; Set label pointer
  13272.         call    l4f9b           ; Get type
  13273.         pop     hl              ; Get back label pointer
  13274.         ld      de,(l7b5a)      ; Get type table
  13275.         ld      (hl),d          ; Store into
  13276.         dec     hl
  13277.         ld      (hl),e
  13278.         call    l6f76           ; Verify =
  13279.         call    l4937           ; Assign constant
  13280.         ld      d,4
  13281. l4928:
  13282.         pop     hl              ; Get back label pointer
  13283.         ld      (hl),d          ; Put into
  13284.         call    l6f48           ; Verify ;
  13285.         call    FndTabStr               ; Find statement
  13286.         db      1
  13287.         dw      l7584
  13288.         jr      nz,l48b7        ; Nope
  13289.         ld      a,(hl)          ; Get type
  13290.         ret
  13291. ;
  13292. ; Process presetted constant
  13293. ;
  13294. l4937:
  13295.         ld      a,(l7b5c)       ; Get type
  13296.         cp      _Ptr            ; Test valid
  13297.         jr      c,l4946         ; May not be a file
  13298.         cp      _String
  13299.         jr      nc,l4946
  13300.         call    ERROR
  13301.         db      _InvFilPtr
  13302. l4946:
  13303.         cp      _Array          ; Test ARRAY constant
  13304.         jr      nz,l49a1        ; Nope
  13305.         call    l6d2a           ; Save environment
  13306.         ld      hl,(l7b60)      ; Get hi set limit
  13307.         call    l5271           ; Load name
  13308.         ld      hl,(l7b6d)      ; Get last memory address
  13309.         ld      de,(l7b6b)
  13310.         or      a
  13311.         sbc     hl,de
  13312.         inc     hl
  13313.         push    hl
  13314.         ld      hl,(l7b5e)      ; Get lo set limit
  13315.         call    l5287           ; Get name
  13316.         pop     de
  13317.         ld      a,(l7b5c)       ; Get type
  13318.         cp      _Char           ; Test character
  13319.         jr      nz,l4978
  13320.         ld      a,d             ; Test byte
  13321.         or      a
  13322.         jr      nz,l4978        ; Nope
  13323.         call    l6f1b           ; Test (
  13324.         jr      nz,l498a        ; Nope
  13325.         jr      l497b
  13326. l4978:
  13327.         call    l6f66           ; Verify (
  13328. l497b:
  13329.         push    de
  13330.         call    l4937           ; Recursive assign constant
  13331.         pop     de
  13332.         dec     de
  13333.         ld      a,d
  13334.         or      e
  13335.         jr      z,l499a
  13336.         call    l6f5e           ; Verify ,
  13337.         jr      l497b
  13338. l498a:
  13339.         push    de
  13340.         call    _GetStrC                ; Get string constant
  13341.         pop     de
  13342.         ld      a,c             ; Get length
  13343.         cp      e
  13344.         call    ErrNZ           ; Verify valid length
  13345.         db      _StrConst
  13346.         call    StConst         ; Store string
  13347.         jr      l499d
  13348. l499a:
  13349.         call    l6f6e           ; Verify )
  13350. l499d:
  13351.         call    RestEnv1                ; Get back environment
  13352.         ret
  13353. l49a1:
  13354.         cp      _Record         ; Test RECORD constant
  13355.         jr      nz,l49fa        ; Nope
  13356.         call    l6d2a           ; Save environment
  13357.         call    l6f66           ; Verify (
  13358.         ld      a,(l7b5d)
  13359.         ld      c,a
  13360.         ld      hl,(l7b62)      ; Get length of type
  13361.         push    hl
  13362.         ld      hl,0
  13363. l49b6:
  13364.         push    bc
  13365.         push    hl
  13366.         ld      b,_Ptr
  13367.         call    FndLABEL                ; Get pointer label
  13368.         call    ErrNZ           ; Should be found
  13369.         db      _Undef
  13370.         call    l5276           ; Get values and name
  13371.         pop     de
  13372.         ld      hl,(l7b58)      ; Get value
  13373.         or      a
  13374.         sbc     hl,de
  13375.         add     hl,de
  13376.         call    ErrNZ           ; Verify valid size
  13377.         db      _InvSetOrder
  13378.         ld      de,(l7b62)      ; Get length of type
  13379.         add     hl,de
  13380.         push    hl
  13381.         call    l6f40           ; Verify :
  13382.         call    l4937           ; Assign constant recursively
  13383.         pop     hl
  13384.         pop     bc
  13385.         call    l6f0f           ; Test ;
  13386.         jr      z,l49b6         ; Yeap
  13387.         call    l6f6e           ; Verify )
  13388.         pop     de
  13389.         ex      de,hl
  13390.         or      a
  13391.         sbc     hl,de
  13392. l49eb:
  13393.         ld      a,h             ; Test zero
  13394.         or      l
  13395.         jr      z,l49f6         ; Yeap
  13396.         xor     a
  13397.         call    writebyte_a_addriy              ; Fill zeroes
  13398.         dec     hl
  13399.         jr      l49eb
  13400. l49f6:
  13401.         call    RestEnv1                ; Get back environment
  13402.         ret
  13403. l49fa:
  13404.         cp      _Set            ; Test SET constant
  13405.         jr      nz,l4a7a        ; Nope
  13406.         call    l6d2a           ; Save environment
  13407.         ld      hl,(l7b62)      ; Get length of type
  13408.         ld      (l7b6f),hl
  13409.         ld      hl,(l7b5e)      ; Get lo set limit
  13410.         call    l5287           ; Get name
  13411.         call    l6f30           ; Verify [
  13412.         ld      (l7ba9),ix      ; Save line pointer
  13413.         call    l0581           ; Initialize a set on stack
  13414.         ld      ix,(l7ba9)      ; Get back line pointer
  13415.         call    l6ef7           ; Test ]
  13416.         jr      z,l4a4b         ; Yeap
  13417. l4a20:
  13418.         call    l4aca
  13419.         push    hl
  13420.         call    FindStr         ; Find ..
  13421.         dw      l7580
  13422.         jr      nz,l4a37        ; Nope
  13423.         call    l4aca
  13424.         ld      (l7ba9),ix      ; Save source pointer
  13425.         call    l059b           ; Init a contiguous set value
  13426.         jr      l4a3f
  13427. l4a37:
  13428.         pop     hl
  13429.         ld      (l7ba9),ix      ; Save source pointer
  13430.         call    l0591           ; Init one set element
  13431. l4a3f:
  13432.         ld      ix,(l7ba9)      ; Get back source pointer
  13433.         call    l6f13           ; Test ,
  13434.         jr      z,l4a20         ; Yeap
  13435.         call    l6f38           ; Verify ]
  13436. l4a4b:
  13437.         ld      hl,l7a57
  13438.         ld      bc,set.len
  13439.         ld      (l7ba9),ix      ; Save source pointer
  13440.         call    l0612           ; Assign set variable
  13441.         ld      ix,(l7ba9)      ; Get back source pointer
  13442.         ld      hl,l7a57
  13443.         ld      a,(l7b5e)       ; Get lo set limit
  13444.         rra                     ; Divide by 8
  13445.         rra
  13446.         rra
  13447.         and     set.len-1       ; Get modulo
  13448.         ld      e,a
  13449.         ld      d,0
  13450.         add     hl,de           ; Build pointer
  13451.         ld      a,(l7b6f)       ; Get length
  13452.         ld      b,a
  13453. l4a6f:
  13454.         ld      a,(hl)          ; Get bytes
  13455.         call    writebyte_a_addriy              ; Store them
  13456.         inc     hl
  13457.         djnz    l4a6f
  13458.         call    RestEnv1                ; Get back environment
  13459.         ret
  13460. l4a7a:
  13461.         cp      _String         ; Test STRING constant
  13462.         jr      nz,l4a99        ; Nope
  13463.         call    _GetStrC                ; Get string constant
  13464.         ld      a,(l7b62)       ; Get length of string
  13465.         dec     a
  13466.         sub     c
  13467.         ld      b,a
  13468.         jr      nc,l4a8d
  13469.         add     a,c
  13470.         ld      c,a             ; Set length
  13471.         ld      b,0
  13472. l4a8d:
  13473.         call    StLen           ; Put string
  13474.         inc     b
  13475. l4a91:
  13476.         dec     b
  13477.         ret     z
  13478.         xor     a
  13479.         call    writebyte_a_addriy              ; Fill zeroes
  13480.         jr      l4a91
  13481. l4a99:
  13482.         cp      _Real           ; Test REAL constant
  13483.         jr      nz,l4abc        ; Nope
  13484.         call    _GetConst               ; Get constant
  13485.         ld      a,b             ; Get type
  13486.         cp      _Real           ; Test real
  13487.         jr      z,l4aaf         ; Yeap
  13488.         cp      _Integ          ; Test integer
  13489.         call    ErrNZ           ; Should be
  13490.         db      _IntRealCexp
  13491.         call    l1008           ; Convert to real
  13492.         exx
  13493. l4aaf:
  13494.         exx
  13495.         push    bc
  13496.         push    de
  13497.         push    hl
  13498.         ld      b,Real.Len/2    ; Set word count
  13499. l4ab5:
  13500.         pop     hl
  13501.         call    writeword_hl_addriy             ; Save real number
  13502.         djnz    l4ab5
  13503.         ret
  13504. l4abc:
  13505.         call    l4aca
  13506.         ld      a,(l7b62)       ; Get length of type
  13507.         dec     a
  13508.         ld      a,l
  13509.         jp      z,writebyte_a_addriy            ; Set byte
  13510.         jp      writeword_hl_addriy             ; Or set word
  13511. ;
  13512. ;
  13513. ;
  13514. l4aca:
  13515.         call    _GetConst               ; Get constant
  13516.         ld      a,(l7b5c)       ; Get type
  13517.         cp      b               ; Verify same types
  13518.         call    ErrNZ
  13519.         db      _InvType
  13520.         ld      de,(l7b5e)      ; Get lo set limit
  13521.         call    l728d           ; Compare
  13522.         jr      c,l4ae7         ; Out of range
  13523.         ld      de,(l7b60)      ; Get hi set limit
  13524.         call    l728d           ; Compare
  13525.         ret     c
  13526.         ret     z
  13527. l4ae7:
  13528.         call    ERROR
  13529.         db      _ConstRange
  13530. ;
  13531. ; Process TYPE
  13532. ;
  13533. l4aeb:
  13534.         ld      hl,(LabPtr)     ; Get label pointer
  13535.         push    hl
  13536. l4aef:
  13537.         ld      hl,(LabPtr)     ; Get label pointer
  13538.         push    hl
  13539.         ld      de,0
  13540.         call    puttolabel_d_e          ; Put to table
  13541.         call    GetLabel                ; Get label
  13542.         ld      hl,(LabPtr)     ; Get label pointer
  13543.         push    hl
  13544.         call    puttolabel_d_e          ; Put to table
  13545.         call    SetLabPtr               ; Set label pointer
  13546.         call    l6f76           ; Verify =
  13547.         call    l4f9b           ; Get type
  13548.         pop     hl
  13549.         ld      de,(l7b5a)      ; Get type table
  13550.         ld      (hl),d          ; Store into
  13551.         dec     hl
  13552.         ld      (hl),e
  13553.         pop     hl
  13554.         ld      (hl),3
  13555.         call    l6f48           ; Verify ;
  13556.         call    FndTabStr               ; Find statement
  13557.         db      _Byte
  13558.         dw      l7584
  13559.         jr      nz,l4aef        ; Nope
  13560.         ld      a,(hl)          ; Fetch type
  13561.         pop     hl
  13562.         push    af
  13563.         call    l5295
  13564.         pop     af
  13565.         ret
  13566. ;
  13567. ; Process VAR
  13568. ;
  13569. l4b2a:
  13570.         call    l4f35
  13571.         call    l6f48           ; Verify ;
  13572.         call    FndTabStr               ; Find statement
  13573.         db      _Byte
  13574.         dw      l7584
  13575.         jr      nz,l4b2a        ; Nope
  13576.         ld      a,(hl)          ; Fetch type
  13577.         ret
  13578. ;
  13579. ; Perform PROCEDURE/FUNCTION
  13580. ;
  13581. ; Accu holds PROCEDURE or FUNCTION
  13582. ; Reg E holds overlay flag (-1)
  13583. ;
  13584. l4b3a:
  13585.         ld      b,a
  13586.         ld      c,0
  13587.         sub     _Proc           ; Get type
  13588.         ld      (l7b97),a       ; 0 is PROCEDURE
  13589.         ld      a,e             ; Get overlay
  13590.         ld      (l7b99),a       ; 0 is normal
  13591.         ld      a,(l7b9d)       ; Get options
  13592.         ld      (l7b9e),a       ; Set local options
  13593.         push    bc
  13594.         call    l6ddb
  13595.         jp      z,l4c61
  13596.         pop     de
  13597.         call    puttolabel_d_e          ; Put to table
  13598.         call    GetLabel                ; Get label
  13599.         ld      hl,(CurLab)     ; Get current label pointer
  13600.         push    hl
  13601.         ld      hl,(PrevLabPtr) ; Get previous label pointer
  13602.         ld      (CurLab),hl
  13603.         ld      hl,(LabPtr)     ; Get label pointer
  13604.         push    hl
  13605.         call    puttolabel_d_e          ; Put to table
  13606.         call    puttolabel_d_e          ; Multiple
  13607.         call    puttolabel_d_e
  13608.         call    puttolabel_d_e
  13609.         ld      de,(RRN_off)    ; Get record base
  13610.         call    puttolabel_d_e          ; Put to table
  13611.         ld      de,0
  13612.         call    puttolabel_d_e          ; Put to table
  13613.         call    l6f1b           ; Test (
  13614.         ld      b,0             ; Clear parameter count
  13615.         jr      nz,l4bda        ; Nope
  13616. l4b88:
  13617.         push    bc
  13618.         ld      hl,(LabPtr)     ; Get label pointer
  13619.         push    hl
  13620.         call    puttolabel_d_e          ; Put to table
  13621.         call    puttolabel_d_e          ; Twice
  13622.         call    FindStr         ; Find VAR
  13623.         dw      l7595
  13624.         ld      bc,0
  13625.         jr      nz,l4b9e        ; Nope
  13626.         dec     c               ; Indicate VAR
  13627. l4b9e:
  13628.         push    bc
  13629.         call    GetLabel                ; Get label
  13630.         pop     bc
  13631.         inc     b               ; Count parameters
  13632.         call    l6f13           ; Test ,
  13633.         jr      z,l4b9e         ; Yeap
  13634.         push    bc
  13635.         call    l6f0b           ; Test :
  13636.         jr      nz,l4bb8        ; Nope
  13637.         ld      a,c
  13638.         ld      (l7b8f),a       ; Save state
  13639.         call    l4f18           ; Get variable
  13640.         jr      l4bc3
  13641. l4bb8:
  13642.         inc     c               ; Verify not VAR
  13643.         call    ErrNZ
  13644.         db      _SemiExp
  13645.         ld      hl,l750b+7
  13646.         ld      (l7b5a),hl      ; Init type table
  13647. l4bc3:
  13648.         pop     bc
  13649.         pop     hl
  13650.         ld      (hl),b
  13651.         dec     hl
  13652.         ld      (hl),c
  13653.         ld      de,(l7b5a)      ; Get type table
  13654.         dec     hl
  13655.         ld      (hl),d          ; Store into
  13656.         dec     hl
  13657.         ld      (hl),e
  13658.         pop     bc
  13659.         inc     b
  13660.         call    l6f0f           ; Test ;
  13661.         jr      z,l4b88         ; Yeap
  13662.         call    l6f6e           ; Verify )
  13663. l4bda:
  13664.         push    bc
  13665.         ld      a,(l7b97)
  13666.         or      a               ; Test PROCEDURE
  13667.         jr      z,l4c07         ; Yeap
  13668.         call    l6f40           ; Verify :
  13669.         xor     a
  13670.         ld      (l7b8f),a
  13671.         call    l4f18           ; Get variable
  13672.         ld      a,(l7b5c)       ; Get type
  13673.         cp      _String         ; Test range
  13674.         jr      nc,l4bf8
  13675.         cp      _Ptr            ; Should be pointer
  13676.         call    ErrNZ
  13677.         db      _InvResult
  13678. l4bf8:
  13679.         pop     bc
  13680.         pop     hl
  13681.         push    hl
  13682.         push    bc
  13683.         ld      de,-4
  13684.         add     hl,de           ; Fix pointer
  13685.         ld      de,(l7b5a)      ; Get type table
  13686.         ld      (hl),d          ; Store into
  13687.         dec     hl
  13688.         ld      (hl),e
  13689. l4c07:
  13690.         pop     bc
  13691.         pop     de
  13692.         pop     hl
  13693.         ld      (CurLab),hl     ; Restore current label pointer
  13694.         push    de
  13695.         push    bc
  13696.         call    SetLabPtr               ; Set label pointer
  13697.         call    l6f48           ; Verify ;
  13698.         ld      a,(l7b99)
  13699.         or      a               ; Test overlay
  13700.         jr      nz,l4c44        ; Yeap
  13701.         call    FindStr         ; Find FORWARD
  13702.         dw      l7533
  13703.         jr      nz,l4c2c        ; Nope
  13704.         push    iy              ; Copy PC
  13705.         pop     de
  13706.         call    StJP_           ; Set JP <addr>
  13707.         ld      a,-1
  13708.         jr      l4c38
  13709. l4c2c:
  13710.         call    FindStr         ; Find EXTERNAL
  13711.         dw      l753a
  13712.         jr      nz,l4c44        ; Nope
  13713.         call    _GetIntC                ; Get integer constant
  13714.         ex      de,hl
  13715.         xor     a
  13716. l4c38:
  13717.         pop     bc
  13718.         pop     hl
  13719.         ld      (hl),a          ; Store values
  13720.         dec     hl
  13721.         ld      (hl),b
  13722.         dec     hl
  13723.         ld      (hl),d          ; Set address
  13724.         dec     hl
  13725.         ld      (hl),e
  13726.         jp      l6f48           ; Verify ;
  13727. l4c44:
  13728.         pop     bc
  13729.         pop     hl
  13730.         push    hl
  13731.         ld      (hl),0          ; Set values
  13732.         dec     hl
  13733.         ld      (hl),b
  13734.         dec     hl
  13735.         push    iy              ; Copy PC
  13736.         pop     de
  13737.         ld      a,(l7b99)
  13738.         or      a               ; Test overlay
  13739.         jr      z,l4c5b         ; Nope
  13740.         ex      de,hl
  13741.         ld      bc,-16
  13742.         add     hl,bc           ; Fix value
  13743.         ex      de,hl
  13744. l4c5b:
  13745.         ld      (hl),d          ; Save address
  13746.         dec     hl
  13747.         ld      (hl),e
  13748.         pop     hl
  13749.         jr      l4c76
  13750. l4c61:
  13751.         ld      a,(hl)
  13752.         or      a
  13753.         call    ErrZ            ; Verify label not found
  13754.         db      _DoubleLab
  13755.         ld      a,(l7b99)
  13756.         or      a               ; Test overlay (0 is not)
  13757.         call    ErrNZ           ; Verify not FORWARD overlay
  13758.         db      _OvlFORW
  13759.         call    SetLine         ; Set new pointer
  13760.         pop     de
  13761.         call    l6f48           ; Verify ;
  13762. l4c76:
  13763.         ex      de,hl
  13764.         ld      a,(l7b9d)       ; Get option
  13765.         ld      hl,(DataBeg)    ; Get start of data
  13766.         bit     _Aopt,a         ; Test $A+ - absolute code for recursion
  13767.         jr      z,l4c84         ; Yeap
  13768.         ld      hl,0
  13769. l4c84:
  13770.         ld      (l7b83),hl
  13771.         ld      hl,(CurLab)     ; Get current label pointer
  13772.         push    hl
  13773.         ld      hl,(LabPtr)     ; Get label pointer
  13774.         ld      (CurLab),hl     ; Into current
  13775.         push    hl
  13776.         ex      de,hl
  13777.         ld      a,(hl)
  13778.         ld      (hl),0
  13779.         dec     hl
  13780.         ld      b,(hl)
  13781.         dec     hl
  13782.         ld      d,(hl)
  13783.         dec     hl
  13784.         ld      e,(hl)
  13785.         dec     hl
  13786.         or      a
  13787.         jr      z,l4ca7
  13788.         push    hl
  13789.         ex      de,hl
  13790.         inc     hl
  13791.         call    storeback_iy_to_addrhl          ; Store back PC
  13792.         pop     hl
  13793. l4ca7:
  13794.         ld      a,(l7b97)
  13795.         or      a               ; Test PROCEDURE
  13796.         jr      z,l4cd2         ; Yeap
  13797.         ld      d,(hl)
  13798.         dec     hl
  13799.         ld      e,(hl)
  13800.         dec     hl
  13801.         push    hl
  13802.         ex      de,hl
  13803.         call    l5287           ; Get name
  13804.         ld      a,(l7b5c)       ; Get type
  13805.         ld      (l7b87),a
  13806.         ld      hl,(l7b62)      ; Get length of type
  13807.         ld      a,l
  13808.         ld      (l7b88),a       ; save lo
  13809.         ex      de,hl
  13810.         call    VarAlloc                ; Allocate space
  13811.         ld      (l7b89),hl
  13812.         ex      de,hl
  13813.         pop     hl
  13814.         ld      (hl),d
  13815.         dec     hl
  13816.         ld      (hl),e
  13817.         dec     hl
  13818.         jr      l4cd6
  13819. l4cd2:
  13820.         ld      de,-4
  13821.         add     hl,de
  13822. l4cd6:
  13823.         ld      de,-4
  13824.         add     hl,de
  13825.         push    hl
  13826.         ld      c,0
  13827.         ld      a,b
  13828.         or      a
  13829.         jr      z,l4d2b
  13830. l4ce1:
  13831.         ld      a,(hl)
  13832.         add     a,c
  13833.         ld      c,a
  13834.         push    bc
  13835.         ld      b,(hl)
  13836.         dec     hl
  13837.         ld      a,(hl)
  13838.         ld      (l7b8f),a
  13839.         dec     hl
  13840.         ld      d,(hl)          ; Get type table
  13841.         dec     hl
  13842.         ld      e,(hl)
  13843.         dec     hl
  13844.         push    hl
  13845.         ex      de,hl
  13846.         ld      (l7b5a),hl      ; Save type table
  13847.         call    l5287           ; Get name
  13848.         ld      hl,(LabPtr)     ; Get label pointer
  13849.         ex      (sp),hl
  13850.         push    bc
  13851. l4cfd:
  13852.         push    bc
  13853.         ld      de,4*256+0
  13854.         call    puttolabel_d_e          ; Put to table
  13855. l4d04:
  13856.         ld      a,(hl)
  13857.         call    puttolabel              ; Store into table
  13858.         bit     _MB,(hl)        ; Test end of table
  13859.         dec     hl
  13860.         jr      z,l4d04         ; Nope
  13861.         push    hl
  13862.         call    puttolabel              ; Store last byte into table
  13863.         call    puttolabel_d_e          ; Put to table
  13864.         call    puttolabel_d_e
  13865.         call    SetLabPtr               ; Set label pointer
  13866.         pop     hl
  13867.         pop     bc
  13868.         djnz    l4cfd
  13869.         pop     bc
  13870.         ex      (sp),hl
  13871.         xor     a
  13872.         ld      (l7b90),a
  13873.         call    l4f52
  13874.         pop     hl
  13875.         pop     bc
  13876.         djnz    l4ce1
  13877. l4d2b:
  13878.         ld      b,c
  13879.         push    bc
  13880.         ld      hl,(LabPtr)     ; Get label pointer
  13881.         push    hl
  13882.         ld      hl,(l7b83)
  13883.         push    hl
  13884.         ld      hl,(l7b89)
  13885.         push    hl
  13886.         ld      a,(l7b87)
  13887.         push    af
  13888.         ld      a,(l7b88)
  13889.         push    af
  13890.         ld      a,(l7b97)       ; Get PROCEDURE/FUNCTION flag
  13891.         push    af              ; Save it
  13892.         ld      hl,l7b94        ; Point to ???
  13893.         inc     (hl)
  13894.         call    l469e           ; Perform a block
  13895.         pop     af
  13896.         ld      (l7b97),a       ; Reset flag
  13897.         pop     af
  13898.         ld      (l7b88),a
  13899.         pop     af
  13900.         ld      (l7b87),a
  13901.         pop     hl
  13902.         ld      (l7b89),hl
  13903.         pop     hl
  13904.         ld      (l7b83),hl
  13905.         ld      (l7b85),de
  13906.         ld      a,h
  13907.         or      l
  13908.         jr      z,l4d79
  13909.         sbc     hl,de
  13910.         jr      z,l4d79
  13911.         call    StLD.BC         ; Set LD BC,val16
  13912.         ex      de,hl
  13913.         call    StLD.HL         ; Set LD HL,val16
  13914.         ld      hl,l0508        ; Set recursion routine
  13915.         call    StCALL_         ; Set CALL RECUR
  13916. l4d79:
  13917.         pop     hl
  13918.         pop     bc
  13919.         inc     b
  13920.         dec     b
  13921.         jp      z,l4df3
  13922.         call    StImm           ; Set POP IY
  13923.         db      a_L1
  13924. s_I1:
  13925.         POP     IY
  13926. a_L1    equ     $-s_I1
  13927. l4d86:
  13928.         push    bc
  13929.         inc     hl
  13930.         ld      e,(hl)
  13931.         inc     hl
  13932.         ld      d,(hl)
  13933.         add     hl,de
  13934.         push    hl
  13935.         dec     hl
  13936.         dec     hl
  13937. l4d8f:
  13938.         bit     _MB,(hl)        ; Test end of string
  13939.         dec     hl
  13940.         jr      z,l4d8f         ; Nope
  13941.         call    l5276           ; Get values and name
  13942.         ld      a,(Envir1)
  13943.         or      a
  13944.         jr      nz,l4dd4
  13945.         ld      a,(l7b5c)       ; Get type
  13946.         cp      _Set
  13947.         jr      c,l4dbd
  13948.         jr      z,l4de6
  13949.         cp      _Ptr
  13950.         jr      z,l4de3
  13951.         cp      _String
  13952.         jr      c,l4dbd
  13953.         jr      z,l4de6
  13954.         cp      _Integ
  13955.         jr      nc,l4de3
  13956.         call    StImm           ; Set POP sequence
  13957.         db      a_L2
  13958. s_I2:
  13959.         POP     HL
  13960.         POP     DE
  13961.         POP     BC
  13962. a_L2    equ     $-s_I2
  13963.         jr      l4de6
  13964. l4dbd:
  13965.         call    StPOP           ; Set POP HL
  13966.         ld      hl,(l7b58)      ; Get value
  13967.         call    StLD.DE         ; Set LD DE,val16
  13968.         ld      hl,(l7b62)      ; Get length of type
  13969.         call    StLD.BC         ; Set LD BC,val16
  13970.         call    StImm           ; Set LDIR
  13971.         db      a_L3
  13972. s_I3:
  13973.         LDIR
  13974. a_L3    equ     $-s_I3
  13975.         jr      l4de9
  13976. l4dd4:
  13977.         xor     a
  13978.         ld      (Envir1),a
  13979.         ld      a,_Ptr
  13980.         ld      (l7b5c),a       ; Set POINTER
  13981.         ld      hl,2
  13982.         ld      (l7b62),hl      ; Set length of pointer type
  13983. l4de3:
  13984.         call    StPOP           ; Set POP HL
  13985. l4de6:
  13986.         call    l661b
  13987. l4de9:
  13988.         pop     hl
  13989.         pop     bc
  13990.         djnz    l4d86
  13991.         call    StImm           ; Set PUSH IY
  13992.         db      a_L4
  13993. s_I4:
  13994.         PUSH    IY
  13995. a_L4    equ     $-s_I4
  13996. l4df3:
  13997.         call    l52fc
  13998.         ld      hl,l7b94        ; Point to ???
  13999.         dec     (hl)
  14000.         ld      a,(l7b97)
  14001.         or      a               ; Test PROCEDURE
  14002.         jr      z,l4e46         ; Yeap
  14003.         ld      hl,(l7b89)
  14004.         ld      a,(l7b87)
  14005.         cp      _String
  14006.         jr      nz,l4e24
  14007.         ld      b,a
  14008.         call    StImm           ; Set POP IY
  14009.         db      a_L5
  14010. s_I5:
  14011.         POP     IY
  14012. a_L5    equ     $-s_I5
  14013.         ld      a,_LD.HL
  14014.         call    StCode          ; Set LD HL,val16
  14015.         ld      hl,l053a
  14016.         call    StCALL_         ; move string to stack
  14017.         call    StImm
  14018.         db      a_L6
  14019. s_I6:
  14020.         PUSH    IY
  14021. a_L6    equ     $-s_I6
  14022.         jr      l4e46
  14023. l4e24:
  14024.         cp      _Real
  14025.         jr      nz,l4e35
  14026.         ld      a,_LD.HL
  14027.         call    StCode          ; Set LD HL,val16
  14028.         ld      hl,l052c
  14029.         call    StCALL_         ; Set load real
  14030.         jr      l4e46
  14031. l4e35:
  14032.         ld      a,_LD_a_HL
  14033.         call    StCode          ; Set LD HL,(adr16)
  14034.         ld      a,(l7b88)
  14035.         dec     a
  14036.         jr      nz,l4e46
  14037.         call    StImm           ; Set LD H,0
  14038.         db      a_L7
  14039. s_I7:
  14040.         LD      H,0
  14041. a_L7    equ     $-s_I7
  14042. l4e46:
  14043.         ld      hl,(l7b83)
  14044.         ld      a,h
  14045.         or      l
  14046.         jr      z,l4e74
  14047.         ld      de,(l7b85)
  14048.         sbc     hl,de
  14049.         jr      z,l4e74
  14050.         ld      a,(l7b97)
  14051.         or      a               ; Test PROCEDURE
  14052.         jr      z,l4e65         ; Yeap
  14053.         ld      a,(l7b87)
  14054.         cp      _String
  14055.         ld      a,_EXX
  14056.         call    nz,writebyte_a_addriy   ; Set EXX
  14057. l4e65:
  14058.         call    StLD.BC         ; Set LD BC,val16
  14059.         ex      de,hl
  14060.         call    StLD.DE         ; Set LD DE,val16
  14061.         ld      hl,l0522
  14062.         call    StJP_           ; Set end of recursive routine
  14063.         jr      l4e79
  14064. l4e74:
  14065.         call    StImm           ; Set RET
  14066.         db      a_L8
  14067. s_I8:
  14068.         RET
  14069. a_L8    equ     $-s_I8
  14070. l4e79:
  14071.         call    l6f48           ; Verify ;
  14072.         pop     de
  14073.         pop     hl
  14074.         ld      (LabPtr),hl     ; Set label pointers
  14075.         ld      (PrevLabPtr),hl
  14076.         pop     hl
  14077.         ld      (CurLab),hl     ; Restore current label pointer
  14078.         ex      de,hl
  14079.         ret
  14080. ;
  14081. ; Process BEGIN
  14082. ;
  14083. l4e8a:
  14084.         ld      hl,(LabPtr)     ; Get label pointer
  14085. l4e8d:
  14086.         ld      de,(CurLab)     ; Get current label pointer
  14087.         or      a
  14088.         sbc     hl,de
  14089.         add     hl,de
  14090.         ret     z               ; End on level 0
  14091.         inc     hl
  14092.         ld      e,(hl)
  14093.         inc     hl
  14094.         ld      d,(hl)
  14095.         add     hl,de
  14096.         ld      a,(hl)
  14097.         cp      6 ;_TxtF???
  14098.         jr      z,l4ea4
  14099.         cp      5 ;_RecF???
  14100.         jr      nz,l4e8d
  14101. l4ea4:
  14102.         push    hl
  14103.         dec     hl
  14104.         dec     hl
  14105. l4ea7:
  14106.         bit     _MB,(hl)        ; Find end of string
  14107.         dec     hl
  14108.         jr      z,l4ea7
  14109.         ld      a,(hl)          ; Get type
  14110.         or      a
  14111.         call    ErrNZ           ; Maybe undefined FORWARD
  14112.         db      _UndefFORW
  14113.         pop     hl
  14114.         jr      l4e8d
  14115. ;
  14116. ;
  14117. ;
  14118. l4eb5:
  14119.         ld      hl,(LabPtr)     ; Get label pointer
  14120.         push    hl
  14121.         ld      b,0
  14122. l4ebb:
  14123.         push    bc
  14124.         ld      d,_Ptr  ; Set type
  14125.         ld      a,(l7b91)       ; Get ???
  14126.         ld      e,a
  14127.         call    puttolabel_d_e          ; Put to table
  14128.         call    GetLabel                ; Get label
  14129.         call    puttolabel              ; Store into table
  14130.         call    puttolabel_d_e          ; Put to table
  14131.         call    puttolabel_d_e          ; Twice
  14132.         call    SetLabPtr               ; Set label pointer
  14133.         pop     bc
  14134.         inc     b
  14135.         call    l6f13           ; Test ,
  14136.         jr      z,l4ebb         ; Yeap
  14137.         pop     hl
  14138.         ret
  14139. ;
  14140. ;
  14141. ;
  14142. l4edd:
  14143.         ld      hl,(LabPtr)     ; Get label pointer
  14144.         push    hl
  14145.         call    l4f9b           ; Get type
  14146.         pop     hl
  14147.         call    l5295
  14148.         call    FindStr         ; Test ABSOLUTE
  14149.         dw      l7562
  14150.         ld      a,0
  14151.         jr      nz,l4f14        ; Nope
  14152.         ld      a,(l7b91)       ; Get ???
  14153.         or      a
  14154.         call    ErrNZ
  14155.         db      _InvalABS
  14156.         ld      bc,256*_Ptr+0
  14157.         call    FndLABEL                ; Find label
  14158.         jr      nz,l4f0c        ; Nope
  14159.         ld      a,(hl)
  14160.         ld      (l7b8f),a
  14161.         dec     hl
  14162.         ld      d,(hl)
  14163.         dec     hl
  14164.         ld      e,(hl)
  14165.         ex      de,hl
  14166.         jr      l4f0f
  14167. l4f0c:
  14168.         call    _GetIntC                ; Get integer constant
  14169. l4f0f:
  14170.         ld      (l7b7f),hl      ; Store value
  14171.         ld      a,-1
  14172. l4f14:
  14173.         ld      (l7b90),a
  14174.         ret
  14175. ;
  14176. ; Process variable on PROCEDURE and FUNCTION
  14177. ;
  14178. l4f18:
  14179.         call    l4fc8           ; Get simple type
  14180.         call    ErrNZ           ; Verify ok
  14181.         db      _TypeExp
  14182.         xor     a
  14183.         ld      (l7b90),a
  14184.         ld      a,(l7b8f)
  14185.         or      a
  14186.         ret     nz
  14187.         ld      a,(l7b5c)       ; Get type
  14188.         cp      _RecF
  14189.         ret     c
  14190.         cp      _String
  14191.         ret     nc
  14192.         call    ERROR           ; Files must be VAR
  14193.         db      _VarFile
  14194. ;
  14195. ;
  14196. ;
  14197. l4f35:
  14198.         call    l4eb5
  14199.         push    hl
  14200.         push    bc
  14201.         call    l6f40           ; Verify :
  14202.         xor     a
  14203.         ld      (l7b8f),a
  14204.         call    l4edd
  14205.         pop     bc
  14206.         ld      a,(l7b90)
  14207.         or      a
  14208.         jr      z,l4f51
  14209.         ld      a,b
  14210.         dec     a
  14211.         call    ErrNZ           ; Invalid ABSOLUTE
  14212.         db      _InvalABS
  14213. l4f51:
  14214.         pop     hl
  14215. l4f52:
  14216.         push    bc
  14217.         push    hl
  14218.         ld      a,(l7b8f)
  14219.         ld      hl,2
  14220.         or      a
  14221.         jr      nz,l4f60
  14222.         ld      hl,(l7b62)      ; Get length of type
  14223. l4f60:
  14224.         ex      de,hl
  14225.         ld      a,(l7b91)       ; Get ???
  14226.         or      a
  14227.         jr      nz,l4f72
  14228.         ld      a,(l7b90)
  14229.         or      a
  14230.         jr      nz,l4f72
  14231.         call    VarAlloc                ; Allocate space
  14232.         jr      l4f7b
  14233. l4f72:
  14234.         ld      hl,(l7b7f)
  14235.         push    hl
  14236.         add     hl,de
  14237.         ld      (l7b7f),hl
  14238.         pop     hl
  14239. l4f7b:
  14240.         ex      de,hl
  14241.         pop     hl
  14242.         dec     hl
  14243. l4f7e:
  14244.         dec     hl
  14245.         bit     _MB,(hl)
  14246.         jr      z,l4f7e
  14247.         dec     hl
  14248.         ld      a,(l7b8f)
  14249.         ld      (hl),a
  14250.         dec     hl
  14251.         ld      (hl),d
  14252.         dec     hl
  14253.         ld      (hl),e
  14254.         dec     hl
  14255.         ld      de,(l7b5a)      ; Get type table
  14256.         ld      (hl),d          ; Store into
  14257.         dec     hl
  14258.         ld      (hl),e
  14259.         dec     hl
  14260.         dec     hl
  14261.         dec     hl
  14262.         pop     bc
  14263.         djnz    l4f52
  14264.         ret
  14265. ;
  14266. ; Get a TYPE
  14267. ;
  14268. l4f9b:
  14269.         call    l4fc8           ; Test simple type
  14270.         ret     z
  14271.         call    FindStr         ; Skip possible PACKED
  14272.         dw      l7542
  14273.         call    l4fdb           ; Check ARRAY
  14274.         ret     z
  14275.         call    l5039           ; Check RECORD
  14276.         ret     z
  14277.         call    l5106           ; Check SET
  14278.         ret     z
  14279.         call    l5140           ; Check ^
  14280.         ret     z
  14281.         call    l516b           ; Check FILE
  14282.         ret     z
  14283.         call    l51a5           ; Check STRING
  14284.         ret     z
  14285.         call    l51c5           ; Test SCALAR ()
  14286.         ret     z
  14287.         call    l5210           ; Test RANGE ..
  14288.         ret     z
  14289.         call    ERROR           ; Type declaration expected
  14290.         db      _TypeExp
  14291. ;
  14292. ; Get SIMPLE TYPE
  14293. ; EXIT  Zero set if found
  14294. ;
  14295. l4fc8:
  14296.         ld      bc,256*3+0
  14297.         call    FndLABEL                ; Get from table
  14298.         ret     nz              ; Not found
  14299.         ld      d,(hl)          ; Fetch type table
  14300.         dec     hl
  14301.         ld      e,(hl)
  14302.         ex      de,hl
  14303.         ld      (l7b5a),hl      ; Save type
  14304.         call    l5287           ; Get name
  14305.         xor     a               ; Set success
  14306.         ret
  14307. ;
  14308. ; Look for ARRAY
  14309. ;
  14310. l4fdb:
  14311.         call    FindStr         ; Test ARRAY
  14312.         dw      l7548
  14313.         ret     nz              ; Nope
  14314.         call    l6f30           ; Verify [
  14315.         ld      b,0
  14316. l4fe6:
  14317.         push    bc
  14318.         call    l523b
  14319.         pop     bc
  14320.         ld      hl,(l7b5a)      ; Get type table
  14321.         push    hl
  14322.         ld      hl,(l7b60)      ; Get hi limit
  14323.         ld      de,(l7b5e)      ; Get lo limit
  14324.         or      a
  14325.         sbc     hl,de
  14326.         inc     hl
  14327.         ld      a,h
  14328.         or      l
  14329.         call    ErrZ            ; Verify not same
  14330.         db      _MemOvfl
  14331.         push    hl
  14332.         inc     b
  14333.         call    l6f13           ; Test ,
  14334.         jr      z,l4fe6         ; Yeap
  14335.         push    bc
  14336.         call    l6f38           ; Verify ]
  14337.         call    l6f88
  14338.         call    l4f9b           ; Get type
  14339.         pop     bc
  14340. l5012:
  14341.         ld      hl,(l7b5a)      ; Get type table
  14342.         ld      (l7b5e),hl      ; Set as lo limit
  14343.         ld      hl,(l7b62)      ; Get length of type
  14344.         pop     de
  14345.         push    bc
  14346.         call    l729a           ; Multiply numbers
  14347.         call    ErrCY           ; Check compiler overflow
  14348.         db      _MemOvfl
  14349.         pop     bc
  14350.         ld      (l7b62),hl      ; Set length of type
  14351.         pop     hl
  14352.         ld      (l7b60),hl      ; Set hi limit
  14353.         ld      a,_Array
  14354.         ld      (l7b5c),a       ; Set ARRAY
  14355.         push    bc
  14356.         call    l5254           ; Put to table
  14357.         pop     bc
  14358.         djnz    l5012
  14359.         ret
  14360. ;
  14361. ; Look for RECORD
  14362. ;
  14363. l5039:
  14364.         call    FindStr         ; Test RECORD
  14365.         dw      l7554
  14366.         ret     nz              ; Nope
  14367.         ld      a,(l7b9a)
  14368.         push    af
  14369.         ld      a,(l7b91)       ; Get ???
  14370.         push    af
  14371.         ld      hl,l7b92        ; Point to ???
  14372.         inc     (hl)
  14373.         ld      a,(hl)
  14374.         ld      (l7b91),a       ; Set ???
  14375.         ld      hl,(l7b7f)
  14376.         push    hl
  14377.         ld      hl,(l7b81)
  14378.         push    hl
  14379.         ld      hl,l0000
  14380.         ld      (l7b7f),hl
  14381.         ld      (l7b81),hl
  14382.         xor     a
  14383.         ld      (l7b9a),a
  14384.         call    l508b
  14385.         ld      hl,(l7b81)
  14386.         ld      (l7b62),hl      ; Set length of type
  14387.         pop     hl
  14388.         ld      (l7b81),hl
  14389.         pop     hl
  14390.         ld      (l7b7f),hl
  14391.         ld      a,(l7b91)       ; Get ???
  14392.         ld      (l7b5d),a
  14393.         pop     af
  14394.         ld      (l7b91),a       ; Set ???
  14395.         pop     af
  14396.         ld      (l7b9a),a
  14397.         ld      a,_Record
  14398.         ld      (l7b5c),a       ; Set RECORD
  14399.         jp      l5254
  14400. ;
  14401. ;
  14402. ;
  14403. l508b:
  14404.         call    l50f9
  14405.         ret     z
  14406.         call    FindStr         ; Test CASE
  14407.         dw      l75da
  14408.         jr      z,l50b0         ; Yeap
  14409.         call    l4f35
  14410.         ld      hl,(l7b7f)
  14411.         ld      de,(l7b81)
  14412.         or      a
  14413.         sbc     hl,de
  14414.         jr      c,l50a9
  14415.         add     hl,de
  14416.         ld      (l7b81),hl
  14417. l50a9:
  14418.         call    l6f0f           ; Test ;
  14419.         jr      z,l508b         ; Yeap
  14420.         jr      l50e8
  14421. l50b0:
  14422.         call    l4fc8
  14423.         call    nz,l4f35
  14424.         call    l6f88
  14425. l50b9:
  14426.         call    l50f9
  14427.         ret     z
  14428.         ld      hl,(l7b7f)
  14429.         push    hl
  14430. l50c1:
  14431.         call    _GetConst               ; Get constant
  14432.         call    l6f13           ; Test ,
  14433.         jr      z,l50c1         ; Yeap
  14434.         call    l6f40           ; Verify :
  14435.         call    l6f66           ; Verify (
  14436.         ld      a,(l7b9a)
  14437.         push    af
  14438.         ld      a,0ffh
  14439.         ld      (l7b9a),a
  14440.         call    l508b
  14441.         pop     af
  14442.         ld      (l7b9a),a
  14443.         pop     hl
  14444.         ld      (l7b7f),hl
  14445.         call    l6f0f           ; Test ;
  14446.         jr      z,l50b9         ; Yeap
  14447. l50e8:
  14448.         ld      a,(l7b9a)
  14449.         or      a
  14450.         jp      nz,l6f6e        ; Verify )
  14451.         call    FindStr         ; Find END
  14452.         dw      l7530
  14453.         ret     z               ; Yeap
  14454.         call    ERROR
  14455.         db      _End
  14456. l50f9:
  14457.         ld      a,(l7b9a)
  14458.         or      a
  14459.         jp      nz,l6f1f
  14460.         call    FindStr         ; Find END
  14461.         dw      l7530
  14462.         ret
  14463. ;
  14464. ; Check SET
  14465. ;
  14466. l5106:
  14467.         call    FindStr         ; Test SET
  14468.         dw      l7551
  14469.         ret     nz              ; Nope
  14470.         call    l6f88
  14471.         call    l523b
  14472.         ld      hl,(l7b60)      ; Get hi set limit
  14473.         ld      de,(l7b5e)      ; Get lo set limit
  14474.         ld      a,h
  14475.         or      d
  14476.         call    ErrNZ
  14477.         db      _IllSetRange
  14478.         srl     l
  14479.         srl     l
  14480.         srl     l
  14481.         srl     e
  14482.         srl     e
  14483.         srl     e
  14484.         ld      a,l
  14485.         inc     a
  14486.         sub     e
  14487.         ld      l,a
  14488.         ld      (l7b62),hl      ; Set length of type
  14489.         ld      hl,(l7b5a)      ; Get type table
  14490.         ld      (l7b5e),hl      ; Set lo set limit
  14491.         ld      a,_Set
  14492.         ld      (l7b5c),a       ; Set SET
  14493.         jp      l5254
  14494. ;
  14495. ; Check ^
  14496. ;
  14497. l5140:
  14498.         call    l6f27
  14499.         ret     nz
  14500.         ld      de,l0000
  14501.         call    puttolabel_d_e          ; Put to table
  14502.         ld      hl,(LabPtr)     ; Get label pointer
  14503.         push    hl
  14504.         call    l6dba
  14505.         call    SetLabPtr               ; Set label pointer
  14506.         pop     hl
  14507.         ld      (l7b5e),hl      ; Set lo set limit
  14508.         ld      a,_Ptr
  14509.         ld      (l7b5c),a       ; Set POINTER
  14510.         ld      a,0ffh
  14511.         ld      (l7b5d),a
  14512.         ld      hl,l0002
  14513.         ld      (l7b62),hl      ; Set length of type
  14514.         jp      l5254
  14515. ;
  14516. ; Check FILE
  14517. ;
  14518. l516b:
  14519.         call    FindStr         ; Find FILE
  14520.         dw      l754d
  14521.         ret     nz              ; Nope
  14522.         call    FindStr         ; Find OF
  14523.         dw      l7560
  14524.         jr      nz,l5197        ; Nope
  14525.         call    l4f9b           ; Get type
  14526.         ld      a,(l7b5c)       ; Get type
  14527.         cp      _RecF
  14528.         jr      c,l518a
  14529.         cp      _String
  14530.         jr      nc,l518a
  14531.         call    ERROR
  14532.         db      _FileF
  14533. l518a:
  14534.         ld      hl,(l7b5a)      ; Get type table
  14535.         ld      (l7b5e),hl      ; Set lo set limit
  14536.         ld      a,_RecF
  14537.         ld      hl,l00b0
  14538.         jr      l519c
  14539. l5197:
  14540.         ld      a,_UntF
  14541.         ld      hl,l0030
  14542. l519c:
  14543.         ld      (l7b5c),a       ; Set type
  14544.         ld      (l7b62),hl      ; Set length of type
  14545.         jp      l5254
  14546. ;
  14547. ; Check STRING
  14548. ;
  14549. l51a5:
  14550.         call    FindStr         ; Find STRING
  14551.         dw      l755a
  14552.         ret     nz              ; Nope
  14553.         call    l6f30           ; Verify [
  14554.         call    _GetIntC                ; Get integer constant
  14555.         inc     h
  14556.         dec     h
  14557.         call    ErrNZ
  14558.         db      _IllStrgLen
  14559.         inc     l
  14560.         dec     l
  14561.         call    ErrZ
  14562.         db      _IllStrgLen
  14563.         call    l6f38           ; Verify ]
  14564.         inc     hl
  14565.         ld      a,_String
  14566.         jr      l519c
  14567. ;
  14568. ; Test SCALAR ()
  14569. ;
  14570. l51c5:
  14571.         call    l6f1b           ; Test (
  14572.         ret     nz              ; Nope
  14573.         ld      hl,lffff
  14574. l51cc:
  14575.         push    hl
  14576.         ld      de,2*256+0 ;l0200
  14577.         call    puttolabel_d_e          ; Put to table
  14578.         call    GetLabel                ; Get label
  14579.         ld      a,(curtype_l7b93)       ; Get type
  14580.         call    puttolabel
  14581.         pop     de
  14582.         inc     de
  14583.         push    de
  14584.         call    puttolabel_d_e          ; Put to table
  14585.         call    SetLabPtr               ; Set label pointer
  14586.         pop     hl
  14587.         call    l6f13           ; Test ,
  14588.         jr      z,l51cc         ; Yeap
  14589.         call    l6f6e           ; Verify )
  14590.         push    hl
  14591.         ld      hl,curtype_l7b93        ; Point to type
  14592.         ld      a,(hl)
  14593.         inc     (hl)
  14594.         pop     hl
  14595.         ld      de,l0000
  14596. l51f8:
  14597.         ld      (l7b5c),a       ; Set type
  14598.         ld      (l7b5e),de      ; Set lo set limit
  14599.         ld      (l7b60),hl      ; Set hi set limit
  14600.         ld      a,d
  14601.         or      h
  14602.         ld      hl,l0001
  14603.         jr      z,l520a
  14604.         inc     hl
  14605. l520a:
  14606.         ld      (l7b62),hl      ; Set length of type
  14607.         jp      l5254
  14608. ;
  14609. ; Test RANGE ..
  14610. ;
  14611. l5210:
  14612.         call    GetConst                ; Get constant
  14613.         ret     nz
  14614.         ld      a,b
  14615.         push    af
  14616.         cp      0ah ;_Integ
  14617.         call    ErrCY
  14618.         db      _IllSkalar
  14619.         push    hl
  14620.         call    FindStr         ; Find ..
  14621.         dw      l7580
  14622.         call    ErrNZ
  14623.         db      _TwoDots
  14624.         call    _GetConst               ; Get constant
  14625.         pop     de
  14626.         pop     af
  14627.         push    af
  14628.         cp      b
  14629.         call    ErrNZ
  14630.         db      _InvType
  14631.         call    l728d           ; Compare
  14632.         call    ErrCY           ; Verify upper > lower
  14633.         db      _IllLimit
  14634.         pop     af
  14635.         jr      l51f8
  14636. ;
  14637. ;
  14638. ;
  14639. l523b:
  14640.         call    l5210
  14641.         ret     z
  14642.         call    l51c5
  14643.         ret     z
  14644.         call    l4fc8
  14645.         call    ErrNZ
  14646.         db      _SimTyp
  14647.         ld      a,(l7b5c)       ; Get type
  14648.         cp      _Integ
  14649.         ret     nc
  14650.         call    ERROR
  14651.         db      _SimTyp
  14652. l5254:
  14653.         ld      de,8*256+0 ;l0800
  14654.         call    puttolabel_d_e          ; Put to table
  14655.         ld      hl,(LabPtr)     ; Get label pointer
  14656.         ld      (l7b5a),hl      ; Save into type table
  14657.         ld      hl,l7b5c        ; Point to type
  14658.         ld      b,8
  14659. l5265:
  14660.         ld      a,(hl)
  14661.         call    puttolabel
  14662.         inc     hl
  14663.         djnz    l5265
  14664.         call    SetLabPtr               ; Set label pointer
  14665.         xor     a
  14666.         ret
  14667. ;
  14668. ;
  14669. ;
  14670. l5271:
  14671.         ld      de,l7b69
  14672.         jr      l528a
  14673. ;
  14674. ; Get values and name
  14675. ;
  14676. l5276:
  14677.         ld      a,(hl)
  14678.         dec     hl
  14679.         ld      (Envir1),a
  14680.         ld      d,(hl)
  14681.         dec     hl
  14682.         ld      e,(hl)
  14683.         dec     hl
  14684.         ld      (l7b58),de      ; Set value
  14685.         ld      d,(hl)
  14686.         dec     hl
  14687.         ld      e,(hl)
  14688.         ex      de,hl
  14689. ;
  14690. ; Get name
  14691. ;
  14692. l5287:
  14693.         ld      de,l7b5c        ; Point to type
  14694. l528a:
  14695.         push    bc
  14696.         ld      b,8
  14697. l528d:
  14698.         ld      a,(hl)
  14699.         ld      (de),a
  14700.         dec     hl
  14701.         inc     de
  14702.         djnz    l528d
  14703.         pop     bc
  14704.         ret
  14705. ;
  14706. ;
  14707. ;
  14708. l5295:
  14709.         ld      (l7b79),hl
  14710.         ld      hl,(LabPtr)     ; Get label pointer
  14711. l529b:
  14712.         ld      bc,(l7b79)
  14713.         or      a
  14714.         sbc     hl,bc
  14715.         add     hl,bc
  14716.         ret     z
  14717.         inc     hl
  14718.         ld      c,(hl)
  14719.         inc     hl
  14720.         ld      b,(hl)
  14721.         add     hl,bc
  14722.         ld      a,(hl)
  14723.         cp      8 ;???
  14724.         jr      nz,l529b
  14725.         ld      (hl),0
  14726.         push    hl
  14727.         dec     hl
  14728.         dec     hl
  14729.         ld      a,(hl)
  14730.         cp      4 ;???
  14731.         jr      nz,l52f8
  14732.         dec     hl
  14733.         ld      a,(hl)
  14734.         or      a
  14735.         jr      z,l52f8
  14736.         ld      (hl),0
  14737.         dec     hl
  14738.         push    hl
  14739.         ld      e,(hl)
  14740.         dec     hl
  14741.         ld      d,(hl)
  14742.         ld      hl,(LabPtr)     ; Get label pointer
  14743. l52c7:
  14744.         ld      bc,(l7b77)      ; Get top of available memory
  14745.         or      a
  14746.         sbc     hl,bc
  14747.         add     hl,bc
  14748.         call    ErrZ
  14749.         db      _InkPointer
  14750.         inc     hl
  14751.         ld      c,(hl)
  14752.         inc     hl
  14753.         ld      b,(hl)
  14754.         add     hl,bc
  14755.         ld      a,(hl)
  14756.         cp      3 ;???
  14757.         jr      nz,l52c7
  14758.         push    hl
  14759.         push    de
  14760.         dec     hl
  14761.         dec     hl
  14762. l52e1:
  14763.         ld      a,(de)
  14764.         cp      (hl)
  14765.         jr      z,l52e9
  14766.         pop     de
  14767.         pop     hl
  14768.         jr      l52c7
  14769. l52e9:
  14770.         bit     7,(hl)
  14771.         dec     hl
  14772.         dec     de
  14773.         jr      z,l52e1
  14774.         pop     bc
  14775.         pop     bc
  14776.         ld      b,(hl)
  14777.         dec     hl
  14778.         ld      c,(hl)
  14779.         pop     hl
  14780.         ld      (hl),c
  14781.         dec     hl
  14782.         ld      (hl),b
  14783. l52f8:
  14784.         pop     hl
  14785.         jp      l529b
  14786. ;
  14787. ;
  14788. ;
  14789. l52fc:
  14790.         xor     a
  14791.         ld      (l7b95),a
  14792.         ld      (l7bc9),a
  14793.         call    l5377
  14794.         ld      (l7ba4),iy
  14795.         call    StJP_
  14796.         ld      hl,(LabPtr)     ; Get label pointer
  14797. l5310:
  14798.         ld      de,(PrevLabPtr) ; Get previous label pointer
  14799.         or      a
  14800.         sbc     hl,de
  14801.         add     hl,de
  14802.         jr      nc,l5363
  14803.         inc     hl
  14804.         ld      c,(hl)
  14805.         inc     hl
  14806.         ld      b,(hl)
  14807.         inc     hl
  14808.         ld      a,(hl)
  14809.         inc     hl
  14810.         ld      e,(hl)
  14811.         inc     hl
  14812.         ld      d,(hl)
  14813.         push    hl
  14814.         push    bc
  14815.         ld      b,a
  14816.         ld      a,d
  14817.         or      e
  14818.         jr      z,l533a
  14819.         ex      de,hl
  14820.         dec     hl
  14821.         ld      a,(hl)
  14822.         ld      c,a
  14823.         inc     a
  14824.         call    ErrZ
  14825.         db      _UnkLabel
  14826.         dec     hl
  14827.         ld      d,(hl)
  14828.         dec     hl
  14829.         ld      e,(hl)
  14830.         jr      l5340
  14831. l533a:
  14832.         ld      de,(l7ba4)
  14833.         ld      c,0
  14834. l5340:
  14835.         pop     hl
  14836.         ld      a,b
  14837.         sub     c
  14838.         jr      nz,l534a
  14839.         call    storeback_de_to_addrhl
  14840.         jr      l5360
  14841. l534a:
  14842.         call    ErrCY
  14843.         db      _IllGOTO
  14844.         push    de
  14845.         push    af
  14846.         call    storeback_iy_to_addrhl          ; Store back PC
  14847.         pop     af
  14848.         ld      b,a
  14849. l5355:
  14850.         call    StPOP           ; Set POP HL
  14851.         djnz    l5355
  14852.         ld      a,_JP
  14853.         pop     hl
  14854.         call    StCode
  14855. l5360:
  14856.         pop     hl
  14857.         jr      l5310
  14858. l5363:
  14859.         ld      hl,(l7ba4)
  14860.         inc     hl
  14861.         push    iy
  14862.         pop     de
  14863.         dec     de
  14864.         dec     de
  14865.         or      a
  14866.         sbc     hl,de
  14867.         add     hl,de
  14868.         jp      nz,storeback_iy_to_addrhl       ; Store back PC
  14869.         dec     hl
  14870.         jp      ChkChn          ; Check chaining
  14871. ;
  14872. ; Statement BEGIN
  14873. ;
  14874. l5377:
  14875.         call    l5385           ; Process a statement
  14876.         call    FindStr         ; Find END
  14877.         dw      l7530
  14878.         ret     z
  14879.         call    l6f50
  14880.         jr      l5377
  14881. ;
  14882. ; Process a statement
  14883. ;
  14884. l5385:
  14885.         ld      a,0ffh
  14886.         ld      (l7b98),a
  14887.         ld      a,(l7b9d)       ; Get options
  14888.         ld      (l7b9e),a       ; Set local options
  14889.         bit     _Uopt,a         ; Test $U+
  14890.         jr      z,l539c         ; Nope
  14891.         ld      a,RST
  14892.         ld      (l7ba0),a       ; Set end on break flag [option U+]
  14893.         call    writebyte_a_addriy              ; Insert RST
  14894. l539c:
  14895.         call    FndTabStr               ; Find statement
  14896.         db      2
  14897.         dw      l75bb
  14898.         jr      z,l53cb         ; Yeap
  14899.         call    l67b2
  14900.         jp      z,l57ea
  14901.         ld      bc,256*5+0
  14902.         call    FndLABEL
  14903.         jp      z,l573d
  14904.         ld      bc,256*1+0
  14905.         call    FndLABEL
  14906.         jr      z,l53d0
  14907.         ld      bc,256*6+0
  14908.         call    FndLABEL
  14909.         jp      z,l591f
  14910.         call    FndTabStr               ; Find procedure
  14911.         db      2
  14912.         dw      l7638
  14913.         ret     nz              ; Nope
  14914. l53cb:
  14915.         ld      e,(hl)          ; Fetch address
  14916.         inc     hl
  14917.         ld      d,(hl)
  14918.         ex      de,hl
  14919.         jp      (hl)            ; Go
  14920. l53d0:
  14921.         call    l6f40           ; Verify :
  14922.         ld      a,(l7b94)       ; Get ???
  14923.         cp      (hl)
  14924.         call    ErrNZ
  14925.         db      _IllLabel
  14926.         dec     hl
  14927.         ld      a,(hl)
  14928.         inc     a
  14929.         call    ErrNZ
  14930.         db      _DoubleLab
  14931.         ld      a,(l7b95)
  14932.         ld      (hl),a
  14933.         push    iy
  14934.         pop     de
  14935.         dec     hl
  14936.         ld      (hl),d
  14937.         dec     hl
  14938.         ld      (hl),e
  14939.         jr      l5385
  14940. ;
  14941. ; Statement IF
  14942. ;
  14943. l53ef:
  14944.         call    l5eb0
  14945.         call    StImm           ; Set BIT 0,L ! JP Z,addr
  14946.         db      a_L9
  14947. s_I9:
  14948.         BIT     _LB,L
  14949.         db      _JPZ
  14950. a_L9    equ     $-s_I9
  14951.         push    iy
  14952.         call    writeword_hl_addriy
  14953.         call    FindStr         ; Find THEN
  14954.         dw      l756a
  14955.         call    ErrNZ
  14956.         db      _StrIdx
  14957.         call    l5385           ; Process a statement
  14958.         call    FindStr         ; Find ELSE
  14959.         dw      l756e
  14960.         jr      nz,l5420        ; Nope
  14961.         call    StJP            ; Set JP
  14962.         pop     hl
  14963.         push    iy
  14964.         call    writeword_hl_addriy
  14965.         call    storeback_iy_to_addrhl          ; Store back PC
  14966.         call    l5385           ; Process a statement
  14967. l5420:
  14968.         pop     hl
  14969.         jp      storeback_iy_to_addrhl          ; Store back PC
  14970. ;
  14971. ; Statement WHILE
  14972. ;
  14973. l5424:
  14974.         push    iy
  14975.         call    l5eb0
  14976.         call    FindStr         ; Find DO
  14977.         dw      l7572
  14978.         call    ErrNZ
  14979.         db      _NoDO
  14980.         call    StImm           ; Set BIT 0,L ! JP Z,addr
  14981.         db      a_L10
  14982. s_I10:
  14983.         BIT     _LB,L
  14984.         db      _JPZ
  14985. a_L10   equ     $-s_I10
  14986.         push    iy
  14987.         call    writeword_hl_addriy
  14988.         call    l5385           ; Process a statement
  14989.         pop     de
  14990.         pop     hl
  14991.         ld      a,_JP
  14992.         call    StCode
  14993.         ex      de,hl
  14994.         jp      storeback_iy_to_addrhl          ; Store back PC
  14995. ;
  14996. ; Statement REPEAT
  14997. ;
  14998. l544c:
  14999.         push    iy
  15000. l544e:
  15001.         call    l5385           ; Process a statement
  15002.         call    FindStr         ; Find UNTIL
  15003.         dw      l7574
  15004.         jr      z,l545d         ; Yeap
  15005.         call    l6f50
  15006.         jr      l544e
  15007. l545d:
  15008.         call    l5eb0
  15009.         call    StImm
  15010.         db      a_L11
  15011. s_I11:
  15012.         BIT     _LB,L
  15013.         db      _JPZ
  15014. a_L11   equ     $-s_I11
  15015.         pop     hl
  15016.         jp      writeword_hl_addriy
  15017. ;
  15018. ; Statement FOR
  15019. ;
  15020. l546b:
  15021.         ld      bc,256*4+0
  15022.         call    FndLABEL
  15023.         call    ErrNZ
  15024.         db      _Undef
  15025.         call    l5276
  15026.         ld      a,(Envir1)
  15027.         or      a
  15028.         jr      nz,l5485
  15029.         ld      a,(l7b5c)       ; Get type
  15030.         cp      _Integ
  15031.         jr      nc,l5489
  15032. l5485:
  15033.         call    ERROR
  15034.         db      _SimTyp
  15035. l5489:
  15036.         call    l6d2a           ; Save environment
  15037.         ld      a,(l7b5c)       ; Get type
  15038.         push    af
  15039.         call    l6f7e
  15040.         call    l5ee8
  15041.         call    StPUSH          ; Set PUSH HL
  15042.         pop     af
  15043.         push    af
  15044.         cp      b
  15045.         call    ErrNZ
  15046.         db      _InvType
  15047.         call    FndTabStr               ; Find TO or DOWNTO
  15048.         db      1
  15049.         dw      l75f5
  15050.         call    ErrNZ
  15051.         db      _NoDOWN_TO
  15052.         ld      e,(hl)          ; Get instruction
  15053.         push    de
  15054.         call    l5ee8
  15055.         pop     de
  15056.         pop     af
  15057.         push    de
  15058.         cp      b
  15059.         call    ErrNZ
  15060.         db      _InvType
  15061.         call    FindStr         ; Find DO
  15062.         dw      l7572
  15063.         call    ErrNZ
  15064.         db      _NoDO
  15065.         call    StImm           ; Set POP DE
  15066.         db      a_L12
  15067. s_I12:
  15068.         POP     DE
  15069. a_L12   equ     $-s_I12
  15070.         pop     de
  15071.         call    l6d63
  15072.         push    de
  15073.         ld      a,e
  15074.         ld      hl,l0666        ; Set up FOR .. TO loop
  15075.         cp      '#'
  15076.         jr      z,l54d5
  15077.         ld      hl,l0676        ; Set up FOR .. DOWNTO loop
  15078. l54d5:
  15079.         call    StCALL_         ; Set CALL <loop>
  15080.         push    iy
  15081.          ;jr $
  15082.         call    StImm           ; Set code sequence
  15083.         db      a_L13
  15084. s_I13:
  15085.         LD      A,D
  15086.         OR      E
  15087.         JP      Z,$-$ ;for future patching???
  15088.         PUSH    DE
  15089. a_L13   equ     $-s_I13
  15090.         call    l661b
  15091.         ld      hl,l7b95
  15092.         inc     (hl)
  15093.         call    l5385           ; Process a statement
  15094.         ld      hl,l7b95
  15095.         dec     (hl)
  15096.         pop     hl
  15097.         pop     de
  15098.         call    RestEnv1                ; Get back environment
  15099.         push    hl
  15100.         ld      hl,(l7b58)      ; Get value
  15101.         ld      a,_LD_a_HL
  15102.         call    StCode
  15103.         ld      a,(l7b62)       ; Get length of type
  15104.         dec     a
  15105.         jr      nz,l550c
  15106.         call    StImm           ; Set LD H,0
  15107.         db      a_L14
  15108. s_I14:
  15109.         LD      H,0
  15110. a_L14   equ     $-s_I14
  15111. l550c:
  15112.         ld      a,e             ; Get byte
  15113.         call    writebyte_a_addriy              ; Store it
  15114.         call    StImm           ; Set code sequence
  15115.         db      a_L15
  15116. s_I15:
  15117.         POP     DE
  15118.         DEC     DE
  15119.         db      _JP
  15120. a_L15   equ     $-s_I15
  15121.         pop     hl
  15122.         call    writeword_hl_addriy
  15123.         inc     hl
  15124.         inc     hl
  15125.         inc     hl
  15126.         jp      storeback_iy_to_addrhl          ; Store back PC
  15127. ;
  15128. ; Statement CASE
  15129. ;
  15130. l5521:
  15131.         call    l5ebb
  15132.         ld      (l7b9c),a
  15133.         xor     a
  15134.         ld      (l7b9b),a
  15135.         call    l6f88
  15136.         ld      b,0
  15137.         push    bc
  15138. l5531:
  15139.         ld      b,1
  15140. l5533:
  15141.         push    bc
  15142.         ld      hl,l7b9b
  15143.         bit     7,(hl)
  15144.         jr      z,l5549
  15145.         call    StImm           ; Set ADD HL,DE
  15146.         db      a_L16
  15147. s_I16:
  15148.         ADD     HL,DE
  15149. a_L16   equ     $-s_I16
  15150.         bit     4,(hl)
  15151.         jr      z,l5549
  15152.         call    StImm           ; Set ADD HL,BC
  15153.         db      a_L17
  15154. s_I17:
  15155.         ADD     HL,BC
  15156. a_L17   equ     $-s_I17
  15157. l5549:
  15158.         call    _GetConst               ; Get constant
  15159.         ld      a,(l7b9c)
  15160.         cp      b
  15161.         call    ErrNZ
  15162.         db      _IllCASE
  15163.         call    StLD.DE         ; Set LD DE,val16
  15164.         push    hl
  15165.         call    FindStr         ; Find ..
  15166.         dw      l7580
  15167.         pop     hl
  15168.         jr      nz,l5582        ; Nope
  15169.         push    hl
  15170.         call    _GetConst               ; Get constant
  15171.         ld      a,(l7b9c)
  15172.         cp      b
  15173.         call    ErrNZ
  15174.         db      _IllCASE
  15175.         pop     de
  15176.         or      a
  15177.         sbc     hl,de
  15178.         inc     hl
  15179.         call    StLD.BC
  15180.         call    StImm           ; Set sequence
  15181.         db      a_L18
  15182. s_I18:
  15183.         OR      A
  15184.         SBC     HL,DE
  15185.         OR      A
  15186.         SBC     HL,BC
  15187. a_L18   equ     $-s_I18
  15188.         ld      a,0dah
  15189.         jr      l558b
  15190. l5582:
  15191.         call    StImm           ; Set sequence
  15192.         db      a_L19
  15193. s_I19:
  15194.         OR      A
  15195.         SBC     HL,DE
  15196. a_L19   equ     $-s_I19
  15197.         ld      a,0cah
  15198. l558b:
  15199.         ld      (l7b9b),a
  15200.         call    l6f0b           ; Test :
  15201.         pop     bc
  15202.         jr      z,l55a5
  15203.         ld      a,(l7b9b)       ; Get byte
  15204.         call    writebyte_a_addriy              ; Store it
  15205.         push    iy
  15206.         call    writeword_hl_addriy
  15207.         call    l6f5e           ; Verify ,
  15208.         inc     b
  15209.         jr      l5533
  15210. l55a5:
  15211.         push    iy
  15212.         pop     de
  15213.         inc     de
  15214.         inc     de
  15215.         inc     de
  15216. l55ab:
  15217.         dec     b
  15218.         jr      z,l55b4
  15219.         pop     hl
  15220.         call    storeback_de_to_addrhl
  15221.         jr      l55ab
  15222. l55b4:
  15223.         ld      a,(l7b9b)       ; Get byte
  15224.         res     3,a             ; Fix it
  15225.         call    writebyte_a_addriy              ; Store
  15226.         pop     bc
  15227.         push    iy
  15228.         inc     b
  15229.         push    bc
  15230.         call    writeword_hl_addriy
  15231.         ld      a,(l7b9b)
  15232.         push    af
  15233.         ld      a,(l7b9c)
  15234.         push    af
  15235.         call    l5385           ; Process a statement
  15236.         pop     af
  15237.         ld      (l7b9c),a
  15238.         pop     af
  15239.         ld      (l7b9b),a
  15240.         call    l6f0f           ; Test ;
  15241.         ld      e,1
  15242.         jr      z,l55df         ; Yeap
  15243.         dec     e
  15244. l55df:
  15245.         push    de
  15246.         call    FindStr         ; Find END
  15247.         dw      l7530
  15248.         pop     de
  15249.         jr      z,l561e
  15250.         call    StJP            ; Set JP
  15251.         pop     bc
  15252.         pop     hl
  15253.         push    iy
  15254.         push    bc
  15255.         push    de
  15256.         call    writeword_hl_addriy
  15257.         call    storeback_iy_to_addrhl          ; Store back PC
  15258.         call    FindStr         ; Find ELSE
  15259.         dw      l756e
  15260.         pop     de
  15261.         jr      z,l560f         ; Yeap
  15262.         dec     e
  15263.         jp      z,l5531
  15264.         ld      a,(l7b98)
  15265.         or      a
  15266.         call    ErrZ
  15267.         db      _End
  15268.         call    ERROR
  15269.         db      _Undef
  15270. l560f:
  15271.         call    l5385           ; Process a statement
  15272.         call    FindStr         ; Find END
  15273.         dw      l7530
  15274.         jr      z,l561e         ; Yeap
  15275.         call    l6f50
  15276.         jr      l560f
  15277. l561e:
  15278.         pop     bc
  15279. l561f:
  15280.         pop     hl
  15281.         call    storeback_iy_to_addrhl          ; Store back PC
  15282.         djnz    l561f
  15283.         ret
  15284. ;
  15285. ; Statement GOTO
  15286. ;
  15287. l5626:
  15288.         ld      bc,256*1+0
  15289.         call    FndLABEL
  15290.         call    ErrNZ
  15291.         db      _UnkLabel
  15292.         ld      a,(l7b94)
  15293.         cp      (hl)
  15294.         call    ErrNZ
  15295.         db      _IllLabel
  15296.         ex      de,hl
  15297. l5639:
  15298.         call    puttolabel_d_e          ; Put to table
  15299.         ld      a,(l7b95)
  15300.         call    puttolabel
  15301.         call    StJP            ; Set JP
  15302.         push    iy
  15303.         pop     de
  15304.         call    puttolabel_d_e          ; Put to table
  15305.         jp      writeword_hl_addriy
  15306. ;
  15307. ; Statement WITH
  15308. ;
  15309. l564e:
  15310.         ld      a,(l7bc9)
  15311.         push    af
  15312. l5652:
  15313.         ld      a,(l7bc6)
  15314.         ld      hl,l7bc9
  15315.         cp      (hl)
  15316.         call    ErrZ
  15317.         db      _TooManyWITH
  15318.         call    l677f
  15319.         ld      a,(l7b5c)       ; Get type
  15320.         cp      _Record
  15321.         call    ErrNZ
  15322.         db      _RecVarExp
  15323.         ld      hl,l7bc9
  15324.         ld      e,(hl)
  15325.         ld      d,0
  15326.         inc     (hl)
  15327.         ld      hl,l7bcc
  15328.         add     hl,de
  15329.         ld      a,(l7b5d)
  15330.         ld      (hl),a
  15331.         ld      hl,(l7bca)
  15332.         add     hl,de
  15333.         add     hl,de
  15334.         ld      a,_LDHL_a
  15335.         call    StCode
  15336.         call    l6f13           ; Test ,
  15337.         jr      z,l5652         ; Yeap
  15338.         call    FindStr         ; Find DO
  15339.         dw      l7572
  15340.         call    ErrNZ
  15341.         db      _NoDO
  15342.         call    l5385           ; Process a statement
  15343.         pop     af
  15344.         ld      (l7bc9),a
  15345.         ret
  15346. ;
  15347. ; Statement INLINE
  15348. ;
  15349. l5698:
  15350.         call    l6f66           ; Verify (
  15351. l569b:
  15352.         ld      a,'>'
  15353.         call    l6f29
  15354.         ld      a,2
  15355.         jr      z,l56ae
  15356.         ld      a,'<'
  15357.         call    l6f29
  15358.         ld      a,1
  15359.         jr      z,l56ae
  15360.         xor     a
  15361. l56ae:
  15362.         ld      (l7ba6),a
  15363.         xor     a
  15364.         ld      h,a
  15365.         ld      l,a
  15366.         ld      b,a
  15367. l56b5:
  15368.         push    bc
  15369.         push    hl
  15370.         call    GetConst                ; Get constant
  15371.         jr      nz,l56c5
  15372.         ld      a,b
  15373.         cp      0ah
  15374.         jr      z,l5702
  15375.         call    ERROR
  15376.         db      _IntConst
  15377. l56c5:
  15378.         ld      hl,l7ba6
  15379.         ld      a,(hl)
  15380.         or      a
  15381.         jr      nz,l56ce
  15382.         ld      (hl),2
  15383. l56ce:
  15384.         ld      a,'*'
  15385.         call    l6f29
  15386.         jr      nz,l56da
  15387.         push    iy
  15388.         pop     hl
  15389.         jr      l5702
  15390. l56da:
  15391.         ld      bc,256*4+0
  15392.         call    FndLABEL
  15393.         jr      nz,l56ea
  15394.         call    l5276
  15395.         ld      hl,(l7b58)      ; Get value
  15396.         jr      l5702
  15397. l56ea:
  15398.         ld      bc,256*5+0
  15399.         call    FndLABEL
  15400.         jr      z,l56fc
  15401.         ld      bc,256*6+0
  15402.         call    FndLABEL
  15403.         call    ErrNZ
  15404.         db      _IllINLINE
  15405. l56fc:
  15406.         dec     hl
  15407.         dec     hl
  15408.         ld      d,(hl)
  15409.         dec     hl
  15410.         ld      e,(hl)
  15411.         ex      de,hl
  15412. l5702:
  15413.         pop     de
  15414.         pop     bc
  15415.         dec     b
  15416.         jr      nz,l570a
  15417.         call    NegateInt
  15418. l570a:
  15419.         add     hl,de
  15420.         ld      b,0
  15421.         ld      a,'+'
  15422.         call    l6f29
  15423.         jr      z,l56b5
  15424.         inc     b
  15425.         ld      a,'-'
  15426.         call    l6f29
  15427.         jr      z,l56b5
  15428.         ld      a,(l7ba6)
  15429.         cp      1
  15430.         jr      z,l5729
  15431.         jr      nc,l572f
  15432.         inc     h
  15433.         dec     h
  15434.         jr      nz,l572f
  15435. l5729:
  15436.         ld      a,l             ; Get byte
  15437.         call    writebyte_a_addriy              ; Store it
  15438.         jr      l5732
  15439. l572f:
  15440.         call    writeword_hl_addriy
  15441. l5732:
  15442.         ld      a,'/'
  15443.         call    l6f29
  15444.         jp      z,l569b
  15445.         jp      l6f6e           ; Verify )
  15446. l573d:
  15447.         dec     hl
  15448.         ld      b,(hl)
  15449.         dec     hl
  15450.         ld      d,(hl)
  15451.         dec     hl
  15452.         ld      e,(hl)
  15453.         dec     hl
  15454.         push    de
  15455.         ld      d,(hl)
  15456.         dec     hl
  15457.         ld      e,(hl)
  15458.         dec     hl
  15459.         push    de
  15460.         dec     hl
  15461.         dec     hl
  15462.         ld      d,(hl)
  15463.         dec     hl
  15464.         ld      e,(hl)
  15465.         dec     hl
  15466.         push    de
  15467.         ld      d,(hl)
  15468.         dec     hl
  15469.         ld      e,(hl)
  15470.         dec     hl
  15471.         push    de
  15472.         inc     b
  15473.         dec     b
  15474.         jp      z,l57d6
  15475.         call    l6f66           ; Verify (
  15476. l575e:
  15477.         push    bc
  15478.         ld      b,(hl)
  15479.         dec     hl
  15480.         ld      a,(hl)
  15481.         dec     hl
  15482.         ld      (Envir1),a
  15483.         ld      d,(hl)
  15484.         dec     hl
  15485.         ld      e,(hl)
  15486.         dec     hl
  15487.         ld      c,b
  15488. l576b:
  15489.         bit     7,(hl)
  15490.         dec     hl
  15491.         jr      z,l576b
  15492.         djnz    l576b
  15493.         ld      b,c
  15494.         push    hl
  15495.         ex      de,hl
  15496.         call    l5287           ; Get name
  15497. l5778:
  15498.         push    bc
  15499.         ld      a,(Envir1)
  15500.         or      a
  15501.         jr      nz,l57a9
  15502.         ld      a,(l7b5c)       ; Get type
  15503.         cp      _Set
  15504.         jr      c,l57a1
  15505.         call    l5e84
  15506.         call    l5864
  15507.         ld      a,(l7b5c)       ; Get type
  15508.         cp      _Ptr
  15509.         jr      z,l57bd
  15510.         cp      _Real
  15511.         jr      c,l57c0
  15512.         jr      nz,l57bd
  15513.         call    StImm           ; Set sequence
  15514.         db      a_L20
  15515. s_I20:
  15516.         PUSH    BC
  15517.         PUSH    DE
  15518. a_L20   equ     $-s_I20
  15519.         jr      l57bd
  15520. l57a1:
  15521.         call    l6d2a           ; Save environment
  15522.         call    l6749
  15523.         jr      l57af
  15524. l57a9:
  15525.         call    l6d2a           ; Save environment
  15526.         call    l677f
  15527. l57af:
  15528.         call    CpyEnv2
  15529.         ld      a,(l7b69)
  15530.         cp      0
  15531.         call    nz,l58c5
  15532.         call    RestEnv1                ; Get back environment
  15533. l57bd:
  15534.         call    StPUSH          ; Set PUSH HL
  15535. l57c0:
  15536.         pop     bc
  15537.         dec     b
  15538.         jr      z,l57c9
  15539.         call    l6f5e           ; Verify ,
  15540.         jr      l5778
  15541. l57c9:
  15542.         pop     hl
  15543.         pop     bc
  15544.         dec     b
  15545.         jr      z,l57d3
  15546.         call    l6f5e           ; Verify ,
  15547.         jr      l575e
  15548. l57d3:
  15549.         call    l6f6e           ; Verify )
  15550. l57d6:
  15551.         pop     de
  15552.         pop     hl
  15553.         ld      a,d
  15554.         or      e
  15555.         jr      z,l57e3
  15556.         call    StLD.HL         ; Set LD HL,val16
  15557.         ex      de,hl
  15558.         call    StLD.DE         ; Set LD DE,val16
  15559. l57e3:
  15560.         pop     de
  15561.         pop     hl
  15562.         ld      a,_CALL
  15563.         jp      StCode
  15564. l57ea:
  15565.         ld      a,(l7b5c)       ; Get type
  15566.         cp      0
  15567.         jr      z,l57f9
  15568.         cp      _RecF
  15569.         jr      c,l57fd
  15570.         cp      _String
  15571.         jr      nc,l57fd
  15572. l57f9:
  15573.         call    ERROR
  15574.         db      _IllAss
  15575. l57fd:
  15576.         ld      a,(l7bbd)
  15577.         bit     1,a
  15578.         jr      nz,l5812
  15579.         bit     0,a
  15580.         jr      z,l580a
  15581.         ld      a,0ffh
  15582. l580a:
  15583.         ld      hl,(l7bbe)
  15584.         ld      (l7b58),hl      ; Set value
  15585.         jr      l581a
  15586. l5812:
  15587.         call    l678b
  15588.         call    StPUSH          ; Set PUSH HL
  15589.         ld      a,1
  15590. l581a:
  15591.         ld      (Envir1),a
  15592.         call    l6f7e
  15593.         ld      a,(l7b5c)       ; Get type
  15594.         cp      _Set
  15595.         jp      nc,l593a
  15596.         call    l6d2a           ; Save environment
  15597.         call    l6749
  15598.         call    RestEnv2
  15599.         call    l58c5
  15600.         ld      a,(Envir2)
  15601.         dec     a
  15602.         jr      z,l5852
  15603.         inc     a
  15604.         jr      z,l5845
  15605.         call    StImm           ; Set LD DE,(adr)
  15606.         db      a_L21
  15607. s_I21:
  15608.         dw      _LD_a_DE
  15609. a_L21   equ     $-s_I21
  15610.         jr      l584a
  15611. l5845:
  15612.         call    StImm
  15613.         db      a_L22
  15614. s_I22:
  15615.         db      _LD.DE          ; Set LD DE,adr
  15616. a_L22   equ     $-s_I22
  15617. l584a:
  15618.         ld      hl,(l7b65)
  15619.         call    writeword_hl_addriy
  15620.         jr      l5857
  15621. l5852:
  15622.         call    StImm           ; Set POP DE
  15623.         db      a_L23
  15624. s_I23:
  15625.         pop     de
  15626. a_L23   equ     $-s_I23
  15627. l5857:
  15628.         ld      hl,(l7b6f)
  15629.         call    StLD.BC
  15630.         call    StImm           ; Set LDIR
  15631.         db      a_L24
  15632. s_I24:
  15633.         LDIR
  15634. a_L24   equ     $-s_I24
  15635.         ret
  15636. l5864:
  15637.         ld      a,(l7b5c)       ; Get type
  15638.         cp      _Real
  15639.         jr      nz,l5877
  15640.         ld      a,b
  15641.         cp      _Integ
  15642.         jr      nz,l589d
  15643.         ld      b,9
  15644.         ld      hl,l1008
  15645.         jr      l589a
  15646. l5877:
  15647.         cp      _String
  15648.         jr      nz,l588c
  15649.         ld      a,b
  15650.         cp      _Char
  15651.         jr      nz,l589d
  15652.         ld      b,8
  15653.         call    StImm           ; Set sequence
  15654.         db      a_L25
  15655. s_I25:
  15656.         LD      H,L
  15657.         LD      L,1
  15658.         PUSH    HL
  15659. a_L25   equ     $-s_I25
  15660.         jr      l589d
  15661. l588c:
  15662.         cp      _Char
  15663.         jr      nz,l589d
  15664.         ld      a,b
  15665.         cp      _String
  15666.         jr      nz,l589d
  15667.         ld      b,0ch
  15668.         ld      hl,l0996        ; Set check assignment
  15669. l589a:
  15670.         call    StCALL_         ; Set CALL <check>
  15671. l589d:
  15672.         ld      a,(l7b5c)       ; Get type
  15673.         cp      b
  15674.         jr      nz,l58c1
  15675.         cp      3
  15676.         jr      nz,l58b1
  15677.         ld      a,c
  15678.         or      a
  15679.         ret     z
  15680.         ld      hl,(l7b5e)      ; Get lo set limit
  15681.         cp      (hl)
  15682.         ret     z
  15683.         jr      l58c1
  15684. l58b1:
  15685.         cp      4
  15686.         ret     nz
  15687.         ld      hl,(l7b8b)
  15688.         ld      a,h
  15689.         or      l
  15690.         ret     z
  15691.         ld      de,(l7b5e)      ; Get lo set limit
  15692.         sbc     hl,de
  15693.         ret     z
  15694. l58c1:
  15695.         call    ERROR
  15696.         db      _InvType
  15697. l58c5:
  15698.         ld      a,(l7b5c)       ; Get type
  15699.         cp      0
  15700.         jr      z,l591b
  15701.         ld      c,0bfh
  15702.         cp      _Integ
  15703.         jr      nc,l5906
  15704.         ld      c,83h
  15705.         cp      _String
  15706.         jr      nz,l58e3
  15707.         ld      a,(l7b9e)       ; Get local options
  15708.         bit     _Vopt,a         ; Test $V+
  15709.         jr      nz,l5906        ; Yeap
  15710.         ld      c,80h
  15711.         jr      l5906
  15712. l58e3:
  15713.         cp      _TxtF
  15714.         jr      nc,l5906
  15715.         ld      c,0b3h
  15716.         cp      _Set
  15717.         jr      nc,l5906
  15718.         ld      c,0c3h
  15719.         cp      _Record
  15720.         jr      nc,l5906
  15721.         ld      hl,(l7b60)      ; Get hi set limit
  15722.         ld      a,h
  15723.         or      l
  15724.         ld      c,0bfh
  15725.         jr      nz,l5906
  15726.         ld      hl,(l7b6d)      ; Get last memory address
  15727.         ld      a,(hl)
  15728.         cp      0ah
  15729.         jr      nz,l591b
  15730.         ld      c,0b3h
  15731. l5906:
  15732.         ld      hl,l7b5c        ; Point to type
  15733.         ld      de,l7b69
  15734.         ld      b,8
  15735. l590e:
  15736.         rl      c
  15737.         jr      nc,l5916
  15738.         ld      a,(de)
  15739.         cp      (hl)
  15740.         jr      nz,l591b
  15741. l5916:
  15742.         inc     hl
  15743.         inc     de
  15744.         djnz    l590e
  15745.         ret
  15746. l591b:
  15747.         call    ERROR
  15748.         db      _InvType
  15749. l591f:
  15750.         ld      de,lfffc
  15751.         add     hl,de
  15752.         ld      d,(hl)
  15753.         dec     hl
  15754.         ld      e,(hl)
  15755.         dec     hl
  15756.         push    de
  15757.         ld      d,(hl)
  15758.         dec     hl
  15759.         ld      e,(hl)
  15760.         ld      (l7b58),de      ; Set value
  15761.         pop     hl
  15762.         call    l5287           ; Get name
  15763.         xor     a
  15764.         ld      (Envir1),a
  15765.         call    l6f7e
  15766. l593a:
  15767.         call    l5e84
  15768.         call    l5864
  15769.         jp      l661b
  15770. ;
  15771. ; Procedure ASSIGN(FileVar,String)
  15772. ;
  15773. l5943:
  15774.         call    l5a0c
  15775.         ld      hl,l1370
  15776.         cp      6
  15777.         jr      nz,l5955
  15778.         ld      hl,l136f
  15779.         call    l5955
  15780.         jr      l5989
  15781. l5955:
  15782.         push    hl
  15783.         call    StPUSH          ; Set PUSH HL
  15784.         call    l6f5e           ; Verify ,
  15785.         call    l5ed0
  15786.         pop     hl
  15787. l5960:
  15788.         call    l6f6e           ; Verify )
  15789.         jp      StCALL_         ; Set CALL <...>
  15790. ;
  15791. ; Procedure RENAME(FileVar,String)
  15792. ;
  15793. l5966:
  15794.         call    l5a0c
  15795.         ld      hl,l1ba5
  15796.         call    l5955
  15797.         jr      l5989
  15798. ;
  15799. ; Procedure ERASE(FileVar)
  15800. ;
  15801. l5971:
  15802.         call    l5a0c
  15803.         ld      hl,l1b93
  15804.         jr      l5960
  15805. ;
  15806. ; Procedure CHAIN(FileVar)
  15807. ;
  15808. l5979:
  15809.         ld      hl,l1beb
  15810.         jr      l5981
  15811. ;
  15812. ; Procedure EXECUTE(FileVar)
  15813. ;
  15814. l597e:
  15815.         ld      hl,l1bea
  15816. l5981:
  15817.         push    hl
  15818.         call    l5a0c
  15819. l5985:
  15820.         pop     hl
  15821. l5986:
  15822.         call    l5960
  15823. l5989:
  15824.         jp      l5abe
  15825. ;
  15826. ; Procedure SEEK(FileVar,Integer)
  15827. ;
  15828. l598c:
  15829.         call    l5a0c
  15830.         cp      6
  15831.         call    ErrZ
  15832.         db      _IllTxtFile
  15833.         ld      hl,l19d5
  15834.         cp      5
  15835.         jr      z,l599f
  15836.         ld      hl,l1b6f
  15837. l599f:
  15838.         push    hl
  15839.         call    StPUSH          ; Set PUSH HL
  15840.         call    l6f5e           ; Verify ,
  15841.         call    l5e97
  15842.         jr      l5985
  15843. ;
  15844. ; Procedure FLUSH(FileVar)
  15845. ;
  15846. l59ab:
  15847.         call    l5a0c
  15848.         cp      5
  15849.         call    ErrNZ
  15850.         db      _IllFileType
  15851.         ld      hl,l19a5
  15852.         jr      l5986
  15853. ;
  15854. ; Procedure RESET(FileVar,String)
  15855. ;
  15856. l59b9:
  15857.         ld      hl,l59fa
  15858.         jr      l59c1
  15859. ;
  15860. ; Procedure REWRITE(FileVar,String)
  15861. ;
  15862. l59be:
  15863.         ld      hl,l5a00
  15864. l59c1:
  15865.         push    hl
  15866.         call    l5a0c
  15867.         ld      a,(l7b5c)       ; Get type
  15868.         cp      _RecF
  15869.         jr      nz,l59d8
  15870.         ld      hl,(l7b5e)      ; Get lo set limit
  15871.         call    l5271           ; Load name
  15872.         ld      hl,(l7b6f)
  15873.         call    StLD.DE         ; Set LD DE,val16
  15874. l59d8:
  15875.         pop     hl
  15876.         jr      l59e1
  15877. ;
  15878. ; Procedure CLOSE(FileVar)
  15879. ;
  15880. l59db:
  15881.         call    l5a0c
  15882.         ld      hl,l5a06
  15883. l59e1:
  15884.         call    l6f6e           ; Verify )
  15885.         call    l59e9
  15886.         jr      l5989
  15887. l59e9:
  15888.         ld      a,(l7b5c)       ; Get type
  15889.         sub     _RecF
  15890.         add     a,a
  15891.         ld      e,a
  15892.         ld      d,0
  15893.         add     hl,de
  15894.         ld      e,(hl)
  15895.         inc     hl
  15896.         ld      d,(hl)
  15897.         ex      de,hl
  15898.         jp      StCALL_         ; Set CALL <...>
  15899. l59fa: ;reset procedures
  15900.         dw      l1811           ; Record file
  15901.         dw      l13ff           ; Text file
  15902.         dw      l1a70           ; Untyped file
  15903. l5a00: ;rewrite procedures
  15904.         dw      l1810
  15905.         dw      l13fe
  15906.         dw      l1a6f
  15907. l5a06: ;close procedures
  15908.         dw      l187a
  15909.         dw      l1469
  15910.         dw      l1ab0
  15911. l5a0c:
  15912.         call    l6f66           ; Verify (
  15913.         call    l5a17
  15914.         ret     z
  15915.         call    ERROR
  15916.         db      _FileVarExp
  15917. l5a17:
  15918.         call    l67b2
  15919.         scf
  15920.         ret     nz
  15921.         ld      a,(l7b5c)       ; Get type
  15922.         cp      _RecF
  15923.         jr      c,l5a2f
  15924.         cp      _String
  15925.         jr      nc,l5a2f
  15926.         call    l678b
  15927.         xor     a
  15928.         ld      a,(l7b5c)       ; Get back type
  15929.         ret
  15930. l5a2f:
  15931.         xor     a
  15932.         dec     a
  15933.         ret
  15934. ;
  15935. ; Procedure READLN(FileVar,Variables)
  15936. ;
  15937. l5a32:
  15938.         db      skip
  15939. ;
  15940. ; Procedure READ(FileVar,Variables)
  15941. ;
  15942. l5a33:
  15943.         xor     a
  15944.         ld      (l7ba3),a
  15945.         call    l6f1b           ; Test (
  15946.         jr      z,l5a41         ; Yeap
  15947.         call    l5aca
  15948.         jr      l5ab4
  15949. l5a41:
  15950.         call    l5a17 ;get type???
  15951.         jr      c,l5a63
  15952.         jr      nz,l5a5b
  15953.         cp      5 ;_RecF???
  15954.         jp      z,l5bd8
  15955.         cp      6 ;_TxtF???
  15956.         call    ErrNZ
  15957.         db      _NoUntypeFile
  15958.         ld      hl,l14a9
  15959.         call    StCALL_         ; Set CALL FILECHECK
  15960.         jr      l5aac
  15961. l5a5b:
  15962.         call    l678b
  15963.         call    l5aca
  15964.         jr      l5a69
  15965. l5a63:
  15966.         call    l5aca
  15967. l5a66:
  15968.         call    l677f
  15969. l5a69:
  15970.         ld      a,(l7b5c)       ; Get type
  15971.         cp      _String
  15972.         jr      c,l5a78
  15973.         cp      _Bool
  15974.         jr      z,l5a78
  15975.         cp      _Char+1
  15976.         jr      c,l5a7c
  15977. l5a78:
  15978.         call    ERROR
  15979.         db      _InvIO
  15980. l5a7c:
  15981.         cp      _String
  15982.         jr      nz,l5a8f
  15983.         ld      a,(l7b62)       ; Get length of type
  15984.         dec     a
  15985.         ld      h,a
  15986.         ld      l,6
  15987.         call    writeword_hl_addriy
  15988.         ld      hl,l168e
  15989.         jr      l5aa9
  15990. l5a8f:
  15991.         ld      hl,l1672
  15992.         cp      _Real
  15993.         jr      z,l5aa9
  15994.         ld      hl,l1644
  15995.         cp      _Char
  15996.         jr      z,l5aa9
  15997.         ld      hl,l164e
  15998.         ld      a,(l7b62)       ; Get length of type
  15999.         dec     a
  16000.         jr      nz,l5aa9
  16001.         ld      hl,l164d
  16002. l5aa9:
  16003.         call    StCALL_         ; Set CALL <read>
  16004. l5aac:
  16005.         call    l6f13           ; Test ,
  16006.         jr      z,l5a66         ; Yeap
  16007.         call    l6f6e           ; Verify )
  16008. l5ab4:
  16009.         ld      hl,l16ab
  16010. l5ab7:
  16011.         ld      a,(l7ba3)
  16012.         or      a
  16013.         call    nz,StCALL_      ; Set CALL NEWLINE
  16014. l5abe:
  16015.         ld      a,(l7b9e)       ; Get local options
  16016.         bit     _Iopt,a         ; Test $I+
  16017.         ret     z               ; Nope
  16018.         ld      hl,l201b
  16019.         jp      StCALL_         ; Set CALL CHECKIO
  16020. l5aca:
  16021.         ld      hl,l149b
  16022.         ld      a,(l7b9e)       ; Get local options
  16023.         bit     _Bopt,a         ; Test $B+
  16024.         jr      z,l5ae4         ; Nope
  16025.         ld      hl,l14cc
  16026.         ld      a,(l7ba3)
  16027.         or      a
  16028.         jr      z,l5ae4
  16029.         ld      hl,l14cb
  16030.         xor     a
  16031.         ld      (l7ba3),a
  16032. l5ae4:
  16033.         jp      StCALL_         ; Set CALL <read>
  16034. ;
  16035. ; Procedure WRITELN(FileVar,Variables)
  16036. ;
  16037. l5ae7:
  16038.         db      skip
  16039. ;
  16040. ; Procedure WRITE(FileVar,Variables)
  16041. ;
  16042. l5ae8:
  16043.         xor     a
  16044.         ld      (l7ba3),a
  16045.         call    l6f1b           ; Test (
  16046.         jr      z,l5afa         ; Yeap
  16047.         ld      hl,l149b
  16048.         call    StCALL_         ; Set CALL STDIO
  16049.         jp      l5bd2
  16050. l5afa:
  16051.         call    l5a17
  16052.         jr      c,l5b20
  16053.         jr      nz,l5b15
  16054.         cp      5
  16055.         jp      z,l5bdd
  16056.         cp      6
  16057.         call    ErrNZ
  16058.         db      _NoUntypeFile
  16059.         ld      hl,l14ba
  16060.         call    StCALL_         ; Set CALL CHECKWRFILE
  16061.         jp      l5bc9
  16062. l5b15:
  16063.         call    l620f
  16064.         ld      hl,l149b
  16065.         call    StCALL_         ; Set CALL STDIO
  16066.         jr      l5b4f
  16067. l5b20:
  16068.         ld      hl,l149b
  16069.         call    StCALL_         ; Set CALL STDIO
  16070. l5b26:
  16071.         call    GetLabType
  16072.         jr      nz,l5b4c
  16073.         ld      a,b
  16074.         cp      8 ;_String???
  16075.         jr      nz,l5b47
  16076.         ld      a,(ix+0)
  16077.         cp      ','
  16078.         jr      z,l5b3b
  16079.         cp      ')'
  16080.         jr      nz,l5b47
  16081. l5b3b:
  16082.         ld      hl,l17ba
  16083.         call    StCALL_         ; Set CALL IMSTRG
  16084.         call    StLen
  16085.         jp      l5bc9
  16086. l5b47:
  16087.         call    l6201
  16088.         jr      l5b4f
  16089. l5b4c:
  16090.         call    l5ee8
  16091. l5b4f:
  16092.         ld      a,b
  16093.         cp      8 ;0..7: _Array,_Record,_Set,_Ptr,_RecF,_TxtF,_UntF
  16094.         jr      c,l5b58 ;not a scalar type???
  16095.         cp      0dh ;element of a set???
  16096.         jr      c,l5b5c ;8..12: (_String excluded above),_Real,_Integ,_Bool,_Char
  16097. l5b58:
  16098.         call    ERROR
  16099.         db      _InvIO
  16100. l5b5c:
  16101.         cp      0ch ;_Char???
  16102.         jr      nz,l5b6a
  16103.         call    l6f0b           ; Test :
  16104.         jr      nz,l5ba6
  16105.         call    l5edd
  16106.         jr      l5b72
  16107. l5b6a:
  16108.         call    l6148
  16109.         call    l6f0b           ; Test :
  16110.         jr      nz,l5b8b
  16111. l5b72:
  16112.         push    bc
  16113.         call    l5e97
  16114.         pop     bc
  16115.         ld      a,b
  16116.         cp      9 ;_Real???
  16117.         jr      nz,l5ba6
  16118.         call    l6f0b           ; Test :
  16119.         jr      nz,l5b9d
  16120.         push    bc
  16121.         call    StPUSH          ; Set PUSH HL
  16122.         call    l5e97
  16123.         pop     bc
  16124.         jr      l5ba6
  16125. l5b8b:
  16126.         ld      hl,l0000
  16127.         ld      a,b
  16128.         cp      9 ;_Real???
  16129.         jr      nz,l5b95
  16130.         ld      l,12h
  16131. l5b95:
  16132.         call    StLD.HL         ; Set LD HL,val16
  16133.         ld      a,b
  16134.         cp      9 ;_Real???
  16135.         jr      nz,l5ba6
  16136. l5b9d:
  16137.         call    StPUSH          ; Set PUSH HL
  16138.         ld      hl,lffff
  16139.         call    StLD.HL         ; Set LD HL,val16
  16140. l5ba6:
  16141.         ld      a,b
  16142.         ld      hl,l17aa
  16143.         cp      8 ;_String???
  16144.         jr      z,l5bc6
  16145.         ld      hl,l1779
  16146.         cp      9 ;_Real???
  16147.         jr      z,l5bc6
  16148.         ld      hl,l1726
  16149.         cp      0ah ;_Integ???
  16150.         jr      z,l5bc6
  16151.         ld      hl,l178b
  16152.         cp      0bh ;_Bool???
  16153.         jr      z,l5bc6
  16154.         ld      hl,l1722
  16155. l5bc6:
  16156.         call    StCALL_         ; Set CALL <wrtype>
  16157. l5bc9:
  16158.         call    l6f13           ; Test ,
  16159.         jp      z,l5b26         ; Yeap
  16160.         call    l6f6e           ; Verify )
  16161. l5bd2:
  16162.         ld      hl,l17cd
  16163.         jp      l5ab7
  16164. l5bd8:
  16165.         ld      hl,l18b6
  16166.         jr      l5be0
  16167. l5bdd:
  16168.         ld      hl,l18dc
  16169. l5be0:
  16170.         ld      (l7ba7),hl
  16171.         ld      a,(l7ba3)
  16172.         or      a
  16173.         call    ErrNZ
  16174.         db      _MustTextFile
  16175.         ld      hl,l18a4
  16176.         call    StCALL_         ; Set CALL PREPRECWR
  16177.         ld      hl,(l7b5e)      ; Get lo set limit
  16178.         call    l5271           ; Load name
  16179. l5bf7:
  16180.         call    l6f13           ; Test ,
  16181.         jr      nz,l5c10        ; Nope
  16182.         call    SavEnv2
  16183.         call    l677f
  16184.         call    RestEnv2
  16185.         call    l58c5
  16186.         ld      hl,(l7ba7)
  16187.         call    StCALL_         ; Set CALL <write>
  16188.         jr      l5bf7
  16189. l5c10:
  16190.         call    l6f6e           ; Verify )
  16191.         jp      l5abe
  16192. ;
  16193. ; Procedure BLOCKREAD(FileVar,Variable,Integer[,Integer])
  16194. ;
  16195. l5c16:
  16196.         ld      hl,l1af1
  16197.         ld      de,l1abe
  16198.         jr      l5c24
  16199. ;
  16200. ; Procedure BLOCKWRITE(FileVar,Variable,Integer[,Integer])
  16201. ;
  16202. l5c1e:
  16203.         ld      hl,l1aed
  16204.         ld      de,l1aba
  16205. l5c24:
  16206.         push    hl
  16207.         push    de
  16208.         call    l5a0c
  16209.         cp      7
  16210.         call    ErrNZ
  16211.         db      _UntFileExp
  16212.         call    StPUSH          ; Set PUSH HL
  16213.         call    l6f5e           ; Verify ,
  16214.         call    l677f
  16215.         call    StPUSH          ; Set PUSH HL
  16216.         call    l6f5e           ; Verify ,
  16217.         call    l5e97
  16218.         call    l6f13           ; Test ,
  16219.         pop     de
  16220.         pop     hl
  16221.         jr      z,l5c4b         ; Yeap
  16222.         push    de
  16223.         jr      l5c63
  16224. l5c4b:
  16225.         push    hl
  16226.         call    StPUSH          ; Set PUSH HL
  16227.         call    l677f
  16228.         ld      a,(l7b5c)       ; Get type
  16229.         cp      _Integ
  16230.         jr      nz,l5c5f
  16231.         ld      a,(l7b62)       ; Get length of type
  16232.         dec     a
  16233.         jr      nz,l5c63
  16234. l5c5f:
  16235.         call    ERROR
  16236.         db      _IntVarExp
  16237. l5c63:
  16238.         jp      l5985
  16239. ;
  16240. ; Procedure DELETE(String,Integer,Integer)
  16241. ;
  16242. l5c66:
  16243.         call    l6f66           ; Verify (
  16244.         call    l5cad
  16245.         call    StPUSH          ; Set PUSH HL
  16246.         call    l6f5e           ; Verify ,
  16247.         call    l5e97
  16248.         call    StPUSH          ; Set PUSH HL
  16249.         call    l6f5e           ; Verify ,
  16250.         call    l5e97
  16251.         ld      hl,l08f3        ; Set DELETE
  16252. l5c81:
  16253.         call    l6f6e           ; Verify )
  16254.         jp      StCALL_         ; Set CALL <string_procedure>
  16255. ;
  16256. ; Procedure INSERT(String,String,Integer)
  16257. ;
  16258. l5c87:
  16259.         call    l6f66           ; Verify (
  16260.         call    l5ed0
  16261.         call    l6f5e           ; Verify ,
  16262.         call    l5cad
  16263.         call    StPUSH          ; Set PUSH HL
  16264.         ld      a,(l7b62)       ; Get length of type
  16265.         dec     a
  16266.         ld      h,a
  16267.         ld      l,6
  16268.         push    hl
  16269.         call    l6f5e           ; Verify ,
  16270.         call    l5e97
  16271.         pop     hl
  16272.         call    writeword_hl_addriy
  16273.         ld      hl,l0920
  16274.         jr      l5c81           ; Set INSERT
  16275. l5cad:
  16276.         call    l677f
  16277.         ld      a,(l7b5c)       ; Get type
  16278.         cp      _String
  16279.         ret     z
  16280.         call    ERROR
  16281.         db      _StrgVarExp
  16282. ;
  16283. ; Procedure STR(Num,String)
  16284. ;
  16285. l5cba:
  16286.         call    l6f66           ; Verify (
  16287.         call    l5ea2
  16288.         call    l6148
  16289.         call    l6f0b           ; Test :
  16290.         jr      nz,l5ce4
  16291.         push    bc
  16292.         call    l5e97
  16293.         call    StPUSH          ; Set PUSH HL
  16294.         pop     bc
  16295.         ld      a,b
  16296.         cp      0ah
  16297.         jr      z,l5d02
  16298.         call    l6f0b           ; Test :
  16299.         jr      nz,l5cf9
  16300.         push    bc
  16301.         call    l5e97
  16302.         call    StPUSH          ; Set PUSH HL
  16303.         pop     bc
  16304.         jr      l5d02
  16305. l5ce4:
  16306.         ld      hl,l0000
  16307.         ld      a,b
  16308.         cp      0ah
  16309.         jr      z,l5cee
  16310.         ld      l,12h
  16311. l5cee:
  16312.         call    StLD.HL         ; Set LD HL,val16
  16313.         call    StPUSH          ; Set PUSH HL
  16314.         ld      a,b
  16315.         cp      0ah
  16316.         jr      z,l5d02
  16317. l5cf9:
  16318.         ld      hl,lffff
  16319.         call    StLD.HL         ; Set LD HL,val16
  16320.         call    StPUSH          ; Set PUSH HL
  16321. l5d02:
  16322.         call    l6f5e           ; Verify ,
  16323.         push    bc
  16324.         call    l5cad
  16325.         ld      a,(l7b62)       ; Get length of type
  16326.         dec     a
  16327.         ld      h,a
  16328.         ld      l,6
  16329.         call    writeword_hl_addriy
  16330.         pop     bc
  16331.         ld      hl,l1ebe
  16332.         ld      a,b
  16333.         cp      0ah
  16334.         jr      z,l5d1f
  16335.         ld      hl,l1ebd
  16336. l5d1f:
  16337.         jp      l5c81
  16338. ;
  16339. ; Procedure VAL(String,Integer,Integer)
  16340. ;
  16341. l5d22:
  16342.         call    l6f66           ; Verify (
  16343.         call    l5ed0
  16344.         call    l6f5e           ; Verify ,
  16345.         call    l677f
  16346.         ld      a,(l7b5c)       ; Get type
  16347.         cp      _Real
  16348.         jr      z,l5d45
  16349.         cp      _Integ
  16350.         jr      nz,l5d41
  16351.         ld      a,(l7b62)       ; Get length of type
  16352.         dec     a
  16353.         ld      a,0ah
  16354.         jr      nz,l5d45
  16355. l5d41:
  16356.         call    ERROR
  16357.         db      _NumVarExp
  16358. l5d45:
  16359.         push    af
  16360.         call    StPUSH          ; Set PUSH HL
  16361.         call    l6f5e           ; Verify ,
  16362.         call    l677f
  16363.         ld      a,(l7b5c)       ; Get type
  16364.         cp      _Integ
  16365.         jr      nz,l5d5c
  16366.         ld      a,(l7b62)       ; Get length of type
  16367.         dec     a
  16368.         jr      nz,l5d60
  16369. l5d5c:
  16370.         call    ERROR
  16371.         db      _IntVarExp
  16372. l5d60:
  16373.         pop     af
  16374.         ld      hl,l1ef4
  16375.         cp      0ah
  16376.         jr      z,l5d1f
  16377.         ld      hl,l1ef3
  16378.         jr      l5d1f
  16379. ;
  16380. ; Procedure GOTOXY(Integer,Integer)
  16381. ;
  16382. l5d6d:
  16383.         call    l6f66           ; Verify (
  16384.         call    l5e97
  16385.         ld      hl,l1fdb
  16386. l5d76:
  16387.         push    hl
  16388.         call    StPUSH          ; Set PUSH HL
  16389.         call    l6f5e           ; Verify ,
  16390.         call    l5e97
  16391.         pop     hl
  16392.         jr      l5db1
  16393. ;
  16394. ; Procedure RANDOMIZE
  16395. ;
  16396. l5d83:
  16397.         ld      hl,l1f48
  16398.         jp      StCALL_         ; Set CALL RANDOMIZE
  16399. ;
  16400. ; Procedure DELAY(Integer)
  16401. ;
  16402. l5d89:
  16403.         call    l6f66           ; Verify (
  16404.         call    l5e97
  16405.         ld      hl,l021d
  16406.         jr      l5db1           ; Set call to delay
  16407. ;
  16408. ; Procedure GETMEM(Variable,Integer)
  16409. ;
  16410. l5d94:
  16411.         call    l5de3
  16412.         call    l6f5e           ; Verify ,
  16413.         call    l5e97
  16414.         jr      l5dae
  16415. ;
  16416. ; Procedure NEW(Variable)
  16417. ;
  16418. l5d9f:
  16419.         call    l5de3
  16420.         ld      hl,(l7b5e)      ; Get lo set limit
  16421.         call    l5271           ; Load name
  16422.         ld      hl,(l7b6f)
  16423.         call    StLD.HL         ; Set LD HL,val16
  16424. l5dae:
  16425.         ld      hl,l1ce5
  16426. l5db1:
  16427.         jp      l5960
  16428. ;
  16429. ; Procedure FREEMEM(Variable,Integer)
  16430. ;
  16431. l5db4:
  16432.         call    l5de3
  16433.         call    l6f5e           ; Verify ,
  16434.         call    l5e97
  16435.         jr      l5dce
  16436. ;
  16437. ; Procedure DISPOSE(Variable)
  16438. ;
  16439. l5dbf:
  16440.         call    l5de3
  16441.         ld      hl,(l7b5e)      ; Get lo set limit
  16442.         call    l5271           ; Load name
  16443.         ld      hl,(l7b6f)
  16444.         call    StLD.HL         ; Set LD HL,val16
  16445. l5dce:
  16446.         ld      hl,l1d7a
  16447.         jp      l5960
  16448. ;
  16449. ; Procedure MARK(Variable)
  16450. ;
  16451. l5dd4:
  16452.         ld      hl,l1ea3
  16453.         jr      l5ddc
  16454. ;
  16455. ; Procedure RELEASE(Variable)
  16456. ;
  16457. l5dd9:
  16458.         ld      hl,l1eab
  16459. l5ddc:
  16460.         push    hl
  16461.         call    l5de9
  16462.         pop     hl
  16463.         jr      l5db1
  16464. l5de3:
  16465.         call    l5de9
  16466.         jp      StPUSH          ; Set PUSH HL
  16467. l5de9:
  16468.         call    l6f66           ; Verify (
  16469.         call    l677f
  16470.         ld      a,(l7b5c)       ; Get type
  16471.         cp      _Ptr
  16472.         ret     z
  16473.         call    ERROR
  16474.         db      _PtrVarExp
  16475. ;
  16476. ; Procedure OVRDRIVE(Integer)
  16477. ;
  16478. l5df9:
  16479.         call    l6f66           ; Verify (
  16480.         call    l5e97
  16481.         ld      hl,l1cdb
  16482.         jp      l5960
  16483. ;
  16484. ; Procedure MOVE(Integer,Integer,Integer)
  16485. ;
  16486. l5e05:
  16487.         call    l6f66           ; Verify (
  16488.         call    l677f
  16489.         call    StPUSH          ; Set PUSH HL
  16490.         call    l6f5e           ; Verify ,
  16491.         call    l677f
  16492.         ld      hl,l1f64
  16493.         jp      l5d76
  16494. ;
  16495. ; Procedure FILLCHAR(Integer,Integer,Byte)
  16496. ;
  16497. l5e1a:
  16498.         call    l6f66           ; Verify (
  16499.         call    l677f
  16500.         call    StPUSH          ; Set PUSH HL
  16501.         call    l6f5e           ; Verify ,
  16502.         call    l5e97
  16503.         call    StPUSH          ; Set PUSH HL
  16504.         call    l6f5e           ; Verify ,
  16505.         call    l5ebb
  16506.         ld      hl,l1f4e
  16507.         jp      l5db1
  16508. ;
  16509. ; Procedure CRTINIT
  16510. ;
  16511. l5e38:
  16512.         ld      hl,l030a
  16513.         jr      l5e45           ; Set call to lead in
  16514. ;
  16515. ; Procedure CRTEXIT
  16516. ;
  16517. l5e3d:
  16518.         ld      hl,l0310
  16519.         jr      l5e45           ; Set call to lead out
  16520. ;
  16521. ; Procedure CLRSCR
  16522. ;
  16523. l5e42:
  16524.         ld      hl,l023e        ; Set call to clear screen
  16525. l5e45:
  16526.         jp      StCALL_         ; Set CALL <crt_procedure>
  16527. ;
  16528. ; Procedure CLREOL
  16529. ;
  16530. l5e48:
  16531.         ld      hl,l0299        ; Set call to clear to end of line
  16532.         jr      l5e45
  16533. ;
  16534. ; Procedure NORMVIDEO or HIGHVIDEO
  16535. ;
  16536. l5e4d:
  16537.         ld      hl,setnormvideo ; Set call to normal video
  16538.         jr      l5e45
  16539. ;
  16540. ; Procedure LOWVIDEO
  16541. ;
  16542. l5e52:
  16543.         ld      hl,setlowvideo  ; Set call to low video
  16544.         jr      l5e45
  16545. ;
  16546. ; Procedure INSLINE
  16547. ;
  16548. l5e57:
  16549.         ld      hl,l0262        ; Set call to insert line
  16550.         jr      l5e45
  16551. ;
  16552. ; Procedure DELLINE
  16553. ;
  16554. l5e5c:
  16555.         ld      hl,l0259        ; Set call to delete line
  16556.         jr      l5e45
  16557. ;
  16558. ; Procedure EXIT
  16559. ;
  16560. l5e61:
  16561.         ld      de,OS           ; Set call to exit
  16562.         jp      l5639
  16563. ;
  16564. ; Procedure HALT
  16565. ;
  16566. l5e67:
  16567.         ld      hl,l20d4
  16568.         jp      StJP_           ; Set call to HALT program
  16569. ;
  16570. ; Procedure PORT(Integer,Integer)
  16571. ;
  16572. l5e6d:
  16573.         call    l5e8e
  16574.         call    StImm           ; Set sequence
  16575.         db      a_L26
  16576. s_I26:
  16577.         POP     BC
  16578.         OUT     (C),L
  16579. a_L26   equ     $-s_I26
  16580.         ret
  16581. ;
  16582. ; Procedure STACKPTR
  16583. ;
  16584. l5e78:
  16585.         call    l6f7e
  16586.         call    l5e97
  16587.         call    StImm   ; Set LD SP,HL
  16588.         db      a_L27
  16589. s_I27:
  16590.         LD      SP,HL
  16591. a_L27   equ     $-s_I27
  16592.         ret
  16593.  
  16594. l5e84:
  16595.         call    l6d2a           ; Save environment
  16596.         call    l5ee8
  16597.         call    RestEnv1                ; Get back environment
  16598.         ret
  16599. l5e8e:
  16600.         call    l65d5
  16601.         call    l6f7e
  16602.         call    StPUSH          ; Set PUSH HL
  16603. l5e97:
  16604.         call    l5ee8
  16605.         ld      a,b
  16606.         cp      0ah
  16607.         ret     z
  16608.         call    ERROR
  16609.         db      _IntExpr
  16610. l5ea2:
  16611.         call    l5ee8
  16612.         ld      a,b
  16613.         cp      0ah
  16614.         ret     z
  16615.         cp      9
  16616.         ret     z
  16617.         call    ERROR
  16618.         db      _NumExprExp
  16619. l5eb0:
  16620.         call    l5ee8
  16621.         ld      a,b
  16622.         cp      0bh
  16623.         ret     z
  16624.         call    ERROR
  16625.         db      _BoolExp
  16626. l5ebb:
  16627.         call    l5ee8
  16628. l5ebe:
  16629.         ld      a,b
  16630.         cp      0ah
  16631.         ret     nc
  16632.         cp      8
  16633.         call    ErrNZ
  16634.         db      _SimpExpr
  16635.         ld      b,0ch
  16636.         ld      hl,l0996
  16637.         jp      StCALL_         ; Set CALL CHECKASSIGNMENT
  16638. l5ed0:
  16639.         call    l5ee8
  16640.         ld      a,b
  16641.         cp      8
  16642.         ret     z
  16643.         cp      0ch
  16644.         call    ErrNZ
  16645.         db      _StrgExpExp
  16646. l5edd:
  16647.         ld      b,8
  16648.         call    StImm           ; Set sequence
  16649.         db      a_L28
  16650. s_I28:
  16651.         LD      H,L
  16652.         LD      L,1
  16653.         PUSH    HL
  16654. a_L28   equ     $-s_I28
  16655.         ret
  16656. l5ee8:
  16657.         call    l5f98
  16658. l5eeb:
  16659.         push    bc
  16660.         call    FndTabStr               ; Find relation
  16661.         db      1
  16662.         dw      l7625
  16663.         pop     bc
  16664.         ret     nz              ; Nope
  16665.         ld      a,(hl)          ; Get code
  16666.         inc     a               ; Test IN
  16667.         jr      z,l5f34         ; Yeap
  16668.         dec     a
  16669.         push    af
  16670.         push    bc
  16671.         call    l6148
  16672.         ld      hl,(l7b8b)
  16673.         push    hl
  16674.         call    l5f98
  16675.         pop     hl
  16676.         ld      (l7b8d),hl
  16677.         pop     de
  16678.         call    l6160
  16679.         pop     af
  16680.         ld      e,a
  16681.         ld      d,0
  16682.         ld      hl,l5f68
  16683.         add     hl,de
  16684.         ld      a,b
  16685.         cp      3
  16686.         jr      z,l5f28
  16687.         inc     hl
  16688.         inc     hl
  16689.         cp      9
  16690.         jr      z,l5f28
  16691.         inc     hl
  16692.         inc     hl
  16693.         cp      8
  16694.         jr      z,l5f28
  16695.         inc     hl
  16696.         inc     hl
  16697. l5f28:
  16698.         ld      e,(hl)
  16699.         inc     hl
  16700.         ld      d,(hl)
  16701.         ld      a,d
  16702.         or      e
  16703.         call    ErrZ
  16704.         db      _IllOps
  16705.         ex      de,hl
  16706.         jr      l5f62
  16707. l5f34:
  16708.         ld      a,b
  16709.         cp      0ah
  16710.         jr      nc,l5f47
  16711.         cp      8
  16712.         call    ErrNZ
  16713.         db      _IllOps
  16714.         ld      hl,l0996
  16715.         call    StCALL_         ; Set CALL CHECKASSIGNMENT
  16716.         ld      b,0ch
  16717. l5f47:
  16718.         push    bc
  16719.         call    StPUSH          ; Set PUSH HL
  16720.         call    l5f98
  16721.         pop     de
  16722.         ld      a,b
  16723.         cp      3
  16724.         call    ErrNZ
  16725.         db      _IllOps
  16726.         ld      a,c
  16727.         or      a
  16728.         jr      z,l5f5f
  16729.         cp      d
  16730.         call    ErrNZ
  16731.         db      _InvType
  16732. l5f5f:
  16733.         ld      hl,l134f
  16734. l5f62:
  16735.         call    StCALL_         ; Set CALL <set>
  16736.         ld      b,0bh
  16737.         ret
  16738. l5f68:
  16739.         dw      l12e1
  16740.         dw      l0688           ; Real =
  16741.         dw      l068d           ; String =
  16742.         dw      l067f           ; Integer =
  16743.         dw      l12dd
  16744.         dw      l069b           ; Real <>
  16745.         dw      l06a0           ; String <>
  16746.         dw      l0692           ; Integer <>
  16747.         dw      l1300
  16748.         dw      l06ae           ; Real >=
  16749.         dw      l06b3           ; String >=
  16750.         dw      l06a5           ; Integer >=
  16751.         dw      l12fc
  16752.         dw      l06c2           ; Real <=
  16753.         dw      l06c7           ; String <=
  16754.         dw      l06b8           ; Integer <=
  16755.         dw      l0000
  16756.         dw      l06d6           ; Real >
  16757.         dw      l06db           ; String >
  16758.         dw      l06cc           ; Integer >
  16759.         dw      l0000
  16760.         dw      l06e9           ; Real <
  16761.         dw      l06ee           ; String <
  16762.         dw      l06e0           ; Integer <
  16763. l5f98:
  16764.         call    l6054
  16765. l5f9b:
  16766.         push    bc
  16767.         call    FndTabStr               ; Find operator
  16768.         db      1
  16769.         dw      l7619
  16770.         pop     bc
  16771.         ret     nz              ; Nope
  16772.         ld      a,b
  16773.         cp      4
  16774.         call    ErrZ
  16775.         db      _IllOps
  16776.         ld      a,(hl)          ; Get operator
  16777.         push    af
  16778.         push    bc
  16779.         call    l6148
  16780.         call    l6054
  16781.         pop     de
  16782.         pop     af              ; Get back operator
  16783.         push    af
  16784.         or      a               ; Test +
  16785.         jr      nz,l5fc9        ; Nope
  16786.         ld      a,b
  16787.         cp      0ch
  16788.         jr      nz,l5fc9
  16789.         call    StImm           ; Set sequence
  16790.         db      a_L29
  16791. s_I29:
  16792.         LD      H,L
  16793.         LD      L,1
  16794.         PUSH    HL
  16795. a_L29   equ     $-s_I29
  16796.         ld      b,8
  16797. l5fc9:
  16798.         call    l6160
  16799.         pop     af              ; Get back operator
  16800.         cp      2               ; Test -
  16801.         jr      nc,l601b        ; Nope, OR or XOR
  16802.         push    af
  16803.         ld      a,b
  16804.         ld      hl,l1318
  16805.         ld      de,l1326
  16806.         cp      3
  16807.         jr      z,l6006
  16808.         ld      hl,l09e9        ; Set add reals
  16809.         ld      de,l09f2        ; Set subtract reals
  16810.         cp      9
  16811.         jr      z,l6006
  16812.         cp      8
  16813.         jr      z,l6010
  16814.         cp      0ah
  16815.         call    ErrNZ
  16816.         db      _IllOps
  16817.         pop     af
  16818.         dec     a
  16819.         jr      z,l5ffc
  16820.         call    StImm           ; Set ADD HL,DE
  16821.         db      a_L30
  16822. s_I30:
  16823.         ADD     HL,DE
  16824. a_L30   equ     $-s_I30
  16825.         jr      l5f9b
  16826. l5ffc:
  16827.         call    StImm           ; Set sequence
  16828.         db      a_L31
  16829. s_I31:
  16830.         EX      DE,HL
  16831.         OR      A
  16832.         SBC     HL,DE
  16833. a_L31   equ     $-s_I31
  16834.         jr      l5f9b
  16835. l6006:
  16836.         pop     af
  16837.         dec     a
  16838.         jr      nz,l600b
  16839.         ex      de,hl
  16840. l600b:
  16841.         call    StCALL_         ; Set CALL <string>
  16842.         jr      l5f9b
  16843. l6010:
  16844.         pop     af
  16845.         dec     a
  16846.         call    ErrZ
  16847.         db      _IllOps
  16848.         ld      hl,l083d
  16849.         jr      l600b           ; Set add two strings
  16850. l601b:
  16851.         ld      a,b
  16852.         jr      nz,l6039        ; Must be XOR
  16853.         cp      0bh
  16854.         jr      z,l602f
  16855.         cp      0ah
  16856.         call    ErrNZ
  16857.         db      _IllOps
  16858.         call    StImm           ; Set OR
  16859.         db      a_L32
  16860. s_I32:
  16861.         LD      A,H
  16862.         OR      D
  16863.         LD      H,A
  16864. a_L32   equ     $-s_I32
  16865. l602f:
  16866.         call    StImm           ; Set OR
  16867.         db      a_L33
  16868. s_I33:
  16869.         LD      A,L
  16870.         OR      E
  16871.         LD      L,A
  16872. a_L33   equ     $-s_I33
  16873.         jp      l5f9b
  16874. l6039:
  16875.         cp      0bh
  16876.         jr      z,l604a
  16877.         cp      0ah
  16878.         call    ErrNZ
  16879.         db      _IllOps
  16880.         call    StImm           ; Set XOR
  16881.         db      a_L34
  16882. s_I34:
  16883.         LD      A,H
  16884.         XOR     D
  16885.         LD      H,A
  16886. a_L34   equ     $-s_I34
  16887. l604a:
  16888.         call    StImm           ; Set XOR
  16889.         db      a_L35
  16890. s_I35:
  16891.         LD      A,L
  16892.         XOR     E
  16893.         LD      L,A
  16894. a_L35   equ     $-s_I35
  16895.         jp      l5f9b
  16896. l6054:
  16897.         call    l60e9
  16898. l6057:
  16899.         push    bc
  16900.         call    FndTabStr               ; Find operator
  16901.         db      1
  16902.         dw      l7600
  16903.         pop     bc
  16904.         ret     nz              ; Nope
  16905.         ld      a,b
  16906.         cp      4
  16907.         call    ErrZ
  16908.         db      _IllOps
  16909.         ld      a,(hl)          ; Get operator
  16910.         push    af
  16911.         push    bc
  16912.         call    l6148
  16913.         call    l60e9
  16914.         pop     de
  16915.         pop     af              ; Get back operator
  16916.         push    af
  16917.         dec     a               ; Test /
  16918.         jr      nz,l6083        ; Nope
  16919.         ld      a,b
  16920.         cp      0ah
  16921.         jr      nz,l6083
  16922.         ld      hl,l1008
  16923.         call    StCALL_         ; Set CALL INT_TO_FLP
  16924.         ld      b,9
  16925. l6083:
  16926.         call    l6160
  16927.         pop     af              ; Get back operator
  16928.         ld      e,a
  16929.         ld      a,b
  16930.         inc     e               ; Test *
  16931.         dec     e
  16932.         jr      nz,l60a9        ; Nope
  16933.         ld      hl,l1333
  16934.         cp      3
  16935.         jr      z,l60a4
  16936.         ld      hl,l06f5        ; Set integer multiply
  16937.         cp      0ah
  16938.         jr      z,l60a4
  16939.         ld      hl,l09fa        ; Set real multiply
  16940. l609e:
  16941.         cp      9
  16942.         call    ErrNZ
  16943.         db      _IllOps
  16944. l60a4:
  16945.         call    StCALL_         ; Set CALL <real>
  16946.         jr      l6057
  16947. l60a9:
  16948.         ld      hl,l09ff        ; Set real division
  16949.         dec     e               ; Test /
  16950.         jr      z,l609e         ; Yeap
  16951.         dec     e               ; Test AND
  16952.         jr      nz,l60cc        ; Nope
  16953.         cp      0bh
  16954.         jr      z,l60c3
  16955.         cp      0ah
  16956.         call    ErrNZ
  16957.         db      _IllOps
  16958.         call    StImm           ; Set AND
  16959.         db      a_L36
  16960. s_I36:
  16961.         LD      A,H
  16962.         AND     D
  16963.         LD      H,A
  16964. a_L36   equ     $-s_I36
  16965. l60c3:
  16966.         call    StImm           ; Set AND
  16967.         db      a_L37
  16968. s_I37:
  16969.         LD      A,L
  16970.         AND     E
  16971.         LD      L,A
  16972. a_L37   equ     $-s_I37
  16973.         jr      l6057
  16974. l60cc:
  16975.         cp      0ah
  16976.         call    ErrNZ
  16977.         db      _IllOps
  16978.         ld      hl,l070f        ; Set integer DIV
  16979.         dec     e               ; Test DIV
  16980.         jr      z,l60a4         ; Yeap
  16981.         ld      hl,l0745        ; Set integer MOD
  16982.         dec     e               ; Test MOD
  16983.         jr      z,l60a4
  16984.         ld      hl,l074e        ; Set SHL
  16985.         dec     e               ; Test SHL
  16986.         jr      z,l60a4
  16987.         ld      hl,l0756        ; Set SHR
  16988.         jr      l60a4
  16989. l60e9:
  16990.         call    FindStr         ; Find NOT
  16991.         dw      l7579
  16992.         jr      nz,l6112        ; Nope
  16993.         call    l6112
  16994.         ld      a,b
  16995.         cp      0ah
  16996.         jr      z,l6107
  16997.         cp      0bh
  16998.         call    ErrNZ
  16999.         db      _IllOps
  17000.         call    StImm           ; Set sequence
  17001.         db      a_L38
  17002. s_I38:
  17003.         LD      A,L
  17004.         XOR     1
  17005.         LD      L,A
  17006. a_L38   equ     $-s_I38
  17007.         ret
  17008. l6107:
  17009.         call    StImm           ; Set sequence
  17010.         db      a_L39
  17011. s_I39:
  17012.         LD      A,L
  17013.         CPL
  17014.         LD      L,A
  17015.         LD      A,H
  17016.         CPL
  17017.         LD      H,A
  17018. a_L39   equ     $-s_I39
  17019.         ret
  17020. l6112:
  17021.         ld      a,(l7ba1)
  17022.         push    af
  17023.         call    GetSign
  17024.         ld      a,e
  17025.         ld      (l7ba1),a
  17026.         call    l621d
  17027.         ld      a,(l7ba1)
  17028.         ld      e,a
  17029.         call    ChkNumSign
  17030.         jr      z,l6143
  17031.         ld      a,b
  17032.         cp      0ah
  17033.         jr      nz,l613b
  17034.         call    StImm           ; Set sequence
  17035.         db      a_L40
  17036. s_I40:
  17037.         LD      A,L
  17038.         CPL
  17039.         LD      L,A
  17040.         LD      A,H
  17041.         CPL
  17042.         LD      H,A
  17043.         INC     HL
  17044. a_L40   equ     $-s_I40
  17045.         jr      l6143
  17046. l613b:
  17047.         call    StImm           ; Set sequence
  17048.         db      a_L41
  17049. s_I41:
  17050.         LD      A,B
  17051.         XOR     80H
  17052.         LD      B,A
  17053. a_L41   equ     $-s_I41
  17054. l6143:
  17055.         pop     af
  17056.         ld      (l7ba1),a
  17057.         ret
  17058. l6148:
  17059.         ld      a,b
  17060.         cp      0ah
  17061.         jr      nc,l615d
  17062.         cp      4
  17063.         jr      z,l615d
  17064.         cp      8
  17065.         ret     z
  17066.         cp      3
  17067.         ret     z
  17068.         call    StImm           ; Set sequence
  17069.         db      a_L42
  17070. s_I42:
  17071.         PUSH    BC
  17072.         PUSH    DE
  17073. a_L42   equ     $-s_I42
  17074. l615d:
  17075.         jp      StPUSH          ; Set PUSH HL
  17076. l6160:
  17077.         ld      a,d
  17078.         cp      9
  17079.         jr      nz,l6174
  17080.         ld      a,b
  17081.         cp      0ah
  17082.         jr      nz,l6187
  17083.         ld      hl,l1008
  17084.         call    StCALL_         ; Set CALL INT_TO_FLP
  17085.         ld      b,9
  17086.         jr      l6187
  17087. l6174:
  17088.         cp      8
  17089.         jr      nz,l6187
  17090.         ld      a,b
  17091.         cp      0ch
  17092.         jr      nz,l6187
  17093.         call    StImm           ; Set sequence
  17094.         db      a_L43
  17095. s_I43:
  17096.         LD      H,L
  17097.         LD      L,1
  17098.         PUSH    HL
  17099. a_L43   equ     $-s_I43
  17100.         ld      b,8
  17101. l6187:
  17102.         ld      a,b
  17103.         cp      9
  17104.         jr      nz,l6193
  17105.         call    StImm           ; Set EXX
  17106.         db      a_L44
  17107. s_I44:
  17108.         EXX
  17109. a_L44   equ     $-s_I44
  17110.         jr      l61a4
  17111. l6193:
  17112.         cp      8
  17113.         jr      nz,l61a4
  17114.         ld      a,d
  17115.         cp      0ch
  17116.         jr      nz,l61a4
  17117.         ld      hl,l09a2
  17118.         call    StCALL_         ; Set CALL CHR_TO_STRG
  17119.         ld      d,8
  17120. l61a4:
  17121.         ld      a,d
  17122.         cp      0ah
  17123.         jr      z,l61bc
  17124.         jr      nc,l61ce
  17125.         cp      4
  17126.         jr      z,l61ce
  17127.         cp      9
  17128.         jr      c,l61d3
  17129.         call    StImm           ; Set sequence
  17130.         db      a_L45
  17131. s_I45:
  17132.         POP     HL
  17133.         POP     DE
  17134.         POP     BC
  17135. a_L45   equ     $-s_I45
  17136.         jr      l61d3
  17137. l61bc:
  17138.         ld      a,b
  17139.         cp      9
  17140.         jr      nz,l61ce
  17141.         call    StPOP           ; Set POP HL
  17142.         ld      hl,l1008
  17143.         call    StCALL_         ; Set CALL INT_TO_FLP
  17144.         ld      d,9
  17145.         jr      l61d3
  17146. l61ce:
  17147.         call    StImm           ; Set POP DE
  17148.         db      a_L46
  17149. s_I46:
  17150.         POP     DE
  17151. a_L46   equ     $-s_I46
  17152. l61d3:
  17153.         ld      a,b
  17154.         cp      d
  17155.         call    ErrNZ
  17156.         db      _InvType
  17157.         cp      3
  17158.         jr      nz,l61ea
  17159.         ld      a,e
  17160.         cp      c
  17161.         ret     z
  17162.         or      a
  17163.         ret     z
  17164.         ld      a,c
  17165.         ld      c,e
  17166.         or      a
  17167.         ret     z
  17168.         call    ERROR
  17169.         db      _InvType
  17170. l61ea:
  17171.         cp      4
  17172.         ret     nz
  17173.         ld      hl,(l7b8b)
  17174.         ld      a,h
  17175.         or      l
  17176.         ret     z
  17177.         ld      de,(l7b8d)
  17178.         ld      a,d
  17179.         or      e
  17180.         ret     z
  17181.         sbc     hl,de
  17182.         ret     z
  17183.         call    ERROR
  17184.         db      _InvType
  17185. l6201:
  17186.         ld      de,l5eeb
  17187.         push    de
  17188.         ld      de,l5f9b
  17189.         push    de
  17190.         ld      de,l6057
  17191.         push    de
  17192.         jr      l622d
  17193. l620f:
  17194.         ld      de,l5eeb
  17195.         push    de
  17196.         ld      de,l5f9b
  17197.         push    de
  17198.         ld      de,l6057
  17199.         push    de
  17200.         jr      l6276
  17201. l621d:
  17202.         call    GetLabType
  17203.         jr      nz,l6257
  17204.         ld      a,(l7ba1)
  17205.         ld      e,a
  17206.         call    NegateNum
  17207.         xor     a
  17208.         ld      (l7ba1),a
  17209. l622d:
  17210.         ld      a,b
  17211.         cp      9
  17212.         jr      nz,l6249
  17213.         exx
  17214.         push    bc
  17215.         push    de
  17216.         push    hl
  17217.         ld      bc,256*3+031h
  17218. l6239:
  17219.         ld      a,c
  17220.         sub     10h
  17221.         ld      c,a             ; Get byte
  17222.         call    writebyte_a_addriy              ; Store it
  17223.         pop     hl
  17224.         call    writeword_hl_addriy
  17225.         djnz    l6239
  17226.         ld      b,9
  17227.         ret
  17228. l6249:
  17229.         cp      8
  17230.         jp      nz,StLD.HL      ; Set LD HL,val16
  17231.         ld      hl,l054d
  17232.         call    StCALL_         ; move immediate string to stack
  17233.         jp      StLen
  17234. l6257:
  17235.         ld      bc,256*6+0
  17236.         call    FndLABEL
  17237.         jr      nz,l6271
  17238.         call    l573d
  17239.         ex      de,hl
  17240.         call    l5287           ; Get name
  17241.         ld      hl,(l7b5e)      ; Get lo set limit
  17242.         ld      (l7b8b),hl
  17243.         ld      a,(l7b5c)       ; Get type
  17244.         ld      b,a
  17245.         ret
  17246. l6271:
  17247.         call    l67b2
  17248.         jr      nz,l62d2
  17249. l6276:
  17250.         ld      a,(l7b5c)       ; Get type
  17251.         cp      _String
  17252.         jr      nc,l6285
  17253.         cp      _Set
  17254.         jr      z,l6285
  17255.         cp      _Ptr
  17256.         jr      nz,l629d
  17257. l6285:
  17258.         call    l66da
  17259.         ld      hl,(l7b5e)      ; Get lo set limit
  17260.         ld      (l7b8b),hl
  17261.         ld      a,(l7b5c)       ; Get type
  17262.         ld      b,a
  17263.         cp      _Set
  17264.         ret     nz
  17265.         call    l5287           ; Get name
  17266.         ld      a,(l7b5c)       ; Get type
  17267.         ld      c,a
  17268.         ret
  17269. l629d:
  17270.         cp      _Array
  17271.         call    ErrNZ
  17272.         db      _NoStruktVar
  17273.         call    l678b
  17274.         ld      hl,(l7b5e)      ; Get lo set limit
  17275.         ld      a,(hl)
  17276.         cp      0ch
  17277.         call    ErrNZ
  17278.         db      _NoStruktVar
  17279.         ld      hl,(l7b60)      ; Get hi set limit
  17280.         ld      a,(hl)
  17281.         cp      0ah
  17282.         call    ErrNZ
  17283.         db      _NoStruktVar
  17284.         ld      hl,(l7b62)      ; Get length of type
  17285.         ld      a,h
  17286.         or      a
  17287.         call    ErrNZ
  17288.         db      _NoStruktVar
  17289.         ld      h,l
  17290.         ld      l,6
  17291.         call    writeword_hl_addriy
  17292.         ld      hl,l0638
  17293.         call    StCALL_         ; Set set to stack
  17294.         ld      b,8
  17295.         ret
  17296. l62d2:
  17297.         call    l6ee0
  17298.         jr      nz,l631c
  17299.         ld      hl,l0581
  17300.         call    StCALL_         ; Initialize a set on stack
  17301.         call    l6ef7           ; Test ]
  17302.         ld      bc,3*256+0 ;l0300
  17303.         ret     z               ; Yeap
  17304. l62e4:
  17305.         push    bc
  17306.         call    l5ebb
  17307.         ld      a,b
  17308.         pop     bc
  17309.         inc     c
  17310.         dec     c
  17311.         jr      nz,l62ef
  17312.         ld      c,a
  17313. l62ef:
  17314.         cp      c
  17315.         call    ErrNZ
  17316.         db      _InvType
  17317.         push    bc
  17318.         call    FindStr         ; Find ..
  17319.         dw      l7580
  17320.         ld      hl,l0591
  17321.         jr      nz,l6310        ; Nope, init one set element
  17322.         call    StPUSH          ; Set PUSH HL
  17323.         call    l5ebb
  17324.         ld      a,b
  17325.         pop     bc
  17326.         push    bc
  17327.         cp      c
  17328.         call    ErrNZ
  17329.         db      _InvType
  17330.         ld      hl,l059b        ; Init a contiguous set value
  17331. l6310:
  17332.         call    StCALL_         ; Set CALL <set>
  17333.         pop     bc
  17334.         call    l6f13           ; Test ,
  17335.         jr      z,l62e4         ; Yeap
  17336.         jp      l6f38           ; Verify ]
  17337. l631c:
  17338.         call    l6f1b           ; Test (
  17339.         jr      nz,l6327        ; Nope
  17340.         call    l5ee8
  17341.         jp      l6f6e           ; Verify )
  17342. l6327:
  17343.         call    FndTabStr               ; Find function
  17344.         db      2
  17345.         dw      l77b1
  17346.         jr      nz,l6335        ; Nope
  17347.         ld      e,(hl)
  17348.         inc     hl
  17349.         ld      d,(hl)
  17350.         ex      de,hl
  17351.         xor     a
  17352.         jp      (hl)
  17353. l6335:
  17354.         call    FindStr         ; Find NIL
  17355.         dw      l757c
  17356.         jr      nz,l6345        ; Nope
  17357.         ld      hl,l0000
  17358.         call    StLD.HL         ; Set LD HL,val16
  17359.         jp      l642e
  17360. l6345:
  17361.          ;jr $
  17362.         ld      bc,256*3+0
  17363.         call    FndLABEL ; Find label with type in reg B
  17364.         call    ErrNZ
  17365.         db      _Undef ;TODO fix bb:=(Txt in [Txt]);
  17366.         ld      d,(hl)
  17367.         dec     hl
  17368.         ld      e,(hl)
  17369.         ld      a,(de)
  17370.         cp      0ah
  17371.         call    ErrCY
  17372.         db      _SimTyp
  17373.         push    af
  17374.         call    l65ef
  17375.         pop     af
  17376.         ld      b,a
  17377.         ret
  17378. ;
  17379. ; Function SQR(Num)
  17380. ;
  17381. l6360:
  17382.         call    l65e7
  17383.         ld      hl,l06f3        ; Set integer SQR
  17384.         ld      a,b
  17385.         cp      0ah
  17386.         jr      z,l636e
  17387.         ld      hl,l09f7        ; Set real SQR
  17388. l636e:
  17389.         jp      StCALL_         ; Set CALL <real>
  17390. ;
  17391. ; Function ABS(Num)
  17392. ;
  17393. l6371:
  17394.         call    l65e7
  17395.         ld      a,b
  17396.         cp      0ah
  17397.         jr      z,l6380
  17398.         call    StImm           ; Set RES 7,B
  17399.         db      a_L47
  17400. s_I47:
  17401.         RES     7,B
  17402. a_L47   equ     $-s_I47
  17403.         ret
  17404. l6380:
  17405.         ld      hl,l0780        ; Set integer ABS
  17406.         jr      l63cf
  17407. ;
  17408. ; Function SQRT(Num)
  17409. ;
  17410. l6385:
  17411.         ld      hl,l0c46
  17412.         jr      l63ab
  17413. ;
  17414. ; Function SIN(Num)
  17415. ;
  17416. l638a:
  17417.         ld      hl,l0c87
  17418.         jr      l63ab
  17419. ;
  17420. ; Function COS(Num)
  17421. ;
  17422. l638f:
  17423.         ld      hl,l0c7f
  17424.         jr      l63ab
  17425. ;
  17426. ; Function ARCTAN(Num)
  17427. ;
  17428. l6394:
  17429.         ld      hl,l0e46
  17430.         jr      l63ab
  17431. ;
  17432. ; Function LN(Num)
  17433. ;
  17434. l6399:
  17435.         ld      hl,l0d2b
  17436.         jr      l63ab
  17437. ;
  17438. ; Function EXP(Num)
  17439. ;
  17440. l639e:
  17441.         ld      hl,l0db6
  17442.         jr      l63ab
  17443. ;
  17444. ; Function INT(Num)
  17445. ;
  17446. l63a3:
  17447.         ld      hl,l0bfd
  17448.         jr      l63ab
  17449. ;
  17450. ; Function FRAC(Num)
  17451. ;
  17452. l63a8:
  17453.         ld      hl,l0c34
  17454. l63ab:
  17455.         push    hl
  17456.         call    l65e7
  17457.         ld      hl,l1008
  17458.         ld      a,b
  17459.         cp      0ah
  17460.         call    z,StCALL_               ; Set CALL INT_TO_FLP
  17461.         pop     hl
  17462.         ld      b,9
  17463.         jp      StCALL_         ; Set CALL <real>
  17464. ;
  17465. ; Function TRUNC(Num)
  17466. ;
  17467. l63be:
  17468.         ld      hl,l0fde
  17469.         jr      l63c6
  17470. ;
  17471. ; Function ROUND(Num)
  17472. ;
  17473. l63c3:
  17474.         ld      hl,l0fd0
  17475. l63c6:
  17476.         push    hl
  17477.         call    l65e7
  17478.         pop     hl
  17479.         ld      a,b
  17480.         cp      0ah
  17481.         ret     z
  17482. l63cf:
  17483.         ld      b,0ah
  17484.         jp      StCALL_         ; Set CALL <real>
  17485. ;
  17486. ; Function SUCC(Num)
  17487. ;
  17488. l63d4:
  17489.         ld      a,_INC.HL       ; INC HL
  17490.         db      skip.3
  17491. ;
  17492. ; Function PRED(Num)
  17493. ;
  17494. l63d7:
  17495.         ld      a,_DEC.HL       ; DEC HL
  17496.         push    af
  17497.         call    l65ef
  17498.         pop     af              ; Get byte back
  17499.         jp      writebyte_a_addriy              ; Store it
  17500. ;
  17501. ; Function LO(Integer)
  17502. ;
  17503. l63e1:
  17504.         call    l65de
  17505.         call    StImm           ; Set LD H,0
  17506.         db      a_L48
  17507. s_I48:
  17508.         LD      H,0
  17509. a_L48   equ     $-s_I48
  17510.         ret
  17511. ;
  17512. ; Function HI(Integer)
  17513. ;
  17514. l63eb:
  17515.         call    l65de
  17516.         call    StImm           ; Set sequence
  17517.         db      a_L49
  17518. s_I49:
  17519.         LD      L,H
  17520.         LD      H,0
  17521. a_L49   equ     $-s_I49
  17522.         ret
  17523. ;
  17524. ; Function SWAP(Num)
  17525. ;
  17526. l63f6:
  17527.         call    l65de
  17528.         call    StImm           ; Set sequence
  17529.         db      a_L50
  17530. s_I50:
  17531.         LD      A,L
  17532.         LD      L,H
  17533.         LD      H,A
  17534. a_L50   equ     $-s_I50
  17535.         ret
  17536. ;
  17537. ; Function ODD(Num)
  17538. ;
  17539. l6401:
  17540.         call    l65de
  17541.         ld      hl,l078b        ; Set function ODD
  17542. l6407:
  17543.         ld      b,0bh
  17544. l6409:
  17545.         jp      StCALL_         ; Set CALL ODD
  17546. ;
  17547. ; Function KEYPRESSED
  17548. ;
  17549. l640c:
  17550.         ld      hl,l00a0
  17551.         jr      l6407
  17552. ;
  17553. ; Function ORD(Var)
  17554. ;
  17555. l6411:
  17556.         call    l6f66           ; Verify (
  17557.         call    l5ee8
  17558.         call    l6f6e           ; Verify )
  17559.         ld      a,b
  17560.         cp      4
  17561.         jr      z,l6422
  17562.         call    l5ebe
  17563. l6422:
  17564.         ld      b,0ah
  17565.         ret
  17566. ;
  17567. ; Function CHR(Num)
  17568. ;
  17569. l6425:
  17570.         call    l65de
  17571.         ld      b,0ch
  17572.         ret
  17573. ;
  17574. ; Function PTR(Integer)
  17575. ;
  17576. l642b:
  17577.         call    l65de
  17578. l642e:
  17579.         ld      hl,l0000
  17580.         ld      (l7b8b),hl
  17581.         ld      b,4
  17582.         ret
  17583. ;
  17584. ; Function UPCASE(Char)
  17585. ;
  17586. l6437:
  17587.         call    l65ef
  17588.         ld      b,0ch
  17589.         ld      hl,l1fe4
  17590.         jr      l6409
  17591. ;
  17592. ; Function LENGTH(String)
  17593. ;
  17594. l6441:
  17595.         call    l6f66           ; Verify (
  17596.         ld      hl,l08a3        ; Set LENGTH
  17597. l6447:
  17598.         push    hl
  17599.         call    l5ed0
  17600.         call    l6f6e           ; Verify )
  17601.         pop     hl
  17602.         jp      l63cf
  17603. ;
  17604. ; Function POS(String,String)
  17605. ;
  17606. l6452:
  17607.         call    l6f66           ; Verify (
  17608.         call    l5ed0
  17609.         call    l6f5e           ; Verify ,
  17610.         ld      hl,l08b2
  17611.         jr      l6447           ; Set POS
  17612. ;
  17613. ; Function COPY(String,Integer,Integer)
  17614. ;
  17615. l6460:
  17616.         call    l6f66           ; Verify (
  17617.         call    l5ed0
  17618.         call    l6f5e           ; Verify ,
  17619.         call    l5e97
  17620.         call    l6f5e           ; Verify ,
  17621.         call    StPUSH          ; Set PUSH HL
  17622.         call    l5e97
  17623.         call    l6f6e           ; Verify )
  17624.         ld      hl,l086b
  17625.         call    StCALL_         ; Set CALL COPY
  17626. l647e:
  17627.         ld      b,8
  17628.         ret
  17629. ;
  17630. ; Function CONCAT(String,String,...)
  17631. ;
  17632. l6481:
  17633.         call    l6f66           ; Verify (
  17634.         call    l5ed0
  17635. l6487:
  17636.         call    l6f13           ; Test ,
  17637.         jr      nz,l6497        ; Nope
  17638.         call    l5ed0
  17639.         ld      hl,l083d
  17640.         call    StCALL_         ; Set add two strings
  17641.         jr      l6487
  17642. l6497:
  17643.         call    l6f6e           ; Verify )
  17644.         jr      l647e
  17645. ;
  17646. ; Function PARAMCOUNT
  17647. ;
  17648. l649c:
  17649.         ld      hl,l1f9b
  17650.         jr      l64bf
  17651. ;
  17652. ; Function PARAMSTR(Integer)
  17653. ;
  17654. l64a1:
  17655.         call    l65de
  17656.         ld      hl,l1f7d
  17657.         ld      b,8
  17658.         jp      StCALL_         ; Set CALL PARAMSTR
  17659. ;
  17660. ; Function RANDOM(Integer)
  17661. ;
  17662. l64ac:
  17663.         call    l6f1b           ; Test (
  17664.         ld      hl,l0fb4
  17665.         ld      b,9
  17666.         jr      nz,l64c1        ; Nope
  17667.         call    l5e97
  17668.         call    l6f6e           ; Verify )
  17669.         ld      hl,l073b        ; Set integer random
  17670. l64bf:
  17671.         ld      b,0ah
  17672. l64c1:
  17673.         jp      StCALL_         ; Set CALL RANDOM
  17674. ;
  17675. ; Function IORESULT
  17676. ;
  17677. l64c4:
  17678.         ld      hl,l1ff1
  17679.         jr      l64bf
  17680. ;
  17681. ; Function EOF(FileVar)
  17682. ;
  17683. l64c9:
  17684.         call    l65f7
  17685.         ld      hl,l6615
  17686.         call    l59e9
  17687. l64d2:
  17688.         ld      b,0bh
  17689.         ret
  17690. ;
  17691. ; Function SEEKEOF(FileVar)
  17692. ;
  17693. l64d5:
  17694.         ld      hl,l17e1
  17695.         jr      l64e2
  17696. ;
  17697. ; Function SEEKEOLN(FileVar)
  17698. ;
  17699. l64da:
  17700.         ld      hl,l17d7
  17701.         jr      l64e2
  17702. ;
  17703. ; Function EOLN(TextFileVar)
  17704. ;
  17705. l64df:
  17706.         ld      hl,l17dc
  17707. l64e2:
  17708.         push    hl
  17709.         call    l65f7
  17710.         cp      6
  17711.         call    ErrNZ
  17712.         db      _MustTextFile
  17713.         pop     hl
  17714.         call    StCALL_         ; Set CALL <eoln>
  17715.         jr      l64d2
  17716. ;
  17717. ; Function FILEPOS(FileVar)
  17718. ;
  17719. l64f2:
  17720.         ld      hl,l1a55
  17721.         ld      de,l1a55
  17722.         jr      l6500
  17723. ;
  17724. ; Function FILESIZE(FileVar)
  17725. ;
  17726. l64fa:
  17727.         ld      hl,l1a5d
  17728.         ld      de,l1a5d
  17729. l6500:
  17730.         push    hl
  17731.         push    de
  17732.         call    l65f7
  17733.         pop     de
  17734.         pop     hl
  17735.         cp      6
  17736.         call    ErrZ
  17737.         db      _IllTxtFile
  17738.         cp      5
  17739.         jr      z,l64bf
  17740.         ex      de,hl
  17741.         jr      l64bf
  17742. ;
  17743. ; Function MEMAVAIL
  17744. ;
  17745. l6514:
  17746.         ld      hl,l1e3d
  17747.         jr      l64bf
  17748. ;
  17749. ; Function MAXAVAIL
  17750. ;
  17751. l6519:
  17752.         ld      hl,l1e44
  17753.         jr      l64bf
  17754. ;
  17755. ; Procedure BIOS(Integer,Integer)
  17756. ; Function BIOSHL(Integer,Integer)
  17757. ;
  17758. l651e:
  17759.         db      skip
  17760. ;
  17761. ; Function BIOS(Integer,Integer)
  17762. ;
  17763. l651f:
  17764.         xor     a
  17765.         push    af
  17766.         call    l6f66           ; Verify (
  17767.         call    l5e97
  17768.         call    StPUSH          ; Set PUSH HL
  17769.         call    l6f13           ; Test ,
  17770.         jr      nz,l6538        ; Nope
  17771.         call    l5e97
  17772.         call    StImm           ; Set sequence
  17773.         db      a_L51
  17774. s_I51:
  17775.         LD      B,H
  17776.         LD      C,L
  17777. a_L51   equ     $-s_I51
  17778. l6538:
  17779.         call    StImm           ; Set POP DE
  17780.         db      a_L52
  17781. s_I52:
  17782.         POP     DE
  17783. a_L52   equ     $-s_I52
  17784.         ld      hl,l1fea
  17785. l6540:
  17786.         call    l6f6e           ; Verify )
  17787.         call    StCALL_         ; Set CALL BIOS
  17788.         pop     af
  17789.         ld      b,0ah
  17790.         or      a
  17791.         ret     nz
  17792.         call    StImm           ; Set sequence
  17793.         db      a_L53
  17794. s_I53:
  17795.         LD      L,A
  17796.         LD      H,0
  17797. a_L53   equ     $-s_I53
  17798.         ret
  17799. ;
  17800. ; Procedure BDOS(Integer,Integer)
  17801. ; Function BDOSHL(Integer,Integer)
  17802. ;
  17803. l6553:
  17804.         db      skip
  17805. ;
  17806. ; Function BDOS(Integer,Integer)
  17807. ;
  17808. l6554:
  17809.         xor     a
  17810.         push    af
  17811.         call    l6f66           ; Verify (
  17812.         call    l5e97
  17813.         call    StPUSH          ; Set PUSH HL
  17814.         call    l6f13           ; Test ,
  17815.         jr      nz,l656c        ; Nope
  17816.         call    l5e97
  17817.         call    StImm           ; Set EX DE,HL
  17818.         db      a_L54
  17819. s_I54:
  17820.         EX      DE,HL
  17821. a_L54   equ     $-s_I54
  17822. l656c:
  17823.         call    StImm           ; Set POP BC
  17824.         db      a_L55
  17825. s_I55:
  17826.         POP     BC
  17827. a_L55   equ     $-s_I55
  17828.         ld      hl,BDOS
  17829.         jr      l6540
  17830. ;
  17831. ; Function ADDR(Var)
  17832. ;
  17833. l6576:
  17834.         call    l6f66           ; Verify (
  17835.         ld      bc,256*5+0
  17836.         call    FndLABEL
  17837.         jr      z,l6589
  17838.         ld      bc,256*6+0
  17839.         call    FndLABEL
  17840.         jr      nz,l6594
  17841. l6589:
  17842.         dec     hl
  17843.         dec     hl
  17844.         ld      d,(hl)
  17845.         dec     hl
  17846.         ld      e,(hl)
  17847.         ex      de,hl
  17848. l658f:
  17849.         call    StLD.HL         ; Set LD HL,val16
  17850.         jr      l6597
  17851. l6594:
  17852.         call    l677f
  17853. l6597:
  17854.         call    l6f6e           ; Verify )
  17855.         ld      b,0ah
  17856.         ret
  17857. ;
  17858. ; Function SIZEOF(Var)
  17859. ;
  17860. l659d:
  17861.         call    l6f66           ; Verify (
  17862.         ld      bc,256*3+0
  17863.         call    FndLABEL
  17864.         jr      nz,l65b1
  17865.         ld      d,(hl)
  17866.         dec     hl
  17867.         ld      e,(hl)
  17868.         ex      de,hl
  17869.         call    l5287           ; Get name
  17870.         jr      l65ba
  17871. l65b1:
  17872.         push    iy
  17873.         call    l677f
  17874.         pop     hl
  17875.         call    ChkChn          ; Check chaining
  17876. l65ba:
  17877.         ld      hl,(l7b62)      ; Get length of type
  17878.         jr      l658f
  17879. ;
  17880. ; Function PORT(Integer)
  17881. ;
  17882. l65bf:
  17883.         call    l65d5
  17884.         call    StImm           ; Set sequence
  17885.         db      a_L56
  17886. s_I56:
  17887.         LD      C,L
  17888.         IN      L,(C)
  17889. a_L56   equ     $-s_I56
  17890.         ret
  17891. ;
  17892. ; Function STACKPTR
  17893. ;
  17894. l65ca:
  17895.         call    StImm           ; Set sequence
  17896.         db      a_L57
  17897. s_I57:
  17898.         LD      HL,0
  17899.         ADD     HL,SP
  17900. a_L57   equ     $-s_I57
  17901.         ld      b,0ah
  17902.         ret
  17903. l65d5:
  17904.         call    l6f30           ; Verify [
  17905.         call    l5e97
  17906.         jp      l6f38           ; Verify ]
  17907. l65de:
  17908.         call    l6f66           ; Verify (
  17909.         call    l5e97
  17910. l65e4:
  17911.         jp      l6f6e           ; Verify )
  17912. l65e7:
  17913.         call    l6f66           ; Verify (
  17914.         call    l5ea2
  17915.         jr      l65e4
  17916. l65ef:
  17917.         call    l6f66           ; Verify (
  17918.         call    l5ebb
  17919.         jr      l65e4
  17920. l65f7:
  17921.         call    l6f1b           ; Test (
  17922.         jr      z,l6608         ; Yeap
  17923.         ld      hl,l00c2
  17924.         call    StLD.HL         ; Set LD HL,val16
  17925.         ld      a,_TxtF
  17926.         ld      (l7b5c),a       ; Set TEXT
  17927.         ret
  17928. l6608:
  17929.         call    l5a17
  17930.         call    ErrNZ
  17931.         db      _FileVarExp
  17932.         push    af
  17933.         call    l6f6e           ; Verify )
  17934.         pop     af
  17935.         ret
  17936. l6615: ;eof procedures
  17937.         dw      l1a49           ; Record file
  17938.         dw      l17e6           ; Text file
  17939.         dw      l1a49           ; Untyped file
  17940.         ;ld     c,c
  17941.         ;ld     a,(de)
  17942.         ;and    17h
  17943.         ;ld     c,c
  17944.         ;ld     a,(de)
  17945. ;
  17946. ;
  17947. ;
  17948. l661b:
  17949.         ld      a,(Envir1)
  17950.         ld      c,a
  17951.         ld      hl,(l7b58)      ; Get value
  17952.         ld      a,(l7b5c)       ; Get type
  17953.         cp      _Set
  17954.         jr      nz,l6634
  17955.         call    l6734
  17956.         ld      hl,l0623
  17957.         ld      de,l0612
  17958.         jr      l6648           ; Assign set variable
  17959. l6634:
  17960.         cp      _String
  17961.         jr      nz,l665e
  17962.         ld      a,(l7b62)       ; Get length of type
  17963.         dec     a
  17964.         ld      h,a
  17965.         ld      l,6
  17966.         call    writeword_hl_addriy
  17967.         ld      hl,l0601        ; Assign string from stack
  17968.         ld      de,l05e2        ; Assign string from stack
  17969. l6648:
  17970.         dec     c
  17971.         jr      z,l665b
  17972.         ex      de,hl
  17973. l664c:
  17974.         ld      a,_LD.HL
  17975.         inc     c
  17976.         jr      z,l6653
  17977.         ld      a,_LD_a_HL
  17978. l6653:
  17979.         push    hl
  17980.         ld      hl,(l7b58)      ; Get value
  17981.         call    StCode
  17982.         pop     hl
  17983. l665b:
  17984.         jp      StCALL_         ; Set CALL <call>
  17985. l665e:
  17986.         cp      _Real
  17987.         jr      nz,l6672
  17988.         call    StImm           ; Set EXX
  17989.         db      a_L58
  17990. s_I58:
  17991.         EXX
  17992. a_L58   equ     $-s_I58
  17993.         ld      hl,l05d1        ; Save real number
  17994.         dec     c
  17995.         jr      nz,l664c
  17996.         call    StPOP           ; Set POP HL
  17997.         jr      l665b
  17998. l6672:
  17999.         cp      _Ptr
  18000.         jr      z,l669d
  18001.         ld      a,(l7b9e)       ; Get local options
  18002.         bit     _Ropt,a         ; Test $R+
  18003.         jr      z,l669d         ; Nope
  18004.         ld      hl,(l7b5e)      ; Get lo set limit
  18005.         ld      de,(l7b60)      ; Get hi set limit
  18006.         inc     de
  18007.         or      a
  18008.         sbc     hl,de
  18009.         add     hl,de
  18010.         jr      z,l669d
  18011.         dec     de
  18012.         call    StLD.DE         ; Set LD DE,val16
  18013.         ex      de,hl
  18014.         or      a
  18015.         sbc     hl,de
  18016.         inc     hl
  18017.         call    StLD.BC
  18018.         ld      hl,l0656
  18019.         call    StCALL_         ; Index check on compiler directive {$R+}
  18020. l669d:
  18021.         dec     c
  18022.         jr      nz,l66b7
  18023.         call    StImm           ; Set sequence
  18024.         db      a_L59
  18025. s_I59:
  18026.         EX      DE,HL
  18027.         POP     HL
  18028. a_L59   equ     $-s_I59
  18029. l66a6:
  18030.         call    StImm           ; Set LD (HL),E
  18031.         db      a_L60
  18032. s_I60:
  18033.         LD      (HL),E
  18034. a_L60   equ     $-s_I60
  18035.         ld      a,(l7b62)       ; Get length of type
  18036.         dec     a
  18037.         ret     z
  18038.         call    StImm           ; Set sequence
  18039.         db      a_L61
  18040. s_I61:
  18041.         INC     HL
  18042.         LD      (HL),D
  18043. a_L61   equ     $-s_I61
  18044.         ret
  18045. l66b7:
  18046.         ld      hl,(l7b58)      ; Get value
  18047.         inc     c
  18048.         jr      nz,l66cf
  18049.         ld      a,(l7b62)       ; Get length of type
  18050.         dec     a
  18051.         ld      a,_LDHL_a
  18052.         jr      nz,l66cc
  18053.         call    StImm           ; Set LD A,L
  18054.         db      a_L62
  18055. s_I62:
  18056.         LD      A,L
  18057. a_L62   equ     $-s_I62
  18058.         ld      a,_LDA_a
  18059. l66cc:
  18060.         jp      StCode
  18061. l66cf:
  18062.         call    StImm           ; Set sequence
  18063.         db      a_L63
  18064. s_I63:
  18065.         EX      DE,HL
  18066.         db      _LD_a_HL
  18067. a_L63   equ     $-s_I63
  18068.         call    writeword_hl_addriy
  18069.         jr      l66a6
  18070. l66da:
  18071.         ld      a,(l7b5c)       ; Get type
  18072.         cp      _Integ
  18073.         jr      nc,l6701
  18074.         cp      _Ptr
  18075.         jr      z,l6701
  18076.         push    af
  18077.         call    l678b
  18078.         pop     af
  18079.         ld      hl,l052c        ; Set load real
  18080.         cp      _Real
  18081.         jr      z,l66fe
  18082.         ld      hl,l053a        ; move string to stack
  18083.         cp      _String
  18084.         jr      z,l66fe
  18085.         call    l6734
  18086.         ld      hl,l055d        ; Push set onto stack
  18087. l66fe:
  18088.         jp      StCALL_         ; Set CALL <set>
  18089. l6701:
  18090.         ld      a,(l7bbd)
  18091.         or      a
  18092.         jr      nz,l671b
  18093.         ld      a,_LD_a_HL
  18094.         ld      hl,(l7bbe)
  18095.         call    StCode
  18096.         ld      a,(l7b62)       ; Get length of type
  18097.         dec     a
  18098.         ret     nz
  18099. l6714:
  18100.         call    StImm           ; Set LD H,0
  18101.         db      a_L64
  18102. s_I64:
  18103.         LD      H,0
  18104. a_L64   equ     $-s_I64
  18105.         ret
  18106. l671b:
  18107.         call    l678b
  18108.         ld      a,(l7b62)       ; Get length of type
  18109.         dec     a
  18110.         jr      nz,l672b
  18111.         call    StImm           ; Set LD L,(HL)
  18112.         db      a_L65
  18113. s_I65:
  18114.         LD      L,(HL)
  18115. a_L65   equ     $-s_I65
  18116.         jr      l6714
  18117. l672b:
  18118.         call    StImm           ; Set sequence
  18119.         db      a_L66
  18120. s_I66:
  18121.         LD      E,(HL)
  18122.         INC     HL
  18123.         LD      D,(HL)
  18124.         EX      DE,HL
  18125. a_L66   equ     $-s_I66
  18126.         ret
  18127. l6734:
  18128.         ld      hl,(l7b5e)      ; Get lo set limit
  18129.         call    l5271           ; Load name
  18130.         ld      hl,(l7b62)      ; Get length of type
  18131.         ld      a,(l7b6b)
  18132.         rra
  18133.         rra
  18134.         rra
  18135.         and     1fh
  18136.         ld      h,a
  18137.         jp      StLD.BC
  18138. l6749:
  18139.         call    GetConst                ; Get constant
  18140.         jr      nz,l677f
  18141.         ld      a,b
  18142.         cp      8
  18143.         call    ErrNZ
  18144.         db      _IllConst
  18145.         ld      l,18h
  18146.         ld      h,c
  18147.         call    writeword_hl_addriy
  18148.         ld      (l7b58),iy      ; Set value
  18149.         ld      a,_Array
  18150.         ld      (l7b5c),a       ; Set ARRAY
  18151.         ld      hl,l74db+7
  18152.         ld      (l7b5e),hl      ; Set lo set limit
  18153.         ld      hl,l0000
  18154.         ld      (l7b60),hl      ; Reset hi set limit
  18155.         ld      l,c
  18156.         ld      (l7b62),hl      ; Set length of type
  18157.         call    StConst         ; Store string
  18158.         ld      a,_LD.HL
  18159.         ld      hl,(l7b58)      ; Get value
  18160.         jp      StCode
  18161. l677f:
  18162.         call    l6787
  18163.         ret     z
  18164.         call    ERROR
  18165.         db      _Undef
  18166. l6787:
  18167.         call    l67b2
  18168.         ret     nz
  18169. l678b:
  18170.         ld      a,(l7bbd)
  18171.         ld      hl,(l7bbe)
  18172.         bit     1,a
  18173.         jr      nz,l67a2
  18174.         bit     0,a
  18175.         ld      a,_LD.HL
  18176.         jr      z,l679d
  18177.         ld      a,_LD_a_HL
  18178. l679d:
  18179.         call    StCode
  18180.         jr      l67b0
  18181. l67a2:
  18182.         bit     0,a
  18183.         jr      nz,l67b0
  18184.         ld      a,_LD.DE
  18185.         call    StCode
  18186.         call    StImm           ; Set ADD HL,DE
  18187.         db      a_L67
  18188. s_I67:
  18189.         ADD     HL,DE
  18190. a_L67   equ     $-s_I67
  18191. l67b0:
  18192.         xor     a
  18193.         ret
  18194. l67b2:
  18195.         call    l680c
  18196.         jr      z,l67d9
  18197.         ld      bc,256*4+0
  18198.         call    FndLABEL
  18199.         jr      nz,l67ed
  18200.         call    l5276
  18201.         ld      a,(Envir1)
  18202.         or      a
  18203.         ld      a,'!'
  18204.         ld      b,0
  18205.         jr      z,l67cf
  18206.         ld      a,'*'
  18207.         inc     b
  18208. l67cf:
  18209.         ld      hl,l7bbd
  18210.         ld      (hl),b
  18211.         ld      hl,(l7b58)      ; Get value
  18212.         ld      (l7bbe),hl
  18213. l67d9:
  18214.         call    l683a
  18215.         jr      z,l67d9
  18216.         call    l6931
  18217.         jr      z,l67d9
  18218.         call    l6974
  18219.         jr      z,l67d9
  18220.         call    l699f
  18221.         xor     a
  18222.         ret
  18223. l67ed:
  18224.         call    FindStr         ; Find MEM
  18225.         dw      l78fa
  18226.         ret     nz              ; Nope
  18227.         call    l65d5
  18228.         ld      a,_Integ
  18229.         ld      (l7b5c),a       ; Set INTEGER
  18230.         ld      hl,l0001
  18231.         ld      (l7b62),hl      ; Set length of type
  18232.         dec     l
  18233.         ld      (l7b5e),hl      ; Set lo set limit
  18234.         dec     l
  18235.         ld      (l7b60),hl      ; Set hi set limit
  18236.         jp      l6903
  18237. l680c:
  18238.         ld      a,(l7bc9)
  18239.         ld      b,a
  18240. l6810:
  18241.         dec     b
  18242.         ret     m
  18243.         push    bc
  18244.         ld      e,b
  18245.         ld      d,0
  18246.         ld      hl,l7bcc
  18247.         add     hl,de
  18248.         ld      a,(hl)
  18249.         ld      c,a
  18250.         ld      b,4
  18251.         call    FndLABEL
  18252.         pop     bc
  18253.         jr      nz,l6810
  18254.         push    hl
  18255.         ld      a,b
  18256.         add     a,a
  18257.         ld      e,a
  18258.         ld      d,0
  18259.         ld      hl,(l7bca)
  18260.         add     hl,de
  18261.         ld      (l7bbe),hl
  18262.         ld      hl,l7bbd
  18263.         ld      (hl),1
  18264.         pop     hl
  18265.         jp      l6948
  18266. l683a:
  18267.         ld      a,(l7b5c)       ; Get type
  18268.         cp      _Array
  18269.         ret     nz
  18270.         call    l6ee0
  18271.         ret     nz
  18272.         call    l678b
  18273. l6847:
  18274.         call    StPUSH          ; Set PUSH HL
  18275.         call    l5e84
  18276.         ld      hl,(l7b60)      ; Get hi set limit
  18277.         call    l5271           ; Load name
  18278.         ld      a,(l7b69)
  18279.         cp      b
  18280.         call    ErrNZ
  18281.         db      _InvType
  18282.         ld      hl,(l7b6b)
  18283.         ld      a,h
  18284.         or      a
  18285.         jr      nz,l6874
  18286.         ld      a,l
  18287.         cp      4
  18288.         jr      nc,l6888
  18289. l6867:
  18290.         or      a
  18291.         jr      z,l6893
  18292.         push    af
  18293.         call    StImm           ; Set DEC HL
  18294.         db      a_L68
  18295. s_I68:
  18296.         DEC     HL
  18297. a_L68   equ     $-s_I68
  18298.         pop     af
  18299.         dec     a
  18300.         jr      l6867
  18301. l6874:
  18302.         inc     a
  18303.         jr      nz,l6888
  18304.         ld      a,l
  18305.         cp      0fdh
  18306.         jr      c,l6888
  18307. l687c:
  18308.         push    af
  18309.         call    StImm           ; Set INC HL
  18310.         db      a_L69
  18311. s_I69:
  18312.         INC     HL
  18313. a_L69   equ     $-s_I69
  18314.         pop     af
  18315.         inc     a
  18316.         jr      nz,l687c
  18317.         jr      l6893
  18318. l6888:
  18319.         call    NegateInt
  18320.         call    StLD.DE         ; Set LD DE,val16
  18321.         call    StImm           ; Set ADD HL,DE
  18322.         db      a_L70
  18323. s_I70:
  18324.         ADD     HL,DE
  18325. a_L70   equ     $-s_I70
  18326. l6893:
  18327.         ld      a,(l7b9e)       ; Get local options
  18328.         bit     _Ropt,a         ; Test $R+
  18329.         jr      z,l68ae
  18330.         ld      hl,(l7b6d)      ; Get last memory address
  18331.         ld      de,(l7b6b)
  18332.         or      a
  18333.         sbc     hl,de
  18334.         inc     hl
  18335.         call    StLD.DE         ; Set LD DE,val16
  18336.         ld      hl,l064c
  18337.         call    StCALL_         ; Index check on compiler directive {$R+}
  18338. l68ae:
  18339.         ld      hl,(l7b5e)      ; Get lo set limit
  18340.         call    l5287           ; Get name
  18341.         ld      hl,(l7b62)      ; Get length of type
  18342.         ld      a,h
  18343.         or      a
  18344.         jr      nz,l68d8
  18345.         ld      a,l
  18346.         dec     a
  18347.         jr      z,l68ed
  18348.         dec     a
  18349.         jr      nz,l68c9
  18350.         call    StImm           ; Set ADD HL,HL
  18351.         db      a_L71
  18352. s_I71:
  18353.         ADD     HL,HL
  18354. a_L71   equ     $-s_I71
  18355.         jr      l68ed
  18356. l68c9:
  18357.         cp      4
  18358.         jr      nz,l68d8
  18359.         call    StImm           ; Set sequence
  18360.         db      a_L72
  18361. s_I72:
  18362.         ADD     HL,HL
  18363.         LD      E,L
  18364.         LD      D,H
  18365.         ADD     HL,HL
  18366.         ADD     HL,DE
  18367. a_L72   equ     $-s_I72
  18368.         jr      l68ed
  18369. l68d8:
  18370.         ld      a,(l7b9e)       ; Get local options
  18371.         bit     _Xopt,a         ; Test $X+
  18372.         jr      nz,l68ea        ; Yeap
  18373.         call    StLD.DE         ; Set LD DE,val16
  18374.         ld      hl,l06f5        ; Set integer multiply
  18375.         call    StCALL_
  18376.         jr      l68ed
  18377. l68ea:
  18378.         call    l690a
  18379. l68ed:
  18380.         call    StImm           ; Set sequence
  18381.         db      a_L73
  18382. s_I73:
  18383.         POP     DE
  18384.         ADD     HL,DE
  18385. a_L73   equ     $-s_I73
  18386.         ld      a,(l7b5c)       ; Get type
  18387.         cp      _Array
  18388.         jr      nz,l6900
  18389.         call    l6f13           ; Test ,
  18390.         jp      z,l6847         ; Yeap
  18391. l6900:
  18392.         call    l6f38           ; Verify ]
  18393. l6903:
  18394.         ld      a,3
  18395.         ld      (l7bbd),a
  18396.         xor     a
  18397.         ret
  18398. l690a:
  18399.         ld      b,1
  18400. l690c:
  18401.         ld      a,h
  18402.         or      a
  18403.         jr      nz,l6914
  18404.         ld      a,l
  18405.         dec     a
  18406.         jr      z,l6927
  18407. l6914:
  18408.         bit     0,l
  18409.         jr      z,l691c
  18410.         call    StPUSH          ; Set PUSH HL
  18411.         inc     b
  18412. l691c:
  18413.         call    StImm           ; Set ADD HL,HL
  18414.         db      a_L74
  18415. s_I74:
  18416.         ADD     HL,HL
  18417. a_L74   equ     $-s_I74
  18418.         srl     h
  18419.         rr      l
  18420.         jr      l690c
  18421. l6927:
  18422.         dec     b
  18423.         ret     z
  18424.         call    StImm           ; Set sequence
  18425.         db      a_L75
  18426. s_I75:
  18427.         POP     DE
  18428.         ADD     HL,DE
  18429. a_L75   equ     $-s_I75
  18430.         jr      l6927
  18431. l6931:
  18432.         ld      a,(l7b5c)       ; Get type
  18433.         cp      _Record
  18434.         ret     nz
  18435.         call    l6f17
  18436.         ret     nz
  18437.         ld      a,(l7b5d)
  18438.         ld      c,a
  18439.         ld      b,4
  18440.         call    FndLABEL
  18441.         call    ErrNZ
  18442.         db      _Undef
  18443. l6948:
  18444.         call    l5276
  18445.         ld      hl,(l7b58)      ; Get value
  18446.         ld      a,h
  18447.         or      l
  18448.         ret     z
  18449.         ld      hl,l7bbd
  18450.         bit     0,(hl)
  18451.         jr      z,l6967
  18452.         push    hl
  18453.         call    l678b
  18454.         pop     hl
  18455.         ld      (hl),2
  18456.         ld      hl,(l7b58)      ; Get value
  18457.         ld      (l7bbe),hl
  18458.         xor     a
  18459.         ret
  18460. l6967:
  18461.         ld      hl,(l7bbe)
  18462.         ld      de,(l7b58)      ; Get value
  18463.         add     hl,de
  18464.         ld      (l7bbe),hl
  18465.         xor     a
  18466.         ret
  18467. l6974:
  18468.         ld      a,(l7b5c)       ; Get type
  18469.         cp      _Ptr
  18470.         ret     nz
  18471.         call    l6f27
  18472.         ret     nz
  18473.         ld      hl,l7bbd
  18474.         ld      a,(hl)
  18475.         or      a
  18476.         jr      nz,l6988
  18477.         inc     (hl)
  18478.         jr      l6997
  18479. l6988:
  18480.         push    hl
  18481.         call    l678b
  18482.         pop     hl
  18483.         ld      (hl),3
  18484.         call    StImm           ; Set sequence
  18485.         db      a_L76
  18486. s_I76:
  18487.         LD      E,(HL)
  18488.         INC     HL
  18489.         LD      D,(HL)
  18490.         EX      DE,HL
  18491. a_L76   equ     $-s_I76
  18492. l6997:
  18493.         ld      hl,(l7b5e)      ; Get lo set limit
  18494.         call    l5287           ; Get name
  18495.         xor     a
  18496.         ret
  18497. l699f:
  18498.         ld      a,(l7b5c)       ; Get type
  18499.         cp      _String
  18500.         ret     nz
  18501.         call    l6ee0
  18502.         ret     nz
  18503.         call    l678b
  18504.         call    StPUSH          ; Set PUSH HL
  18505.         ld      hl,(l7b62)      ; Get length of type
  18506.         push    hl
  18507.         call    l5e97
  18508.         pop     hl
  18509.         ld      a,(l7b9e)       ; Get local options
  18510.         bit     _Ropt,a         ; Test $R+
  18511.         jr      z,l69c7         ; Nope
  18512.         call    StLD.DE         ; Set LD DE,val16
  18513.         ld      hl,l064c
  18514.         call    StCALL_         ; Index check on compiler directive {$R+}
  18515. l69c7:
  18516.         call    StImm           ; Set sequence
  18517.         db      a_L77
  18518. s_I77:
  18519.         POP     DE
  18520.         ADD     HL,DE
  18521. a_L77   equ     $-s_I77
  18522.         call    l6f38           ; Verify ]
  18523.         ld      a,_Char
  18524.         ld      (l7b5c),a       ; Set CHAR
  18525.         ld      hl,l0001
  18526.         ld      (l7b62),hl      ; Set length of type
  18527.         dec     hl
  18528.         ld      (l7b5e),hl      ; Set lo set limit
  18529.         dec     l
  18530.         ld      (l7b60),hl      ; Set hi set limit
  18531.         ld      a,3
  18532.         ld      (l7bbd),a
  18533.         xor     a
  18534.         ret
  18535. ;
  18536. ; Get constant
  18537. ;
  18538. _GetConst:
  18539.         call    GetConst                ; Get constant
  18540.         ret     z
  18541.         call    ERROR
  18542.         db      _Undef
  18543. ;
  18544. ; Get integer constant
  18545. ;
  18546. _GetIntC:
  18547.         call    _GetConst               ; Get constant
  18548.         ld      a,b
  18549.         cp      0ah ;_Integ
  18550.         ret     z
  18551.         call    ERROR
  18552.         db      _IntConst
  18553. ;
  18554. ; Get string constant
  18555. ;
  18556. _GetStrC:
  18557.         call    _GetConst               ; Get constant
  18558.         ld      a,b
  18559.         cp      8 ;_String
  18560.         ret     z
  18561.         cp      0ch ;_Char
  18562.         call    ErrNZ
  18563.         db      _StrgConExp
  18564.         ld      b,8 ;_String
  18565.         ret
  18566. ;
  18567. ; Get constant
  18568. ;
  18569. GetConst:
  18570.         call    GetSign
  18571.         push    de
  18572.         call    GetLabType
  18573.         pop     de
  18574.         jr      z,NegateNum
  18575.         inc     e
  18576.         dec     e
  18577.         call    ErrNZ
  18578.         db      _IntRealCexp
  18579.         dec     e
  18580.         ret
  18581. NegateNum:
  18582.         call    ChkNumSign
  18583.         ret     z
  18584.         ld      a,b
  18585.         cp      9 ;_Real
  18586.         jr      nz,NegateInt
  18587.         exx
  18588.         ld      a,b
  18589.         xor     80h
  18590.         ld      b,a
  18591.         exx
  18592.         xor     a
  18593.         ret
  18594. NegateInt:
  18595.         ld      a,h
  18596.         cpl
  18597.         ld      h,a
  18598.         ld      a,l
  18599.         cpl
  18600.         ld      l,a
  18601.         inc     hl
  18602.         xor     a
  18603.         ret
  18604. GetSign:
  18605.         ld      e,0ffh
  18606.         ld      a,(ix+0)
  18607.         cp      '-'
  18608.         jr      z,l6a47
  18609.         inc     e
  18610.         cp      '+'
  18611.         ret     nz
  18612.         inc     e
  18613. l6a47:
  18614.         jp      NewLine         ; Process line
  18615. ChkNumSign:
  18616.         inc     e
  18617.         dec     e
  18618.         ret     z
  18619.         ld      a,b
  18620.         cp      0ah ;_Integ
  18621.         jr      z,ChkNumSign_valid
  18622.         cp      9 ;_Real
  18623.         jr      nz,ChkNumSign_bad
  18624. ChkNumSign_valid:
  18625.         dec     e
  18626.         ret
  18627. ChkNumSign_bad:
  18628.         call    ERROR
  18629.         db      _IntRealCexp
  18630. GetLabType:
  18631.         call    GetConstType            ; Sample constant
  18632.         ret     z               ; Got one
  18633.         ld      bc,256*2+0
  18634.         call    FndLABEL
  18635.         ret     nz
  18636.         ld      b,(hl)
  18637.         ld      a,b
  18638.         dec     hl
  18639.         cp      0ah ;_Integ
  18640.         jr      c,GetLabType_noOrd
  18641.         ld      d,(hl)
  18642.         dec     hl
  18643.         ld      e,(hl)
  18644.         ex      de,hl
  18645.         xor     a
  18646.         ret
  18647. GetLabType_noOrd:
  18648.         cp      9 ;_Real
  18649.         jr      nz,GetLabType_noReal
  18650.         push    bc
  18651.         ld      b,(hl)
  18652.         dec     hl
  18653.         ld      c,(hl)
  18654.         dec     hl
  18655.         ld      d,(hl)
  18656.         dec     hl
  18657.         ld      e,(hl)
  18658.         dec     hl
  18659.         ld      a,(hl)
  18660.         dec     hl
  18661.         ld      l,(hl)
  18662.         ld      h,a
  18663.         exx
  18664.         pop     bc
  18665.         ret
  18666. GetLabType_noReal:
  18667.         ld      c,(hl)
  18668.         ld      de,l7a57
  18669.         push    bc
  18670.         inc     c
  18671. GetLabType_cpyStr:
  18672.         dec     c
  18673.         jr      z,GetLabType_ex
  18674.         dec     hl
  18675.         ld      a,(hl)
  18676.         ld      (de),a
  18677.         inc     de
  18678.         jr      GetLabType_cpyStr
  18679. GetLabType_ex:
  18680.         pop     bc
  18681.         ret
  18682. ;
  18683. ; Sample constant - Z set indicates constant
  18684. ;
  18685. ; Reg B holds type of constant
  18686. ; Reg C holds length of constant
  18687. ;
  18688. GetConstType:
  18689.         ld      a,(ix+0)        ; Get character
  18690.         cp      ''''            ; Test string
  18691.         jr      z,GetConstType_strg
  18692.         cp      '^'             ; Test control character prefix
  18693.         jr      z,GetConstType_strg
  18694.         cp      '#'             ; Test character prefix
  18695.         jr      nz,GetConstType_noStrg
  18696. GetConstType_strg:
  18697.         ld      hl,l7a57        ; Init parameter buffer
  18698.         ld      c,0             ; Init length
  18699. GetConstType_chkMore:
  18700.         ld      a,(ix+0)
  18701.         cp      '^'             ; Test control character prefix
  18702.         jr      z,GetConstType_ctrChr
  18703.         cp      '#'             ; Test character prefix
  18704.         jr      z,GetConstType_chrPrfx
  18705.         cp      ''''            ; Test string
  18706.         jr      nz,GetConstType_ex
  18707. GetConstType_cpyStrg:
  18708.         inc     ix
  18709.         ld      a,(ix+0) ;Get character
  18710.         or      a
  18711.         call    ErrZ
  18712.         db      _StrConLong
  18713.         cp      ''''
  18714.         jr      nz,GetConstType_unp
  18715.         inc     ix
  18716.         ld      a,(ix+0) ;Get character
  18717.         cp      ''''
  18718.         jr      nz,GetConstType_chkMore
  18719. GetConstType_unp:
  18720.         ld      (hl),a
  18721.         inc     hl
  18722.         inc     c
  18723.         jr      GetConstType_cpyStrg
  18724. GetConstType_ctrChr:
  18725.         inc     ix
  18726.         ld      a,(ix+0) ;Get character
  18727.         call    doupcase                ; Convert to upper case
  18728.         or      a
  18729.         call    ErrZ
  18730.         db      _StrConLong
  18731.         xor     '@'
  18732.         inc     ix
  18733. GetConstType_sav:
  18734.         ld      (hl),a
  18735.         inc     hl
  18736.         inc     c
  18737.         jr      GetConstType_chkMore
  18738. GetConstType_chrPrfx:
  18739.         inc     ix
  18740.         push    bc
  18741.         push    hl
  18742.         call    cnv_int         ; Convert ASCII to integer
  18743.         ld      a,l
  18744.         pop     hl
  18745.         pop     bc
  18746.         call    ErrCY
  18747.         db      _IntegErr
  18748.         jr      GetConstType_sav
  18749. GetConstType_ex:
  18750.         ld      b,8 ;_String
  18751.         ld      a,c ; Get count
  18752.         dec     a   ; Test character
  18753.         jr      nz,GetConstType_getLine ; .. nope
  18754.         ld      h,a                ; .. clear HI
  18755.         ld      a,(l7a57)          ; .. get LO
  18756.         ld      l,a
  18757.         ld      b,0ch ;_Char    ; Change mode
  18758. GetConstType_getLine:
  18759.         jp      GetLine         ; Process line
  18760. GetConstType_noStrg:
  18761.         cp      '$'
  18762.         jr      z,GetConstType_hex
  18763.         call    IsItDigit       ; Test digit
  18764.         jr      nc,GetConstType_numb
  18765.         xor     a
  18766.         dec     a
  18767.         ret
  18768. GetConstType_numb:
  18769.         push    ix
  18770.         pop     de
  18771. GetConstType_wtNoNum:
  18772.         inc     de
  18773.         ld      a,(de)
  18774.         call    IsItDigit               ; Test digit
  18775.         jr      nc,GetConstType_wtNoNum
  18776.         call    doupcase                ; Convert to upper case
  18777.         cp      'E'
  18778.         jr      z,GetConstType_real
  18779.         cp      '.'
  18780.         jr      nz,GetConstType_hex
  18781.         inc     de
  18782.         ld      a,(de)
  18783.         cp      '.'
  18784.         jr      z,GetConstType_hex
  18785.         cp      ')'
  18786.         jr      z,GetConstType_hex
  18787. GetConstType_real:
  18788.         call    cnv_flp ; Convert to real
  18789.         call    ErrCY   ; Real constant error
  18790.         db      _RealErr
  18791.         exx              ; Real into alternate set
  18792.         ld      b,9 ;_Real ; .. set mode
  18793.         jr      GetConstType_getLine
  18794. GetConstType_hex:
  18795.         call    cnv_int         ; Convert ASCII to integer
  18796.         call    ErrCY
  18797.         db      _IntegErr
  18798.         ld      b,0ah
  18799.         jr      GetConstType_getLine
  18800. ;
  18801. ; Transfer immediate opcodes
  18802. ; Sequence starts with length
  18803. ;
  18804. StImm:
  18805.         ex      (sp),hl
  18806.         push    bc
  18807.         ld      b,(hl)          ; Get length
  18808.         inc     hl
  18809. StI_loop:
  18810.         ld      a,(hl)          ; Get byte
  18811.         call    writebyte_a_addriy              ; Store it
  18812.         inc     hl
  18813.         djnz    StI_loop
  18814.         pop     bc
  18815.         ex      (sp),hl
  18816.         ret
  18817. StLen:
  18818.         ld      a,c             ; Get byte
  18819.         call    writebyte_a_addriy              ; Store it
  18820. ;
  18821. ; Store string
  18822. ;
  18823. StConst:
  18824.         ld      hl,l7a57
  18825.         inc     c
  18826. StC_loop:
  18827.         dec     c
  18828.         ret     z
  18829.         ld      a,(hl)          ; Get character
  18830.         inc     hl
  18831.         call    writebyte_a_addriy              ; Store it
  18832.         jr      StC_loop
  18833. ;
  18834. ; Set PUSH HL
  18835. ;
  18836. StPUSH:
  18837.         ld      a,_PUSH.HL
  18838.         jr      writebyte_a_addriy
  18839. ;
  18840. ; Set POP HL
  18841. ;
  18842. StPOP:
  18843.         ld      a,_POP.HL
  18844.         jr      writebyte_a_addriy
  18845. ;
  18846. ; Set JP
  18847. ;
  18848. StJP:
  18849.         ld      a,_JP
  18850.         jr      writebyte_a_addriy
  18851. ;
  18852. ; Insert operand
  18853. ; ENTRY Reg DE holds operand
  18854. ; (Set word in reg DE)
  18855. ;
  18856. writeword_de_addriy:
  18857.         ld      a,e
  18858.         call    writebyte_a_addriy
  18859.         ld      a,d
  18860.         jr      writebyte_a_addriy
  18861. ;
  18862. ; Set JP WORD
  18863. ;
  18864. StJP_:
  18865.         ld      a,_JP
  18866.         jr      StCode
  18867. ;
  18868. ; Set CALL WORD
  18869. ;
  18870. StCALL_:
  18871.         ld      a,_CALL
  18872.         jr      StCode
  18873. ;
  18874. ; Set LD BC,WORD
  18875. ;
  18876. StLD.BC:
  18877.         ld      a,_LD.BC
  18878.         jr      StCode
  18879. ;
  18880. ; Set LD DE,WORD
  18881. ;
  18882. StLD.DE:
  18883.         ld      a,_LD.DE
  18884.         jr      StCode
  18885. ;
  18886. ; Set LD HL,WORD
  18887. ;
  18888. StLD.HL:
  18889.         ld      a,_LD.HL
  18890. ;
  18891. ; Insert opcodes in Accu, reg L and reg H
  18892. ;
  18893. StCode:
  18894.         call    writebyte_a_addriy
  18895. ;
  18896. ; Insert word in reg HL
  18897. ;
  18898. writeword_hl_addriy:
  18899.         ld      a,l
  18900.         call    writebyte_a_addriy
  18901.         ld      a,h
  18902. ;
  18903. ; Insert byte in Accu
  18904. ;
  18905. writebyte_a_addriy:
  18906.         push    bc
  18907.         ld      b,a
  18908.         ld      a,(CmpTyp)      ; Get compile flag
  18909.         or      a               ; Test mode
  18910.         jr      nz,St__noSt     ; Searching or compiling       
  18911.         ld      (iy+0),b        ; Store byte into memory
  18912. St__noSt:
  18913.         inc     iy              ; Update PC
  18914.         or      a               ; Test compile to memory
  18915.         jr      z,St__skp               ; Yeap
  18916.         push    hl
  18917.         push    de
  18918.         dec     a               ; Test search
  18919.         jr      z,St__St                ; Nope ; .. compile to file
  18920.         push    iy
  18921.         pop     de
  18922.         dec     de
  18923.         ld      hl,(l00ce)      ; Get current PC
  18924.         or      a
  18925.         sbc     hl,de
  18926.         call    ErrZ
  18927.         db      _FndRTerr
  18928.         jr      St__pop
  18929. St__St:
  18930.         call    savebyte_b              ; Put byte to file
  18931. St__pop:
  18932.         pop     de
  18933.         pop     hl
  18934. St__skp:
  18935.         pop     bc
  18936. ;
  18937. ; Check enough memory
  18938. ;
  18939. ChkOvfl:
  18940.         push    hl
  18941.         push    de
  18942.         push    iy
  18943.         pop     de
  18944.         ld      a,(CmpTyp)      ; Get compile flag
  18945.         or      a
  18946.         jr      z,ChkOv.mem             ; Skip if compiling to memory
  18947.         ld      de,(MemsTop)    ; Get memory top
  18948.         dec     a
  18949.         jr      nz,ChkOv.mem
  18950.         ld      de,(COMsTop)    ; Get top of .COM file
  18951.         ld      a,(IncFlg)      ; Test memory read
  18952.         or      a
  18953.         jr      z,ChkOv.mem             ; Yeap
  18954.         ld      de,(INCsTop)
  18955. ChkOv.mem:
  18956.         ld      hl,(LabPtr)     ; Get label pointer
  18957.         scf
  18958.         sbc     hl,de
  18959.         call    ErrCY
  18960.         db      _CompOvfl
  18961.         push    iy
  18962.         pop     de
  18963.         ld      hl,(DataBeg)    ; Get start of data
  18964.         dec     h
  18965.         dec     h
  18966.         sbc     hl,de
  18967.         call    ErrCY
  18968.         db      _MemOvfl
  18969.         pop     de
  18970.         pop     hl
  18971.         ret
  18972. ;
  18973. ; Put byte in reg B to file
  18974. ;
  18975. savebyte_b:
  18976.         ld      hl,RRN_stat     ; Point to file access
  18977.         set     1,(hl)          ; Set write enabled
  18978.         bit     0,(hl)          ; Test re-read
  18979.         jr      z,SkpRdRRN              ; Nope
  18980.         res     0,(hl)          ; Clear it
  18981.         push    bc
  18982.         call    readrecord_TmpBuff              ; Re-read record
  18983.         pop     bc
  18984. SkpRdRRN:
  18985.         ld      a,(RecPtr)      ; Get record pointer
  18986.         ld      e,a
  18987.         ld      d,0
  18988.         ld      hl,TmpBuff
  18989.         add     hl,de           ; Build buffer address
  18990.         ld      (hl),b          ; Store byte
  18991.         inc     a               ; Advance record pointer
  18992.         jp      p,StToF__ex             ; Still within limits
  18993.         call    writerecord_TmpBuff             ; Write record
  18994.         ld      hl,(FFCB+_rrn)
  18995.         inc     hl              ; Advance record count
  18996.         ld      (FFCB+_rrn),hl
  18997.         xor     a
  18998. StToF__ex:
  18999.         ld      (RecPtr),a      ; Set record pointer
  19000.         ret
  19001. ;
  19002. ; Allocate space in reg DE
  19003. ;
  19004. VarAlloc:
  19005.         ld      hl,(DataBeg)    ; Get start of data
  19006.         or      a
  19007.         sbc     hl,de
  19008.         call    ErrCY
  19009.         db      _MemOvfl
  19010.         ld      (DataBeg),hl    ; Set start of data
  19011.         jr      ChkOvfl         ; Check enough memory
  19012. ;
  19013. ; Store back current PC to ^HL
  19014. ;
  19015. storeback_iy_to_addrhl:
  19016.         push    iy              ; Get PC
  19017.         pop     de
  19018. ;
  19019. ; Store back reg DE to ^HL
  19020. ;
  19021. storeback_de_to_addrhl:
  19022.         ld      a,(CmpTyp)      ; Get compile flag
  19023.         dec     a               ; Test compiling to memory
  19024.         jr      z,StBackMem             ; nope
  19025.         push    iy
  19026.         push    hl
  19027.         pop     iy
  19028.         call    writeword_de_addriy             ; Set word
  19029.         pop     iy
  19030.         ret
  19031. flushunfinished
  19032.         ld a,(RecPtr)   ; Get record pointer
  19033.         or a
  19034.         ret z
  19035.          push bc
  19036.          push de
  19037.          push hl
  19038.         ;ld a,h
  19039.         ;and l
  19040.         ;inc a ;-1=fake record number
  19041.         ;jr z,flushunfinished_skip
  19042.          call flushunfinishedpp
  19043. ;flushunfinished_skip
  19044. ;close, open to force flush???
  19045.         ;ld de,FFCB
  19046.         ;ld c,_close
  19047.         ;call _BDOS             ; BDOS with keep ix,iy
  19048.         ;ld de,FFCB
  19049.         ;ld c,_open
  19050.         ;call _BDOS             ; BDOS with keep ix,iy
  19051.          pop hl
  19052.          pop de
  19053.          pop bc
  19054.          ret
  19055. StBackMem:
  19056.          call flushunfinished
  19057.         push    bc
  19058.         push    de
  19059.         push    hl
  19060.         ld      hl,(MemsTop)    ; Get memory top
  19061.         ld      a,(BackLevel)   ; Get back fix level
  19062.         ld      b,a
  19063.         inc     b
  19064. l6c5e:
  19065.         dec     b
  19066.         jr      z,l6c84
  19067.         ld      e,(hl)
  19068.         inc     hl
  19069.         ld      d,(hl)
  19070.         ex      (sp),hl
  19071.         or      a
  19072.         sbc     hl,de
  19073.         add     hl,de
  19074.         ex      (sp),hl
  19075.         jr      c,l6c71
  19076.         inc     hl
  19077.         inc     hl
  19078.         inc     hl
  19079.         jr      l6c5e
  19080. l6c71:
  19081.         dec     hl
  19082.         ex      de,hl
  19083.         ld      l,b
  19084.         ld      h,0
  19085.         add     hl,hl
  19086.         add     hl,hl
  19087.         ld      b,h
  19088.         ld      c,l
  19089.         add     hl,de
  19090.         ld      d,h
  19091.         ld      e,l
  19092.         dec     hl
  19093.         inc     de
  19094.         inc     de
  19095.         inc     de
  19096.         lddr
  19097.         inc     hl
  19098. l6c84:
  19099.         pop     de
  19100.         ld      (hl),e
  19101.         inc     hl
  19102.         ld      (hl),d
  19103.         inc     hl
  19104.         pop     de
  19105.         ld      (hl),e
  19106.         inc     hl
  19107.         ld      (hl),d
  19108.         pop     bc
  19109.         ld      hl,BackLevel    ; Point to back fix level
  19110.         inc     (hl)
  19111.         ret     nz
  19112.         xor     a
  19113.         jr      ForceBack
  19114. ;
  19115. ; Fix back level
  19116. ;
  19117. FixBack:
  19118.         ld      a,(BackLevel)   ; Get back fix level
  19119.         or      a
  19120.         ret     z
  19121. ForceBack:
  19122.         push    bc
  19123.         push    de
  19124.         push    iy
  19125.         ld      b,a
  19126.         ld      hl,(MemsTop)    ; Get memory top
  19127. Back_Loop:
  19128.         push    bc
  19129.         ld      e,(hl)
  19130.         inc     hl
  19131.         ld      d,(hl)
  19132.         inc     hl
  19133.         push    hl
  19134.         ex      de,hl
  19135.         call    ChkChn          ; Check chaining
  19136.         pop     hl
  19137.         ld      b,(hl)
  19138.         inc     hl
  19139.         push    hl
  19140.         call    savebyte_b              ; Put byte to file
  19141.         pop     hl
  19142.         ld      b,(hl)
  19143.         inc     hl
  19144.         push    hl
  19145.         call    savebyte_b              ; Put byte to file
  19146.         pop     hl
  19147.         pop     bc
  19148.         djnz    Back_Loop
  19149.         pop     hl
  19150.         pop     de
  19151.         pop     bc
  19152. ;
  19153. ; Check chaining
  19154. ;
  19155. ChkChn:
  19156.          ld     a,(CmpTyp)      ; Get compile flag
  19157.          dec    a               ; Test compiling to memory
  19158.          call z,flushunfinished ;nope
  19159.         push    hl
  19160.         pop     iy
  19161.         ld      a,(CmpTyp)      ; Get compile flag
  19162.         dec     a               ; Test compiling to memory
  19163.         ret     nz              ; yes
  19164.         push    de
  19165.         push    bc
  19166.         ld      de,(CodePC)     ; Get code pointer
  19167.         or      a
  19168.         sbc     hl,de
  19169.         ld      a,l
  19170.         and     7fh
  19171.         ld      (RecPtr),a      ; Set record pointer
  19172.         add     hl,hl
  19173.         ld      l,h
  19174.         rla
  19175.         and     1
  19176.         ld      h,a
  19177.         ld      de,(RRN_off)    ; Get record base
  19178.         add     hl,de           ; Calculate new record
  19179.         ld      de,(FFCB+_rrn)
  19180.         or      a
  19181.         sbc     hl,de
  19182.         add     hl,de
  19183.         jr      z,Chk_sameRRN
  19184.         push    hl
  19185.         call    writerecord_TmpBuff             ; Write record
  19186.         pop     hl
  19187.         ld      (FFCB+_rrn),hl  ; Reset record
  19188. Chk_sameRRN:
  19189.         pop     bc
  19190.         pop     de
  19191.         ret
  19192.  
  19193. ;
  19194. ; Read random record from file
  19195. ; Read a record
  19196. ;
  19197. readrecord_TmpBuff:
  19198.          ;ld hl,(FFCB+_rrn)
  19199.          ;jr $
  19200.         ld      c,_rndrd ; .. load read function
  19201.         jr      l6d09    ; .. fall in read
  19202. ;
  19203. ; Write a record
  19204. ;
  19205. writerecord_TmpBuff:
  19206.         ld      hl,RRN_stat     ; Point to file access
  19207.         set     0,(hl)          ; Set re-read enabled
  19208.         bit     1,(hl)          ; Test record to be written
  19209.         ret     z               ; Nope
  19210.         res     1,(hl)          ; Reset it
  19211. flushunfinishedpp
  19212. ;write unfinished last sector???
  19213.         ld      c,_rndwr
  19214. l6d09:
  19215.         push    bc              ; Save function
  19216.         ld      de,TmpBuff
  19217.         ld      c,_setdma
  19218.         call    _BDOS           ; Set disk buffer
  19219.         pop     bc
  19220.         ld      de,FFCB
  19221.         call    _BDOS           ; Read or write record
  19222.       ret ;КОСТЫЛЬ!!! иначе lister не компилируется на диск (читает сектор за границей файла перед патчем и записью?)
  19223.         or      a
  19224.         ret     z
  19225.         ;dec    a
  19226.         ;ret    z
  19227.         ;cp     3
  19228.         ;ret    z
  19229.          cp 128 ;fail
  19230.          ret nz ;not fail
  19231.         call    ERROR
  19232.         db      _DskFull
  19233. ;
  19234. ; Save environment to stack
  19235. ;
  19236. SavEnv2:
  19237.         exx
  19238.         ld      de,Envir2
  19239.         jr      SavEnv7
  19240. ;
  19241. ; Save environment to stack
  19242. ;
  19243. l6d2a:
  19244.         exx
  19245.         ld      de,Envir1
  19246. SavEnv7:
  19247.         pop     hl
  19248.         ld      (Env_PC),hl
  19249.         ld      hl,-l000d;lfff3
  19250.         add     hl,sp
  19251.         ld      sp,hl
  19252.         ex      de,hl
  19253.         ld      bc,l000d
  19254.         ldir
  19255. BackEnv_PC:
  19256.         ld      hl,(Env_PC)
  19257.         push    hl
  19258.         exx
  19259.         ret
  19260. RestEnv2:
  19261.         exx
  19262.         ld      de,Envir2
  19263.         jr      RestEnv7
  19264. ;
  19265. ; Get back environment
  19266. ;
  19267. RestEnv1:
  19268.         exx
  19269.         ld      de,Envir1
  19270. RestEnv7:
  19271.         pop     hl
  19272.         ld      (Env_PC),hl
  19273.         ld      hl,0;l0000
  19274.         add     hl,sp
  19275.         ld      bc,l000d
  19276.         ldir
  19277.         ld      sp,hl
  19278.         jr      BackEnv_PC
  19279. ;
  19280. ; Restore environment from stack, leave stack intact
  19281. ;
  19282. CpyEnv2:
  19283.         exx
  19284.         ld      de,Envir2
  19285.         jr      CpyEnv7
  19286. l6d63:
  19287.         exx
  19288.         ld      de,Envir1
  19289. CpyEnv7:
  19290.         ld      hl,2;l0002
  19291.         add     hl,sp
  19292.         ld      bc,l000d
  19293.         ldir
  19294.         exx
  19295.         ret
  19296. ;
  19297. ; Store current PC into label table
  19298. ;
  19299. puttolabel_i_y:
  19300.         push    iy
  19301.         pop     de
  19302. puttolabel_d_e:
  19303.         ld      a,d
  19304.         call    puttolabel
  19305.         ld      a,e
  19306. puttolabel:
  19307.         push    hl
  19308.         ld      hl,(LabPtr)     ; Get label pointer
  19309.         ld      (hl),a
  19310.         dec     hl
  19311.         ld      (LabPtr),hl     ; Set label pointer
  19312.         pop     hl
  19313.         jp      ChkOvfl         ; Check enough memory
  19314. ;
  19315. ; Get label
  19316. ;
  19317. GetLabel:
  19318.         ld      a,(ix+0)   ; Get 1st character
  19319.         call    IsItLab         ; Test label character
  19320. ;
  19321. ; Build label
  19322. ;
  19323. SampLabel:
  19324.         call    ErrCY
  19325.         db      _IllChar
  19326.         call    DoubleLabel  ; Verify no double label
  19327. l6d94:
  19328.         call    Reserved ; Verify no reserved word
  19329.         ld      a,(ix+0)
  19330. l6d9a:
  19331.         cp      'a'
  19332.         jr      c,l6da4
  19333.         cp      'z'+1
  19334.         jr      nc,l6da4
  19335.         sub     'a'-'A'
  19336. l6da4:
  19337.         call    puttolabel
  19338.         inc     ix
  19339.         ld      a,(ix+0)
  19340.         call    IsItValid               ; Test valid character
  19341.         jr      nc,l6d9a        ; Yeap
  19342.         ld      hl,(LabPtr)     ; Get label pointer
  19343.         inc     hl
  19344.         set     7,(hl)
  19345.         jp      GetLine         ; Process line
  19346. l6dba:
  19347.         ld      a,(ix+0)
  19348.         call    IsItLab         ; Test label character
  19349.         call    ErrCY
  19350.         db      _IllChar
  19351.         jr      l6d94
  19352. ;
  19353. ; Set label pointer
  19354. ;
  19355. SetLabPtr:
  19356.         ld      hl,(PrevLabPtr) ; Get previous label pointer
  19357.         ld      de,(LabPtr)     ; Get label pointer
  19358.         or      a
  19359.         sbc     hl,de
  19360.         ex      de,hl
  19361.         call    puttolabel_d_e          ; Put to table
  19362.         ld      hl,(LabPtr)     ; Get label pointer
  19363.         ld      (PrevLabPtr),hl ; Unpack into previous
  19364.         ret
  19365. l6ddb:
  19366.         ld      hl,(CurLab)     ; Get current label pointer
  19367.         jr      l6de3
  19368. ;
  19369. ;
  19370. ; Find label from table
  19371. ; ENTRY Reg B holds selected TYPE
  19372. ;       Reg C holds item flag
  19373. ;                0 if 1st item in line
  19374. ;               -1 if not 1st one
  19375. ; EXIT  Zero set if label found
  19376. ;;
  19377. ;; l7bc1 = 00, A = -1, NZ ---->>> Not found
  19378. ;; l7bc1 = type, NZ       ---->>> Not same type as B
  19379. ;;                Z       ---->>> Same type
  19380. ;;              HL, DE hold pointers
  19381. ;
  19382. FndItem:
  19383.         ld      hl,(l7b77)      ; Get top of available memory
  19384. l6de3:
  19385.         ld      (l7b7d),hl
  19386.         ld      a,(FirstVAR)
  19387.         cp      c
  19388.         jr      z,l6e48
  19389.         ld      a,c
  19390.         ld      (FirstVAR),a
  19391.         ld      hl,(PrevLabPtr) ; Get previous label pointer
  19392. l6df3:
  19393.         ld      de,(l7b7d)
  19394.         xor     a
  19395.         sbc     hl,de          ; Test pointer reached
  19396.         add     hl,de
  19397.         jr      nz,l6e03
  19398.         xor     a
  19399.         ld      (l7bc1),a
  19400.         dec     a
  19401.         ret
  19402. l6e03:
  19403.         inc     hl
  19404.         ld      e,(hl)          ; Get length of entry ?????????
  19405.         inc     hl
  19406.         ld      d,(hl)
  19407.         add     hl,de           ; Point to end
  19408.         ld      a,(hl)          ; Test more
  19409.         or      a
  19410.         jr      z,l6df3         ; .. end of table ??????????????
  19411.         dec     hl
  19412.         ld      a,(hl)          ; Get type
  19413.         inc     hl
  19414.         cp      c
  19415.         jr      nz,l6df3        ; .. not what we expect
  19416.         push    ix
  19417.         pop     de   ; Copy pointer
  19418.         push    bc
  19419.         push    hl
  19420.         dec     hl   ; Fix to lable
  19421.         dec     hl
  19422. l6e19:
  19423.         ld      b,(hl) ; Get characters
  19424.         ld      a,(de)
  19425.         dec     hl
  19426.         inc     de
  19427.         ld      c,b       ; Save label
  19428.         res     7,b       ; Clear MSB
  19429.         cp      'a'       ; Check a..z
  19430.         jr      c,l6e2a
  19431.         cp      'z'+1
  19432.         jr      nc,l6e2a
  19433.         sub     'a'-'A'   ; .. map to a..z
  19434. l6e2a:
  19435.         cp      b         ; Compare
  19436.         jr      nz,l6e37
  19437.         bit     7,c        ; Test last character
  19438.         jr      z,l6e19    ; .. nope
  19439.         ld      a,(de)     ; Verify end of label
  19440.         call    IsItValid               ; Test valid character
  19441.         jr      c,l6e3b         ; Nope
  19442. l6e37:
  19443.         pop     hl
  19444.         pop     bc
  19445.         jr      l6df3
  19446. l6e3b:
  19447.         ld      (l7bc2),hl     ; Save pointers
  19448.         ld      (l7bc4),de
  19449.         pop     hl
  19450.         pop     bc
  19451.         ld      a,(hl)         ; Save type
  19452.         ld      (l7bc1),a
  19453. l6e48:
  19454.         ld      hl,(l7bc2)
  19455.         ld      de,(l7bc4)
  19456.         ld      a,(l7bc1)
  19457.         cp      b              ; Fix result
  19458.         ret
  19459. ;
  19460. ; Get TYPE from table
  19461. ; ENTRY Reg B holds TYPE searched for
  19462. ;       Reg C holds flag ???????
  19463. ; EXIT  Zero set if TYPE found
  19464. ;       Reg HL points to TYPE
  19465. ; (Find label with type in reg B)
  19466. ;
  19467. FndLABEL:
  19468.         call    FndItem    ; Find it
  19469.         ret     nz         ; .. nope
  19470.         jr      SetLine    ; .. set source pointer
  19471. ;
  19472. ; Find string
  19473. ; ENTRY <SP> points to length of code
  19474. ;       followed by address of string
  19475. ; EXIT  Zero flag set indicates found
  19476. ; (Find constant string list ^PC)
  19477. ; Z set says found
  19478. ;
  19479. FndTabStr:
  19480.         ex      (sp),hl
  19481.         ld      c,(hl)          ; Get length of data following string
  19482.         inc     hl
  19483.         ld      e,(hl)          ; Get address of string
  19484.         inc     hl
  19485.         ld      d,(hl)
  19486.         inc     hl
  19487.         ex      (sp),hl
  19488.         ex      de,hl
  19489. FndDirStr:
  19490.         call    FndStr          ; Find string
  19491.         ret     z               ; Got it
  19492.         dec     hl              ; Postion to previous character
  19493. FndDirStr_fix:
  19494.         bit     _MB,(hl)        ; Find end of string
  19495.         inc     hl
  19496.         jr      z,FndDirStr_fix
  19497.         ld      b,0
  19498.         add     hl,bc           ; Position to next string in list
  19499.         ld      a,(hl)
  19500.         or      a               ; Test more in list
  19501.         jr      nz,FndDirStr    ; Yeap
  19502.         dec     a               ; Set string not found
  19503.         ret
  19504. ;
  19505. ; Find constant string ^PC
  19506. ; Z set says found
  19507. ;
  19508. FindStr:
  19509.         ex      (sp),hl
  19510.         ld      e,(hl)          ; Get address of string
  19511.         inc     hl
  19512.         ld      d,(hl)
  19513.         inc     hl
  19514.         ex      (sp),hl
  19515.         ex      de,hl
  19516. ;
  19517. ; Find string ^HL
  19518. ;
  19519. FndStr:
  19520.         push    ix              ; Copy source pointer
  19521.         pop     de
  19522.         ld      a,(hl)          ; Get character from searched string
  19523.         call    IsItLab         ; Test label character
  19524.         jr      c,l6e92         ; Nope
  19525.         call    l6e9c           ; Compare
  19526.         ret     nz              ; Not found
  19527.         ld      a,(de)          ; Get character from source
  19528.         call    IsItValid               ; Test valid character
  19529.         jr      c,SetLine               ; Nope
  19530.         or      a
  19531.         ret
  19532. l6e92:
  19533.         call    l6e9c           ; Compare
  19534.         ret     nz              ; Not found
  19535. SetLine:
  19536.         push    de              ; Set resulting source pointer
  19537.         pop     ix
  19538.         jp      GetLine         ; Process line
  19539. ;
  19540. ; Compare reference ^HL: source ^DE
  19541. ; Z set says match
  19542. ;
  19543. l6e9c:
  19544.         push    bc
  19545. l6e9d:
  19546.         ld      b,(hl)          ; Get from reference
  19547.         ld      a,(de)          ; Get from source
  19548.         inc     hl
  19549.         inc     de
  19550.         ld      c,b             ; Save reference
  19551.         res     _MB,b           ; Strip off MSB
  19552.         cp      'a'             ; Test range
  19553.         jr      c,l6eae
  19554.         cp      'z'+1
  19555.         jr      nc,l6eae
  19556.         sub     'a'-'A'         ; Convert to UPPER case
  19557. l6eae:
  19558.         cp      b               ; Compare
  19559.         jr      nz,l6eb6        ; No match
  19560.         bit     _MB,c           ; Test end of reference
  19561.         jr      z,l6e9d         ; Nope
  19562.         xor     a               ; Force match
  19563. l6eb6:
  19564.         pop     bc
  19565.         ret
  19566. ;
  19567. ; Verify no reserved word
  19568. ;
  19569. Reserved:
  19570.         ld      hl,l7513
  19571. l6ebb:
  19572.         ld      c,(hl)
  19573.         inc     c
  19574.         ret     z
  19575.         dec     c
  19576.         inc     hl
  19577.         ld      e,(hl)
  19578.         inc     hl
  19579.         ld      d,(hl)
  19580.         inc     hl
  19581.         push    hl
  19582.         ex      de,hl
  19583.         call    FndDirStr
  19584.         pop     hl
  19585.         jr      nz,l6ebb
  19586.         call    ERROR
  19587.         db      _ResWord
  19588. DoubleLabel:
  19589.         ld      a,(l7b91)       ; Get ???
  19590.         ld      c,a
  19591.         call    l6ddb
  19592.         ld      a,(l7bc1)
  19593.         or      a
  19594.         ret     z
  19595.         call    ERROR
  19596.         db      _DoubleLab
  19597. l6ee0:
  19598.         ld      a,'['
  19599.         call    l6f29
  19600.         ret     z
  19601.         ld      a,(ix+0)
  19602.         cp      '('
  19603.         ret     nz
  19604.         ld      a,(ix+1)
  19605.         cp      '.'
  19606.         ret     nz
  19607. l6ef2:
  19608.         inc     ix
  19609.         jp      NewLine         ; Process line
  19610. ;
  19611. ; Test ] - Z set says found
  19612. ;
  19613. l6ef7:
  19614.         ld      a,']'
  19615.         call    l6f29
  19616.         ret     z
  19617. ;;:::
  19618.         ld      a,(ix+0)
  19619.         cp      '.'
  19620.         ret     nz
  19621.         ld      a,(ix+1)
  19622.         cp      ')'
  19623.         ret     nz
  19624.         jr      l6ef2
  19625. ;
  19626. ; Test colon : - Z set says found
  19627. ;
  19628. l6f0b:
  19629.         ld      a,':'
  19630.         jr      l6f29
  19631. ;
  19632. ; Test semicolon ; - Z set says found
  19633. ;
  19634. l6f0f:
  19635.         ld      a,';'
  19636.         jr      l6f29
  19637. ;
  19638. ; Test comma , - Z set says found
  19639. ;
  19640. l6f13:
  19641.         ld      a,','
  19642.         jr      l6f29
  19643. l6f17:
  19644.         ld      a,'.'
  19645.         jr      l6f29
  19646. ;
  19647. ; Test left parenthesis ( - Z set says found
  19648. ;
  19649. l6f1b:
  19650.         ld      a,'('
  19651.         jr      l6f29
  19652. l6f1f:
  19653.         ld      a,')'
  19654.         jr      l6f29
  19655. ;
  19656. ; Test equate = - Z set says found
  19657. ;
  19658. l6f23:
  19659.         ld      a,'='
  19660.         jr      l6f29
  19661. l6f27:
  19662.         ld      a,'^'
  19663. l6f29:
  19664.         cp      (ix+0)
  19665.         ret     nz
  19666.         jp      NewLine         ; Process line
  19667. ;
  19668. ; Verify [
  19669. ;
  19670. l6f30:
  19671.         call    l6ee0
  19672.         ret     z
  19673.         call    ERROR
  19674.         db      _LftBrExp
  19675. ;
  19676. ; Verify ]
  19677. ;
  19678. l6f38:
  19679.         call    l6ef7           ; Test ]
  19680.         ret     z
  19681.         call    ERROR
  19682.         db      _RgtBrExp
  19683. ;
  19684. ; Verify :
  19685. ;
  19686. l6f40:
  19687.         call    l6f0b           ; Test :
  19688.         ret     z
  19689.         call    ERROR
  19690.         db      _SemiExp
  19691. ;
  19692. ; Verify ;
  19693. ;
  19694. l6f48:
  19695.         call    l6f0f           ; Test ;
  19696.         ret     z               ; Yeap
  19697. l6f4c:
  19698.         call    ERROR
  19699.         db      _ColExp
  19700. l6f50:
  19701.         call    l6f0f           ; Test ;
  19702.         ret     z               ; Yeap
  19703.         ld      a,(l7b98)
  19704.         or      a
  19705.         jr      z,l6f4c
  19706.         call    ERROR
  19707.         db      _Undef
  19708. ;
  19709. ; Verify ,
  19710. ;
  19711. l6f5e:
  19712.         call    l6f13           ; Test ,
  19713.         ret     z               ; Yeap
  19714.         call    ERROR
  19715.         db      _CommaExp
  19716. ;
  19717. ; Verify (
  19718. ;
  19719. l6f66:
  19720.         call    l6f1b           ; Test (
  19721.         ret     z               ; Yeap
  19722.         call    ERROR
  19723.         db      _LftPar
  19724. ;
  19725. ; Verify )
  19726. ;
  19727. l6f6e:
  19728.         call    l6f1f
  19729.         ret     z
  19730.         call    ERROR
  19731.         db      _RgtPar
  19732. ;
  19733. ; Verify =
  19734. ;
  19735. l6f76:
  19736.         call    l6f23           ; Find =
  19737.         ret     z
  19738.         call    ERROR
  19739.         db      _EquExp
  19740. l6f7e:
  19741.         call    FindStr         ; Find :=
  19742.         dw      l7582
  19743.         ret     z               ; Yeap
  19744.         call    ERROR
  19745.         db      _AssigExp
  19746. l6f88:
  19747.         call    FindStr         ; Find OF
  19748.         dw      l7560
  19749.         ret     z               ; Yeap
  19750.         call    ERROR
  19751.         db      _NoOF
  19752. ;
  19753. ; Process source line
  19754. ;
  19755. NewLine:
  19756.         call    l7124           ; Get character from file
  19757. GetLine:
  19758.         xor     a
  19759.         ld      (l7b98),a
  19760.         dec     a
  19761.         ld      (FirstVAR),a
  19762.         ld      a,(ix+0)        ; Get a character
  19763.         or      a               ; Test empty
  19764.         jr      z,NewLine               ; Yeap, so get next
  19765.         cp      ' '             ; Skip blanks
  19766.         jr      z,NewLine
  19767.         cp      tab             ; Skip tabs
  19768.         jr      z,NewLine
  19769.         cp      '('             ; Test possible comment
  19770.         jr      z,l6fb5
  19771.         cp      '{'             ; Test real comment
  19772.         jr      z,l6fbf
  19773. l6fb3:
  19774.         xor     a
  19775.         ret
  19776. l6fb5:
  19777.         ld      a,(ix+1)        ; Get next
  19778.         cp      '*'             ; Test comment
  19779.         jr      nz,l6fb3        ; Nope
  19780.         call    l7124           ; Get next character
  19781. l6fbf:
  19782.         push    bc
  19783.         ld      b,(ix+0)        ; Get comment indicator
  19784.         ld      a,(ix+1)        ; Get next character
  19785.         cp      '$'             ; Test compiler directive
  19786.         jr      z,l6feb         ; Maybe
  19787. l6fca:
  19788.         call    l7124           ; Get next character
  19789. l6fcd:
  19790.         ld      a,b
  19791.         cp      '*'             ; Test two character indicators
  19792.         ld      a,(ix+0)
  19793.         jr      nz,l6fe4        ; Nope
  19794.         cp      b
  19795.         jr      nz,l6fca
  19796.         ld      a,(ix+1)
  19797.         cp      ')'
  19798.         jr      nz,l6fca
  19799.         call    l7124           ; Get character from file
  19800.         jr      l6fe8
  19801. l6fe4:
  19802.         cp      '}'             ; Test end of comment
  19803.         jr      nz,l6fca        ; Nope, wait for
  19804. l6fe8:
  19805.         pop     bc
  19806.         jr      NewLine
  19807. l6feb:
  19808.         push    bc
  19809.         push    de
  19810.         push    hl
  19811.         call    l7124           ; Get character from file
  19812. l6ff1:
  19813.         call    l7124           ; Get character from file
  19814.         ld      a,(ix+0)
  19815.         call    doupcase                ; Convert to upper case
  19816.         cp      'I'             ; Test include or I/O error
  19817.         ld      b,00000001b
  19818.         jr      z,l704d
  19819.         cp      'R'             ; Test index range test
  19820.         ld      b,00000010b
  19821.         jr      z,l704d
  19822.         cp      'A'             ; Test absolute code
  19823.         ld      b,00000100b
  19824.         jr      z,l704d
  19825.         cp      'U'             ; Test user break
  19826.         ld      b,00001000b
  19827.         jr      z,l704d
  19828.         cp      'X'             ; Test arry optimization
  19829.         ld      b,00010000b
  19830.         jr      z,l704d
  19831.         cp      'V'             ; Test var type test
  19832.         ld      b,00100000b
  19833.         jr      z,l704d
  19834.         cp      'B'             ; Test I/O mode
  19835.         ld      b,01000000b
  19836.         jr      z,l704d
  19837.         cp      'C'             ; Test keyboard interrupt
  19838.         ld      b,10000000b
  19839.         jr      z,l704d
  19840.         cp      'W'             ; Test WITH check
  19841.         jr      z,l707a
  19842. ;
  19843. ; Next directives used by MS-DOS only.
  19844. ; They will be checked for compatibility only
  19845. ;
  19846.         ld      b,00000000b
  19847.         cp      'K'             ; Test stack check ([$K+, $K-])
  19848.         jr      z,l704d
  19849.         cp      'D'             ; Test device check ([$D+, $D-])
  19850.         jr      z,l704d
  19851.         cp      'F'             ; Test number of open files ([$Fnum])
  19852.         jr      z,l708e
  19853.         cp      'G'             ; Test input buffer ([$Gnum])
  19854.         jr      z,l708e
  19855.         cp      'P'             ; Test output buffer ([$Pnum])
  19856.         jr      z,l708e
  19857.         call    ERROR           ; Invalid directive
  19858.         db      _CompDirec
  19859. l7048:
  19860.         pop     hl
  19861.         pop     de
  19862.         pop     bc
  19863.         jr      l6fcd
  19864. ;
  19865. ; Set or reset directive $x+ or $x-
  19866. ;
  19867. ; Bit to be attached held in reg B
  19868. ;
  19869. l704d:
  19870.         call    l7124           ; Get character from file
  19871.         ld      a,(ix+0)
  19872.         ld      c,0             ; Init for set
  19873.         cp      '+'             ; Test it
  19874.         jr      z,l7065         ; Yeap
  19875.         dec     c               ; Prepare for reset - all bits set
  19876.         cp      '-'
  19877.         jr      z,l7065
  19878.         dec     b               ; Remember $I is 00000001b - used multiple
  19879.         call    ErrNZ           ; Else error
  19880.         db      _CompDirec
  19881.         jr      l709b           ; Now process include
  19882. l7065:
  19883.         ld      hl,l7b9d        ; Point to options
  19884.         ld      a,(hl)          ; Get current bits
  19885.         xor     c               ; Toggle bits or let in tact
  19886.         or      b               ; Insert bit
  19887.         xor     c               ; Set result
  19888.         ld      (hl),a
  19889. l706d:
  19890.         call    l7124           ; Get character from file
  19891. l7070:
  19892.         ld      a,(ix+0)
  19893.         cp      ','             ; Test more
  19894.         jp      z,l6ff1         ; Yeap
  19895.         jr      l7048
  19896. l707a:
  19897.         call    l7124           ; Get character from file
  19898.         ld      a,(ix+0)
  19899.         call    IsItDigit               ; Test digit
  19900.         call    ErrCY
  19901.         db      _CompDirec
  19902.         sub     '0'
  19903.         ld      (l7bc7),a       ; Change depth for WITH
  19904.         jr      l706d
  19905. ;
  19906. ; Process MS-DOS compatible directives
  19907. ;
  19908. l708e:
  19909.         call    l7124           ; Get character from file
  19910.         ld      a,(ix+0)
  19911.         call    IsItDigit               ; Test digit
  19912.         jr      nc,l708e        ; Yeap, skip over
  19913.         jr      l7070
  19914. l709b:
  19915.         cp      ' '
  19916.         jr      nz,l70a7        ; Skip over directive
  19917.         call    l7124           ; Get character from file
  19918.         ld      a,(ix+0)
  19919.         jr      l709b
  19920. l70a7: ;include???
  19921.         ld      a,(IncFlg)      ; Get memory read flag
  19922.         or      a
  19923.         call    ErrNZ           ; Should be memory read
  19924.         db      _INCLerr
  19925.         push    ix
  19926.         pop     de
  19927.         call    l2d2a           ; Prepare .PAS file
  19928.         push    de
  19929.         pop     ix
  19930.         ld      de,l005c
  19931.         push    de
  19932.          ;jr $
  19933.         ld      c,_open
  19934.         call    _BDOS           ; Open file ;WHERE IS CLOSE???
  19935.         pop     hl
  19936.         inc     a
  19937.         call    ErrZ
  19938.         db      _NoFileErr
  19939.         ld      de,l790f
  19940.         ld      bc,FCBlen
  19941.         ldir                    ; Unpack file
  19942.         ld      a,(CmpTyp)      ; Get compile flag
  19943.         dec     a               ; Test compiling to file
  19944.         jr      z,l70e2         ; Yeap
  19945.         ld      hl,TmpBuff
  19946.         ld      (l7be4),hl      ; Save top of .COM file
  19947.         ld      hl,l79d7        ; Get start of source line
  19948.         ld      a,1
  19949.         jr      l7103
  19950. l70e2:
  19951.         ld      hl,(LabPtr)     ; Get label pointer
  19952.         ld      de,(COMsTop)    ; Get top of .COM file
  19953.         ld      (l7be4),de      ; Save it
  19954.         or      a
  19955.         sbc     hl,de           ; Calculate difference
  19956.         srl     h
  19957.         rr      l
  19958.         ld      a,h
  19959.         or      a
  19960.         call    ErrZ            ; If hi zero, no memory
  19961.         db      _CompOvfl
  19962.         ld      a,l
  19963.         and     RecLng
  19964.         ld      l,a
  19965.         push    hl
  19966.         add     hl,hl
  19967.         ld      a,h
  19968.         pop     hl
  19969.         add     hl,de
  19970. l7103:
  19971.         ld      (INCsTop),hl
  19972.         ld      (l7be9),hl
  19973.         ld      (l7be8),a
  19974.         ld      (IncFlg),a      ; Re/Set memory read flag
  19975.         ld      hl,l0000
  19976.         ld      (l7beb),hl
  19977.         ld      a,(l7b9d)       ; Get options
  19978.         ld      (l7b9f),a
  19979.         ld      a,(l7bc7)       ; Get depth for WITH
  19980.         ld      (l7bc8),a
  19981.         jp      l7048
  19982. ;
  19983. ; Get character from file
  19984. ;
  19985. l7124:
  19986.         ld      a,(ix+0)
  19987.         inc     ix
  19988.         or      a
  19989.         ret     nz
  19990.         push    bc
  19991.         push    de
  19992.         push    hl
  19993.         ld      a,(l7ba2)       ; Get end of file
  19994.         or      a
  19995.         call    ErrNZ
  19996.         db      _IllSrcEnd
  19997.         ld      hl,(l7bd7)      ; Get source pointer
  19998.         ld      (l7bd9),hl      ; Unpack it
  19999.         ld      hl,(l7beb)
  20000.         ld      (l7bed),hl
  20001.         ld      hl,l79d7        ; Get start of source line
  20002.         push    hl
  20003.         pop     ix              ; Copy it
  20004.         ld      b,RecLng-1      ; Set max length
  20005. l714a:
  20006.         push    hl
  20007.         push    bc
  20008.         call    l71f3
  20009.          if TERM
  20010.          ;push af
  20011.          ;push ix
  20012.          ;push iy
  20013.          ;PRCHAR_
  20014.          ;pop iy
  20015.          ;pop ix
  20016.          ;pop af
  20017.          else
  20018.          ;push af
  20019.          ;push ix
  20020.          ;push iy
  20021.          ;PRCHAR
  20022.          ;pop iy
  20023.          ;pop ix
  20024.          ;pop af
  20025.          endif
  20026.         pop     bc
  20027.         pop     hl
  20028.         cp      cr
  20029.         jr      z,l7175
  20030.         cp      eof
  20031.          ;jr z,$ ;never
  20032.         jr      z,l716a
  20033.         cp      tab
  20034.         jr      z,l7161
  20035.         cp      ' '
  20036.         jr      c,l714a
  20037. l7161:
  20038.         djnz    l7166
  20039.         inc     b
  20040.         jr      l714a
  20041. l7166:
  20042.         ld      (hl),a
  20043.         inc     hl
  20044.         jr      l714a
  20045. l716a:
  20046.         ld      (l7ba2),a       ; Set end of file
  20047.         call    l717e
  20048.         call    l718f           ; Test abort
  20049.         jr      l7178
  20050. l7175:
  20051.         call    l717e ;compile_newline
  20052. l7178:
  20053.         ld      (hl),0
  20054.         pop     hl
  20055.         pop     de
  20056.         pop     bc
  20057.         ret
  20058. l717e: ;compile_newline
  20059.         push    af
  20060.         push    hl
  20061.         ld      hl,(l7bef)
  20062.         inc     hl              ; Advance line count
  20063.         ld      (l7bef),hl
  20064.         ld      a,l
  20065.         and     0fh
  20066.         ;jr     z,l7191
  20067.         pop     hl
  20068.         pop     af
  20069.         ret
  20070. ;
  20071. ; Test abortion of compilation
  20072. ;
  20073. l718f:
  20074.         push    af
  20075.         push    hl
  20076. l7191:
  20077.         push    bc
  20078.         push    de
  20079.         push    ix
  20080.         push    iy
  20081.         ld      a,cr
  20082.         call    puttoconsole_a          ; Put to console
  20083.         ld      a,(IncFlg)      ; Test memory read
  20084.         or      a
  20085.         jr      z,l71a6         ; Yeap
  20086.         ld      a,'I'
  20087.         jr      l71a8
  20088. l71a6:
  20089.         ld      a,' '
  20090. l71a8:
  20091.         call    puttoconsole_a          ; Put to console
  20092.         ld      a,' '
  20093.         call    puttoconsole_a          ; Put to console
  20094.         ld      hl,(l7bef)      ; Get line count
  20095.         call    l2e61           ; Print number
  20096.         call    l00a0           ; Test key pressed
  20097.         or      a
  20098.         jr      z,l71ea
  20099.         call    l0200
  20100.         db      '   *** Abort compilation'
  20101.         db      null
  20102.         call    l2d01           ; Ask for YES or NO
  20103.         call    ErrNZ
  20104.         db      _ABORT
  20105.         ld      b,32
  20106. l71e1:
  20107.         call    l0200
  20108.         db      bs,' ',bs
  20109.         db      null
  20110.         djnz    l71e1
  20111. l71ea:
  20112.         pop     iy
  20113.         pop     ix
  20114.         pop     de
  20115.         pop     bc
  20116.         pop     hl
  20117.         pop     af
  20118.         ret
  20119. ;
  20120. ; Read character from file
  20121. ;
  20122. l71f3:
  20123.         ld      a,(IncFlg)      ; Test memory read
  20124.         or      a
  20125.         jr      nz,l7205        ; Nope
  20126. l71f9:
  20127.         ld      hl,(l7bd7)      ; Get source pointer
  20128.         ld      a,(hl)
  20129.         cp      eof             ; Test end of file
  20130.         ret     z               ; Yeap
  20131.         inc     hl
  20132.         ld      (l7bd7),hl
  20133.         ret
  20134. l7205:
  20135.         ld      hl,(l7be9)
  20136.         ld      de,(INCsTop)
  20137.         or      a
  20138.         sbc     hl,de
  20139.         add     hl,de
  20140.         jr      c,l7242
  20141.         ld      de,(l7be4)      ; Get top of .COM file
  20142.         ld      a,(l7be8)
  20143.         ld      b,a
  20144. l721a:
  20145.         push    bc
  20146.         push    de
  20147.         ld      c,_setdma
  20148.         call    _BDOS           ; Set disk buffer
  20149.         ld      de,l790f
  20150.         ld      c,_rdseq
  20151.         call    _BDOS           ; Read record
  20152.         pop     de
  20153.         pop     bc
  20154.         ;or     a
  20155.         ;jr     nz,l7237
  20156.          xor 128 ;EOF in NedoOS
  20157.          jr z,l7237
  20158.         ;ld     hl,RecLng
  20159.          ld l,a
  20160.          ld h,0
  20161. ;CP/M has eofs in the end of last sector?
  20162. ;do this by hand:
  20163.         xor 128
  20164.         jr z,readchar_load_noaddzeros ;full sector
  20165. ;a=128+bytes loaded
  20166.         neg
  20167. ;a=128-bytes loaded
  20168.         push bc
  20169.         push de
  20170.         ld b,a
  20171.         ld a,e
  20172.         add a,127
  20173.         ld e,a
  20174.         adc a,d
  20175.         sub e
  20176.         ld d,a
  20177.         ;de= Point to buffer end
  20178.         ld a,eof;-1
  20179.         ld (de),a
  20180.         dec de
  20181.         djnz $-2
  20182.         pop de
  20183.         pop bc
  20184. readchar_load_noaddzeros
  20185.         add     hl,de           ; Advance buffer
  20186.         ex      de,hl
  20187.         djnz    l721a
  20188.         jr      l723f
  20189. l7237:
  20190.         ld      a,eof           ; Set end of file
  20191.         ld      (de),a
  20192.         inc     de
  20193.         ld      (INCsTop),de
  20194. l723f:
  20195.         ld      hl,(l7be4)      ; Get top of .COM file
  20196. l7242:
  20197.         ld      a,(hl)
  20198.         inc     hl
  20199.         ld      (l7be9),hl
  20200.         cp      eof
  20201.         jr      nz,l725d
  20202.          ld c,_close
  20203.          call BDOS_with_FCB1
  20204.         xor     a
  20205.         ld      (IncFlg),a      ; Enable memory read
  20206.         ld      a,(l7b9f)
  20207.         ld      (l7b9d),a       ; Reset options
  20208.         ld      a,(l7bc8)
  20209.         ld      (l7bc7),a       ; Set depth for WITH
  20210.         jp      l71f9
  20211. l725d:
  20212.         ld      hl,(l7beb)
  20213.         inc     hl
  20214.         ld      (l7beb),hl
  20215.         ret
  20216. ;
  20217. ; Perform OS call
  20218. ;
  20219. _BDOS:
  20220.         push    ix              ; Preserve index registers
  20221.         push    iy
  20222.         call    BDOS            ; Call system
  20223.         pop     iy
  20224.         pop     ix
  20225.         ret
  20226. ;
  20227. ; Test label character
  20228. ; C set says no
  20229. ;
  20230. IsItLab:
  20231.         cp      'A'
  20232.         ret     c
  20233.         cp      'Z'+1
  20234.         ccf
  20235.         ret     nc
  20236.         cp      '_'
  20237.         ret     z
  20238.         cp      'a'
  20239.         ret     c
  20240.         cp      'z'+1
  20241.         ccf
  20242.         ret
  20243. ;
  20244. ; Test valid character
  20245. ; C set says no
  20246. ;
  20247. IsItValid:
  20248.         call    IsItLab         ; Test label character
  20249.         ret     nc              ; Yeap
  20250. ;
  20251. ; Test character a digit
  20252. ; C set says no
  20253. ;
  20254. IsItDigit:
  20255.         cp      '0'             ; Test digit
  20256.         ret     c
  20257.         cp      '9'+1
  20258.         ccf
  20259.         ret
  20260. ;
  20261. ; Compare signed integers HL:DE
  20262. ;
  20263. ; C set if HL<DE
  20264. ; Z set if HL=DE
  20265. ;
  20266. l728d:
  20267.         ld      a,h
  20268.         xor     d
  20269.         ld      a,h
  20270.         jp      m,l7298
  20271.         cp      d
  20272.         ret     nz
  20273.         ld      a,l
  20274.         cp      e
  20275.         ret
  20276. l7298:
  20277.         rla
  20278.         ret
  20279. ;
  20280. ; HL:=HL*DE - C set on overflow
  20281. ;
  20282. l729a:
  20283.         ld      b,h
  20284.         ld      c,l
  20285.         ld      hl,0            ; Init product
  20286.         ld      a,16
  20287. l72a1:
  20288.         add     hl,hl
  20289.         ret     c
  20290.         ex      de,hl
  20291.         add     hl,hl
  20292.         ex      de,hl
  20293.         jr      nc,l72aa
  20294.         add     hl,bc
  20295.         ret     c
  20296. l72aa:
  20297.         dec     a
  20298.         jr      nz,l72a1
  20299.         ret
  20300. ;
  20301. ; HL:=HL DIV DE                         *** NOT USED HERE
  20302. ; HL:=HL MOD DE
  20303. ;
  20304.         ld      b,d
  20305.         ld      c,e
  20306.         ex      de,hl
  20307.         xor     a
  20308.         ld      h,a
  20309.         ld      l,a
  20310.         ld      a,17
  20311. l72b6:
  20312.         adc     hl,hl
  20313.         sbc     hl,bc
  20314.         jr      nc,l72be
  20315.         add     hl,bc
  20316.         scf
  20317. l72be:
  20318.         ccf
  20319.         rl      e
  20320.         rl      d
  20321.         dec     a
  20322.         jr      nz,l72b6
  20323.         ex      de,hl
  20324.         ret
  20325. ;
  20326. ; Process error if entry C
  20327. ;
  20328. ErrCY:
  20329.         ex      (sp),hl
  20330.         inc     hl              ; Fix caller's address
  20331.         ex      (sp),hl
  20332.         ret     nc              ; No error
  20333.         jr      l72de
  20334. l72ce:: ;;**
  20335.         ex      (sp),hl
  20336.         inc     hl              ; Fix caller's address
  20337.         ex      (sp),hl
  20338.         ret     c               ; No error
  20339.         jr      l72de
  20340. ;
  20341. ; Process error if entry Z
  20342. ;
  20343. ErrZ:
  20344.         ex      (sp),hl
  20345.         inc     hl              ; Fix caller's address
  20346.         ex      (sp),hl
  20347.         ret     nz              ; No error
  20348.         jr      l72de
  20349. ;
  20350. ; Process error if entry NZ
  20351. ;
  20352. ErrNZ:
  20353.         ex      (sp),hl
  20354.         inc     hl              ; Fix caller's address
  20355.         ex      (sp),hl
  20356.         ret     z               ; No error
  20357. ;
  20358. ; Common entry of error routine
  20359. ;
  20360. l72de:
  20361.         pop     hl              ; Get back caller
  20362.         dec     hl              ; Fix pointer
  20363.         push    hl
  20364. ;
  20365. ; Process error
  20366. ;
  20367. ERROR:
  20368.         pop     hl              ; Get pointer
  20369.         ld      a,(hl)          ; Fetch error number
  20370. l72e3:
  20371.         call    l718f           ; Test abort
  20372.         ld      (l7901),a
  20373.         or      a
  20374.         jr      z,l730c
  20375.         push    ix
  20376.         pop     hl
  20377.         ld      de,l79d7        ; Get start of source line
  20378.         sbc     hl,de
  20379.         ld      de,(l7bed)
  20380.         ld      a,(IncFlg)      ; Test memory read
  20381.         or      a
  20382.         jr      nz,l7308        ; Nope
  20383.         ld      de,(l4544)      ; Get start of text
  20384.         sbc     hl,de
  20385.         ld      de,(l7bd9)      ; Get back source pointer
  20386. l7308:
  20387.         add     hl,de
  20388.         ld      (l790c),hl      ; Save current editor address
  20389. l730c:
  20390.         ld      a,(CmpTyp)      ; Get compile flag
  20391.         dec     a               ; Test compiling to file
  20392.         jr      nz,l731a        ; Nope
  20393.         ld      de,FFCB
  20394.         ld      c,_close
  20395.         call    _BDOS           ; Close file
  20396. l731a:
  20397.         ld      sp,(l7b71)      ; Get back stack
  20398.         ret                     ; Exit compiler
  20399.  
  20400. ;
  20401. ; Compiler tables
  20402. ; Internal label table
  20403. ;
  20404. ; -->> INTEGER
  20405. ;
  20406. l731f:
  20407.         dw      _.INT
  20408. ssINT:
  20409.         dw      l74d3+7
  20410.         db      'R'+MSB,'EGETNI'
  20411.         db      0,_Type
  20412. _.INT   equ     $-ssINT
  20413. ;
  20414. ; -->> CHAR
  20415. ;
  20416.         dw      _.CHAR
  20417. ssCHAR:
  20418.         dw      l74db+7
  20419.         db      'R'+MSB,'AHC'
  20420.         db      0,_Type
  20421. _.CHAR  equ     $-ssCHAR
  20422. ;
  20423. ; -->> REAL
  20424. ;
  20425.         dw      _.REAL
  20426. ssREAL:
  20427.         dw      l74e3+7
  20428.         db      'L'+MSB,'AER'
  20429.         db      0,_Type
  20430. _.REAL  equ     $-ssREAL
  20431. ;
  20432. ; -->> BOOLEAN
  20433. ;
  20434.         dw      _.BOOL
  20435. ssBOOL:
  20436.         dw      l74eb+7
  20437.         db      'N'+MSB,'AELOOB'
  20438.         db      0,_Type
  20439. _.BOOL  equ     $-ssBOOL
  20440. ;
  20441. ; -->> TEXT
  20442. ;
  20443.         dw      _.TEXT
  20444. ssTEXT:
  20445.         dw      l74f3+7 ;text file type???
  20446.         db      'T'+MSB,'XET'
  20447.         db      0,_Type
  20448. _.TEXT  equ     $-ssTEXT
  20449. ;
  20450. ; -->> BYTE
  20451. ;
  20452.         dw      _.BYTE
  20453. ssBYTE:
  20454.         dw      l74fb+7 ;byte type
  20455.         db      'E'+MSB,'TYB'
  20456.         db      0,_Type
  20457. _.BYTE  equ     $-ssBYTE
  20458. ;
  20459. ; -->> TRUE
  20460. ;
  20461.         dw      _.TRUE
  20462. ssTRUE:
  20463.         dw      _TRUE
  20464.         db      _Bool
  20465.         db      'E'+MSB,'URT'
  20466.         db      0,_Const
  20467. _.TRUE  equ     $-ssTRUE
  20468. ;
  20469. ; -->> FALSE
  20470. ;
  20471.         dw      _.FALSE
  20472. ssFALSE:
  20473.         dw      FALSE
  20474.         db      _Bool
  20475.         db      'E'+MSB,'SLAF'
  20476.         db      0,_Const
  20477. _.FALSE equ     $-ssFALSE
  20478. ;
  20479. ; -->> MAXINT
  20480. ;
  20481.         dw      _.MXINT
  20482. ssMAXINT:
  20483.         dw      MAXINT
  20484.         db      _Integ
  20485.         db      'T'+MSB,'NIXAM'
  20486.         db      0,_Const
  20487. _.MXINT equ     $-ssMAXINT
  20488. ;
  20489. ; -->> PI
  20490. ;
  20491.         dw      _.PI
  20492. ssPI:
  20493.         db      082h,021h,0a2h,0dah,00fh,049h
  20494.         db      _Real
  20495.         db      'I'+MSB,'P'
  20496.         db      0,_Const
  20497. _.PI    equ     $-ssPI
  20498. ;
  20499. ; -->> OUTPUT
  20500. ;
  20501.         dw      _.OUTP
  20502. ssOUTP:
  20503.         dw      l74f3+7 ;text file type???
  20504.         dw      l00c2
  20505.         db      0
  20506.         db      'T'+MSB,'UPTUO'
  20507.         db      0,4
  20508. _.OUTP  equ     $-ssOUTP
  20509. ;
  20510. ; -->> INPUT
  20511. ;
  20512.         dw      _.INPT
  20513. ssINPT:
  20514.         dw      l74f3+7 ;text file type???
  20515.         dw      l00c2
  20516.         db      0
  20517.         db      'T'+MSB,'UPNI'
  20518.         db      0,_Ptr
  20519. _.INPT  equ     $-ssINPT
  20520. ;
  20521. ; -->> CON
  20522. ;
  20523.         dw      _.CON
  20524. ssCON:
  20525.         dw      l74f3+7 ;text file type???
  20526.         dw      l00b8
  20527.         db      0
  20528.         db      'N'+MSB,'OC'
  20529.         db      0,_Ptr
  20530. _.CON   equ     $-ssCON
  20531. ;
  20532. ; -->> TRM
  20533. ;
  20534.         dw      _.TRM
  20535. ssTRM:
  20536.         dw      l74f3+7 ;text file type???
  20537.         dw      l00b8
  20538.         db      0
  20539.         db      'M'+MSB,'RT'
  20540.         db      0,_Ptr
  20541. _.TRM   equ     $-ssTRM
  20542. ;
  20543. ; -->> KBD
  20544. ;
  20545.         dw      _.KBD
  20546. ssKBD:
  20547.         dw      l74f3+7 ;text file type???
  20548.         dw      l00ba
  20549.         db      0
  20550.         db      'D'+MSB,'BK'
  20551.         db      0,_Ptr
  20552. _.KBD   equ     $-ssKBD
  20553. ;
  20554. ; -->> LST
  20555. ;
  20556.         dw      _.LST
  20557. ssLST:
  20558.         dw      l74f3+7 ;text file type???
  20559.         dw      l00bc
  20560.         db      0
  20561.         db      'T'+MSB,'SL'
  20562.         db      0,_Ptr
  20563. _.LST   equ     $-ssLST
  20564. ;
  20565. ; -->> AUX
  20566. ;
  20567.         dw      _.AUX
  20568. ssAUX:
  20569.         dw      l74f3+7 ;text file type???
  20570.         dw      l00be
  20571.         db      0
  20572.         db      'X'+MSB,'UA'
  20573.         db      0,_Ptr
  20574. _.AUX   equ     $-ssAUX
  20575. ;
  20576. ; -->> USR
  20577. ;
  20578.         dw      _.USR
  20579. ssUSR:
  20580.         dw      l74f3+7 ;text file type???
  20581.         dw      l00c0
  20582.         db      0
  20583.         db      'R'+MSB,'SU'
  20584.         db      0,_Ptr
  20585. _.USR   equ     $-ssUSR
  20586. ;
  20587. ; -->> BUFLEN
  20588. ;
  20589.         dw      _.BUFL
  20590. ssBUFL:
  20591.         dw      l74fb+7 ;byte type
  20592.         dw      l00d1
  20593.         db      0
  20594.         db      'N'+MSB,'ELFUB'
  20595.         db      0,_Ptr
  20596. _.BUFL  equ     $-ssBUFL
  20597. ;
  20598. ; -->> HEAPPTR
  20599. ;
  20600.         dw      _.HEAP
  20601. ssHEAP:
  20602.         dw      l74d3+7 ;integer type
  20603.         dw      l00c4
  20604.         db      0
  20605.         db      'R'+MSB,'TPPAEH'
  20606.         db      0,_Ptr
  20607. _.HEAP  equ     $-ssHEAP
  20608. ;
  20609. ; -->> RECURPTR
  20610. ;
  20611.         dw      _.RECUR
  20612. ssRECUR:
  20613.         dw      l74d3+7 ;integer type
  20614.         dw      l00c6
  20615.         db      0
  20616.         db      'R'+MSB,'TPRUCER'
  20617.         db      0,_Ptr
  20618. _.RECUR equ     $-ssRECUR
  20619. ;
  20620. ; -->> CONSTPTR
  20621. ;
  20622.         dw      _.CONSP
  20623. ssCONSP:
  20624.         dw      l74d3+7 ;integer type
  20625.         dw      l00a0+1
  20626.         db      0
  20627.         db      'R'+MSB,'TPTSNOC'
  20628.         db      0,_Ptr
  20629. _.CONSP equ     $-ssCONSP
  20630. ;
  20631. ; -->> CONINPTR
  20632. ;
  20633.         dw      _.CONIP
  20634. ssCONIP:
  20635.         dw      l74d3+7 ;integer type
  20636.         dw      l00a3+1
  20637.         db      0
  20638.         db      'R'+MSB,'TPNINOC'
  20639.         db      0,_Ptr
  20640. _.CONIP equ     $-ssCONIP
  20641. ;
  20642. ; -->> CONOUTPTR
  20643. ;
  20644.         dw      _.CONOP
  20645. ssCONOP:
  20646.         dw      l74d3+7 ;integer type
  20647.         dw      l00a6+1
  20648.         db      0
  20649.         db      'R'+MSB,'TPTUONOC'
  20650.         db      0,_Ptr
  20651. _.CONOP equ     $-ssCONOP
  20652. ;
  20653. ; -->> LSTOUTPTR
  20654. ;
  20655.         dw      _.LSTOP
  20656. ssLSTOP:
  20657.         dw      l74d3+7 ;integer type
  20658.         dw      l00a9+1
  20659.         db      0
  20660.         db      'R'+MSB,'TPTUOTSL'
  20661.         db      0,_Ptr
  20662. _.LSTOP equ     $-ssLSTOP
  20663. ;
  20664. ; -->> AUXINPTR
  20665. ;
  20666.         dw      _.AUXIP
  20667. ssAUXIP:
  20668.         dw      l74d3+7 ;integer type
  20669.         dw      l00af+1
  20670.         db      0
  20671.         db      'R'+MSB,'TPNIXUA'
  20672.         db      0,_Ptr
  20673. _.AUXIP equ     $-ssAUXIP
  20674. ;
  20675. ; -->> AUXOUTPTR
  20676. ;
  20677.         dw      _.AUXOP
  20678. ssAUXOP:
  20679.         dw      l74d3+7 ;integer type
  20680.         dw      l00ac+1
  20681.         db      0
  20682.         db      'R'+MSB,'TPTUOXUA'
  20683.         db      0,_Ptr
  20684. _.AUXOP equ     $-ssAUXOP
  20685. ;
  20686. ; -->> USRINPTR
  20687. ;
  20688.         dw      _.USRIP
  20689. ssUSRIP:
  20690.         dw      l74d3+7 ;integer type
  20691.         dw      l00b5+1
  20692.         db      0
  20693.         db      'R'+MSB,'TPNIRSU'
  20694.         db      0,_Ptr
  20695. _.USRIP equ     $-ssUSRIP
  20696. ;
  20697. ; -->> USROUTPTR
  20698. ;
  20699.         dw      _.USROP
  20700. ssUSROP:
  20701.         dw      l74d3+7 ;integer type
  20702.         dw      l00b2+1
  20703.         db      0
  20704.         db      'R'+MSB,'TPTUORSU'
  20705.         db      0,_Ptr
  20706. _.USROP equ     $-ssUSROP
  20707. ;
  20708. ; -->> ERRORPTR
  20709. ;
  20710.         dw      _.ERRPT
  20711. ssERRPT:
  20712.         dw      l74d3+7 ;integer type
  20713.         dw      l00da
  20714.         db      0
  20715.         db      'R'+MSB,'TPRORRE'
  20716.         db      0,_Ptr
  20717. _.ERRPT equ     $-ssERRPT
  20718. ;
  20719. ; -->> CBREAK
  20720. ;
  20721.         dw      _.CBRK
  20722. ssCBRK:
  20723.         dw      l74eb+7
  20724.         dw      l00dd
  20725.         db      0
  20726.         db      'K'+MSB,'AERBC'
  20727.         db      0,_Ptr
  20728. _.CBRK  equ     $-ssCBRK
  20729. IntLabTab:
  20730. LenLab  equ     IntLabTab-l731f
  20731. ;
  20732. ; Standard type length table
  20733. ; Note HI-LO entries of definition words
  20734. ;
  20735.  
  20736. dww     macro   val
  20737.         db      HIGH val
  20738.         db      LOW  val
  20739.         endm
  20740.  
  20741. l74d3:
  20742.         dww     2               ; Length for this type
  20743.         dww     MAXINT          ; Max value
  20744.         dww     (-MAXINT-1)     ; Min value
  20745.         dww     _Integ          ; Type
  20746. l74db:
  20747.         dww     1
  20748.         dww     255
  20749.         dww     0
  20750.         dww     _Char
  20751. l74e3:
  20752.         dww     6
  20753.         dww     0
  20754.         dww     0
  20755.         dww     _Real
  20756. l74eb:
  20757.         dww     1
  20758.         dww     _TRUE
  20759.         dww     FALSE
  20760.         dww     _Bool
  20761. l74f3:
  20762.         dww     (FIBlen+RecLng)
  20763.         dww     0
  20764.         dww     0
  20765.         dww     _TxtF
  20766. l74fb:
  20767.         dww     1
  20768.         dww     255
  20769.         dww     0
  20770.         dww     _Integ
  20771. ;
  20772.         dww     (DefSTR+1)
  20773.         dww     0
  20774.         dww     0
  20775.         dww     _String
  20776. l750b:
  20777.         dww     0
  20778.         dww     0
  20779.         dww     0
  20780.         dww     0
  20781. ;
  20782. ; Table of reserved words
  20783. ;
  20784. l7513:
  20785.         db      0
  20786.         dw      l7529
  20787.         db      _Byte
  20788.         dw      l7584
  20789.         db      _Addr
  20790.         dw      l75bb
  20791.         db      _Byte
  20792.         dw      l75f5
  20793.         db      _Byte
  20794.         dw      l7604
  20795.         db      _Byte
  20796.         dw      l761d
  20797.         db      _Byte
  20798.         dw      l7634
  20799.         db      -1
  20800. ;
  20801. ; Keywords
  20802. ;
  20803. l7529:
  20804.         dc      'PROGRAM'
  20805. l7530:
  20806.         dc      'END'
  20807. l7533:
  20808.         dc      'FORWARD'
  20809. l753a:
  20810.         dc      'EXTERNAL'
  20811. l7542:
  20812.         dc      'PACKED'
  20813. l7548:
  20814.         dc      'ARRAY'
  20815. l754d:
  20816.         dc      'FILE'
  20817. l7551:
  20818.         dc      'SET'
  20819. l7554:
  20820.         dc      'RECORD'
  20821. l755a:
  20822.         dc      'STRING'
  20823. l7560:
  20824.         dc      'OF'
  20825. l7562:
  20826.         dc      'ABSOLUTE'
  20827. l756a:
  20828.         dc      'THEN'
  20829. l756e:
  20830.         dc      'ELSE'
  20831. l7572:
  20832.         dc      'DO'
  20833. l7574:
  20834.         dc      'UNTIL'
  20835. l7579:
  20836.         dc      'NOT'
  20837. l757c:
  20838.         dc      'NIL'
  20839.         db      0
  20840. l7580:
  20841.         dc      '..'
  20842. l7582:
  20843.         dc      ':='
  20844. ;
  20845. ; Main block table
  20846. ; -->> Code is type
  20847. ;
  20848. l7584:
  20849.         dc      'LABEL'
  20850.         db      1
  20851.         dc      'CONST'
  20852.         db      2
  20853.         dc      'TYPE'
  20854.         db      3
  20855. l7595:
  20856.         dc      'VAR'
  20857.         db      4
  20858.         dc      'BEGIN'
  20859.         db      8
  20860. l759f:
  20861.         dc      'OVERLAY'
  20862.         db      7
  20863. l75a7:
  20864.         dc      'PROCEDURE'
  20865.         db      5
  20866.         dc      'FUNCTION'
  20867.         db      6
  20868.         db      0
  20869. ;
  20870. ; Statement table
  20871. ;
  20872. l75bb:
  20873.         dc      'BEGIN'
  20874.         dw      l5377
  20875.         dc      'IF'
  20876.         dw      l53ef
  20877.         dc      'WHILE'
  20878.         dw      l5424
  20879.         dc      'REPEAT'
  20880.         dw      l544c
  20881.         dc      'FOR'
  20882.         dw      l546b
  20883. l75da:
  20884.         dc      'CASE'
  20885.         dw      l5521
  20886.         dc      'GOTO'
  20887.         dw      l5626
  20888.         dc      'WITH'
  20889.         dw      l564e
  20890.         dc      'INLINE'
  20891.         dw      l5698
  20892.         db      0
  20893. l75f5:
  20894.         dc      'TO'
  20895.         inc     hl
  20896.         dc      'DOWNTO'
  20897.         dec     hl
  20898.         db      0
  20899. l7600:
  20900.         db      '*'+0x80
  20901.         db      0
  20902.         db      '/'+0x80
  20903.         db      1
  20904. l7604:
  20905.         dc      'AND'
  20906.         db      2
  20907.         dc      'DIV'
  20908.         db      3
  20909.         dc      'MOD'
  20910.         db      4
  20911.         dc      'SHL'
  20912.         db      5
  20913.         dc      'SHR'
  20914.         db      6
  20915.         db      0
  20916. l7619:
  20917.         db      '+'+0x80
  20918.         db      0
  20919.         db      '-'+0x80
  20920.         db      1
  20921. l761d:
  20922.         dc      'OR'
  20923.         db      2
  20924.         dc      'XOR'
  20925.         db      3
  20926.         db      0
  20927. l7625:
  20928.         db      '='+0x80
  20929.         db      00000000b
  20930.         db      '<','>'+0x80
  20931.         db      00001000b
  20932.         db      '>','='+0x80
  20933.         db      00010000b
  20934.         db      '<','='+0x80
  20935.         db      00011000b
  20936.         db      '>'+0x80
  20937.         db      00100000b
  20938.         db      '<'+0x80
  20939.         db      00101000b
  20940. l7634:
  20941.         dc      'IN'
  20942.         db      11111111b
  20943.         db      0
  20944. l7638:
  20945.         dc      'WRITELN'
  20946.         dw      l5ae7
  20947.         dc      'WRITE'
  20948.         dw      l5ae8
  20949.         dc      'READLN'
  20950.         dw      l5a32
  20951.         dc      'READ'
  20952.         dw      l5a33
  20953.         dc      'DELETE'
  20954.         dw      l5c66
  20955.         dc      'INSERT'
  20956.         dw      l5c87
  20957.         dc      'ASSIGN'
  20958.         dw      l5943
  20959.         dc      'RESET'
  20960.         dw      l59b9
  20961.         dc      'REWRITE'
  20962.         dw      l59be
  20963.         dc      'CLOSE'
  20964.         dw      l59db
  20965.         dc      'ERASE'
  20966.         dw      l5971
  20967.         dc      'RENAME'
  20968.         dw      l5966
  20969.         dc      'SEEK'
  20970.         dw      l598c
  20971.         dc      'GETMEM'
  20972.         dw      l5d94
  20973.         dc      'NEW'
  20974.         dw      l5d9f
  20975.         dc      'FREEMEM'
  20976.         dw      l5db4
  20977.         dc      'DISPOSE'
  20978.         dw      l5dbf
  20979.         dc      'MARK'
  20980.         dw      l5dd4
  20981.         dc      'RELEASE'
  20982.         dw      l5dd9
  20983.         dc      'OVRDRIVE'
  20984.         dw      l5df9
  20985.         dc      'CRTINIT'
  20986.         dw      l5e38
  20987.         dc      'CRTEXIT'
  20988.         dw      l5e3d
  20989.         dc      'GOTOXY'
  20990.         dw      l5d6d
  20991.         dc      'CLRSCR'
  20992.         dw      l5e42
  20993.         dc      'CLREOL'
  20994.         dw      l5e48
  20995.         dc      'NORMVIDEO'
  20996.         dw      l5e4d
  20997.         dc      'HIGHVIDEO'
  20998.         dw      l5e4d
  20999.         dc      'LOWVIDEO'
  21000.         dw      l5e52
  21001.         dc      'INSLINE'
  21002.         dw      l5e57
  21003.         dc      'DELLINE'
  21004.         dw      l5e5c
  21005.         dc      'DELAY'
  21006.         dw      l5d89
  21007.         dc      'BLOCKREAD'
  21008.         dw      l5c16
  21009.         dc      'BLOCKWRITE'
  21010.         dw      l5c1e
  21011.         dc      'RANDOMIZE'
  21012.         dw      l5d83
  21013.         dc      'MOVE'
  21014.         dw      l5e05
  21015.         dc      'FILLCHAR'
  21016.         dw      l5e1a
  21017.         dc      'EXIT'
  21018.         dw      l5e61
  21019.         dc      'HALT'
  21020.         dw      l5e67
  21021.         dc      'PORT'
  21022.         dw      l5e6d
  21023.         dc      'STACKPTR'
  21024.         dw      l5e78
  21025.         dc      'FLUSH'
  21026.         dw      l59ab
  21027.         dc      'EXECUTE'
  21028.         dw      l597e
  21029.         dc      'CHAIN'
  21030.         dw      l5979
  21031.         dc      'STR'
  21032.         dw      l5cba
  21033.         dc      'VAL'
  21034.         dw      l5d22
  21035.         dc      'BDOS'
  21036.         dw      l6553
  21037.         dc      'BIOS'
  21038.         dw      l651e
  21039.         db      0
  21040. l77b1:
  21041.         dc      'CHR'
  21042.         dw      l6425
  21043.         dc      'ORD'
  21044.         dw      l6411
  21045.         dc      'COPY'
  21046.         dw      l6460
  21047.         dc      'LENGTH'
  21048.         dw      l6441
  21049.         dc      'POS'
  21050.         dw      l6452
  21051.         dc      'CONCAT'
  21052.         dw      l6481
  21053.         dc      'SUCC'
  21054.         dw      l63d4
  21055.         dc      'PRED'
  21056.         dw      l63d7
  21057.         dc      'UPCASE'
  21058.         dw      l6437
  21059.         dc      'TRUNC'
  21060.         dw      l63be
  21061.         dc      'ROUND'
  21062.         dw      l63c3
  21063.         dc      'ODD'
  21064.         dw      l6401
  21065.         dc      'ABS'
  21066.         dw      l6371
  21067.         dc      'SQR'
  21068.         dw      l6360
  21069.         dc      'SQRT'
  21070.         dw      l6385
  21071.         dc      'SIN'
  21072.         dw      l638a
  21073.         dc      'COS'
  21074.         dw      l638f
  21075.         dc      'ARCTAN'
  21076.         dw      l6394
  21077.         dc      'LN'
  21078.         dw      l6399
  21079.         dc      'EXP'
  21080.         dw      l639e
  21081.         dc      'INT'
  21082.         dw      l63a3
  21083.         dc      'FRAC'
  21084.         dw      l63a8
  21085.         dc      'RANDOM'
  21086.         dw      l64ac
  21087.         dc      'PARAMCOUNT'
  21088.         dw      l649c
  21089.         dc      'PARAMSTR'
  21090.         dw      l64a1
  21091.         dc      'LO'
  21092.         dw      l63e1
  21093.         dc      'HI'
  21094.         dw      l63eb
  21095.         dc      'SWAP'
  21096.         dw      l63f6
  21097.         dc      'PTR'
  21098.         dw      l642b
  21099.         dc      'IORESULT'
  21100.         dw      l64c4
  21101.         dc      'EOF'
  21102.         dw      l64c9
  21103.         dc      'EOLN'
  21104.         dw      l64df
  21105.         dc      'SEEKEOF'
  21106.         dw      l64d5
  21107.         dc      'SEEKEOLN'
  21108.         dw      l64da
  21109.         dc      'FILESIZE'
  21110.         dw      l64fa
  21111.         dc      'FILEPOS'
  21112.         dw      l64f2
  21113.         dc      'KEYPRESSED'
  21114.         dw      l640c
  21115.         dc      'MEMAVAIL'
  21116.         dw      l6514
  21117.         dc      'MAXAVAIL'
  21118.         dw      l6519
  21119.         dc      'PORT'
  21120.         dw      l65bf
  21121.         dc      'STACKPTR'
  21122.         dw      l65ca
  21123.         dc      'ADDR'
  21124.         dw      l6576
  21125.         dc      'SIZEOF'
  21126.         dw      l659d
  21127.         dc      'BDOSHL'
  21128.         dw      l6553
  21129.         dc      'BDOS'
  21130.         dw      l6554
  21131.         dc      'BIOSHL'
  21132.         dw      l651e
  21133.         dc      'BIOS'
  21134.         dw      l651f
  21135.         db      0
  21136. l78fa:
  21137.         dc      'MEM'
  21138.         dw      0
  21139.         db      0
  21140. ;
  21141. ; Start of dynamic data
  21142. ; - originally at page boundary - here : 7900h
  21143. ;
  21144. ; Dynamic data area starts - shared by editor and compiler most
  21145. ;
  21146. CmpTyp:
  21147.         db      1ah             ; Compile flag:
  21148.                                 ; 0: Compile to memory
  21149.                                 ; 1: Compile to .COM/.CHN file
  21150.                                 ; 2: Searching
  21151. l7901:
  21152.         db      'd'             ; Error code
  21153. CodePC:
  21154.         db      'SE'            ; Code pointer
  21155. l7904:
  21156.         db      'EK'            ; Code start address
  21157. l7906:
  21158.         db      'EO'            ; Code end address
  21159. DataBeg:
  21160.         db      'L',0ceh        ; Start of data
  21161. l790a:
  21162.         db      0dah,'d'        ; End of code address
  21163. l790c:
  21164.         db      'FI'            ; Current editor address
  21165. IncFlg:
  21166.         db      'L'             ; Memory read flag (0 is read)
  21167. l790f:
  21168.         db      'ESIZ',0c5h,0fah,'dFILEPO',0d3h,0f2h
  21169.         db      'dKEYPRESSE',0c4h,0ch,'dMEMAVAI',0cch
  21170. ;
  21171. ; FCB of source file
  21172. ;
  21173. FFCB: ;36 bytes???
  21174.         db      14h
  21175.         db      'eMAXAVAI'
  21176.         db      0cch
  21177.         db      19h,'ePOR',0d4h,0bfh,'eSTACKPT'
  21178.         db      0d2h,0cah,'eADD',0d2h,'v'
  21179.         db      'eSI'
  21180. ;
  21181. ; DISK BUFFER
  21182. ;
  21183. TmpBuff:
  21184.         db      'ZEO',0c6h,9dh,'eBDOS'
  21185.         db      'H',0cch,'SeBDO',0d3h,'TeBIOSH'
  21186.         db      0cch,1eh,'eBIO',0d3h,1fh,'e'
  21187.         db      0,'ME',0cdh,0,0,0
  21188. l7980:: ;;**
  21189.  
  21190. l79d7   equ     TmpBuff+RecLng  ; Start of source line
  21191. l7a57   equ     l79d7+RecLng
  21192. l7ad7   equ     l7a57+RecLng    ; Top of used memory on start
  21193. Envir1  equ     l7ad7+RecLng
  21194. l7b58   equ     Envir1+1                ; Value of symbol
  21195. l7b59   equ     l7b58+1
  21196. l7b5a   equ     l7b59+1         ; Type table
  21197. l7b5c   equ     l7b5a+2         ; Type
  21198. l7b5d   equ     l7b5c+1
  21199. l7b5e   equ     l7b5d+1         ; Lo set limit
  21200. l7b60   equ     l7b5e+2         ; Hi set limit
  21201. l7b62   equ     l7b60+2         ; Length of type
  21202. Envir2  equ     l7b62+2
  21203. l7b65   equ     Envir2+1
  21204. l7b69   equ     l7b65+4
  21205. l7b6b   equ     l7b69+2
  21206. l7b6d   equ     l7b6b+2         ; Last memory address
  21207. l7b6f   equ     l7b6d+2         ; TEMP
  21208. l7b71   equ     l7b6f+2         ; TEMP
  21209. l7b72   equ     l7b71+1         ; EDT: Pointer to delimters
  21210. LabPtr  equ     l7b72+1         ; Label pointer
  21211. l7b74   equ     LabPtr+1                ; EDT: Edited line
  21212. PrevLabPtr      equ     l7b74+1         ; Previous label pointer
  21213. l7b77   equ     PrevLabPtr+2            ; Top of available memory
  21214. l7b79   equ     l7b77+2
  21215. CurLab  equ     l7b79+2         ; Current label pointer
  21216. l7b7d   equ     CurLab+2
  21217. l7b7f   equ     l7b7d+2
  21218. l7b81   equ     l7b7f+2
  21219. l7b83   equ     l7b81+2
  21220. l7b85   equ     l7b83+2
  21221. l7b87   equ     l7b85+2
  21222. l7b88   equ     l7b87+1
  21223. l7b89   equ     l7b88+1
  21224. l7b8b   equ     l7b89+2
  21225. l7b8d   equ     l7b8b+2
  21226. l7b8f   equ     l7b8d+2
  21227. l7b90   equ     l7b8f+1
  21228. l7b91   equ     l7b90+1         ; ???
  21229. l7b92   equ     l7b91+1         ; ???
  21230. curtype_l7b93   equ     l7b92+1         ; Type
  21231. l7b94   equ     curtype_l7b93+1         ; ???
  21232. l7b95   equ     l7b94+1
  21233. l7b96   equ     l7b95+1         ; OVERLAY number
  21234. l7b97   equ     l7b96+1         ; PROCEDURE (=0) or FUNCTION (<>0)
  21235. l7b98   equ     l7b97+1
  21236. l7b99   equ     l7b98+1         ; Overlay flag (-1)
  21237. l7b9a   equ     l7b99+1
  21238. l7b9b   equ     l7b9a+1
  21239. l7b9c   equ     l7b9b+1
  21240. l7b9d   equ     l7b9c+1         ; Option bits
  21241. l7b9e   equ     l7b9d+1         ; Local PROCEDURE/FUNCTION options
  21242. l7b9f   equ     l7b9e+1
  21243. l7ba0   equ     l7b9f+1         ; End on break
  21244. l7ba1   equ     l7ba0+1
  21245. l7ba2   equ     l7ba1+1         ; End of file
  21246. l7ba3   equ     l7ba2+1
  21247. l7ba4   equ     l7ba3+1
  21248. l7ba6   equ     l7ba4+2
  21249. l7ba7   equ     l7ba6+1
  21250. l7ba9   equ     l7ba7+2
  21251. l7bab   equ     l7ba9+2         ; Data pointer for overlay
  21252. l7bb0   equ     l7bab+5         ; Length of overlay
  21253. l7bb2   equ     l7bb0+2         ; OVERLAY file name
  21254. l7bbd   equ     l7bb2+11
  21255. l7bbe   equ     l7bbd+1
  21256. FirstVAR        equ     l7bbe+2
  21257. l7bc1   equ     FirstVAR+1
  21258. l7bc2   equ     l7bc1+1
  21259. l7bc4   equ     l7bc2+2
  21260. l7bc6   equ     l7bc4+2
  21261. l7bc7   equ     l7bc6+1         ; Depth for WITH
  21262. l7bc8   equ     l7bc7+1
  21263. l7bc9   equ     l7bc8+1
  21264. l7bca   equ     l7bc9+1
  21265. l7bcc   equ     l7bca+2
  21266. Env_PC  equ     l7bcc+9
  21267. l7bd7   equ     Env_PC+2                ; Source pointer
  21268. l7bd9   equ     l7bd7+2         ; Dtto.
  21269. RRN_stat        equ     l7bd9+2         ; File access
  21270. RecPtr  equ     RRN_stat +1             ; Record pointer
  21271. RRN_off equ     RecPtr+1                ; Record base
  21272. MemsTop equ     RRN_off+2
  21273. COMsTop equ     MemsTop+2               ; Top of .COM file
  21274. BackLevel       equ     COMsTop+2               ; Back fix level
  21275. l7be4   equ     BackLevel+1             ; Saved top of .COM file
  21276. INCsTop equ     l7be4+2
  21277. l7be8   equ     INCsTop+2
  21278. l7be9   equ     l7be8+1
  21279. l7beb   equ     l7be9+2
  21280. l7bed   equ     l7beb+2
  21281. l7bef   equ     l7bed+2         ; Line count
  21282. l7bf5   equ     l7bef+6         ; Start of text
  21283.  
  21284. end
  21285.         savebin "tp.com",begin,end-begin
  21286.        
  21287.         LABELSLIST "../../us/user.l"
  21288.