?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;
  3. ;ADD termination bit to ENCBUF
  4. ;
  5. eterm:  push    af
  6.         push    bc
  7.         push    de
  8.         push    hl
  9.         ld      hl,encbuf
  10.         ld      a,(encptr)      ;A = no. of characters in buffer.
  11.         or      a
  12.         jr      z,eterm2
  13.         dec     a
  14. eterm1: cp      3               ;Reset the "termination" bit on all
  15.         jr      c,eterm2        ;characters except the last.
  16.         res     7,(hl)
  17.         inc     hl
  18.         inc     hl
  19.         sub     3
  20.         jr      eterm1
  21. ;
  22. eterm2: or      a
  23.         jr      z,eterm3
  24.         ld      d,5             ;IF no. of characters remaining is not a
  25.         call    eaddch          ;multiple of 3, append character 5 until it is.
  26.         dec     a
  27.         jr      nz,eterm2
  28. eterm3: set     7,(hl)          ;SET the termination bit at the end.
  29. ;
  30. ;<< v0.02 Also set termination bits at encbuf+4 (z1-z3) or encbuf+6 (z4+)
  31. ;
  32.         ld      hl,encbuf+2     ;Start of 2nd word
  33.         ld      a,(zver)
  34.         cp      4
  35.         jr      c,etermz
  36.         ld      hl,encbuf+4     ;Start of 3rd word
  37.         jr      etermz
  38. ;
  39. etermz: set     7,(hl)  ; >> v0.02
  40.         jp      popd
  41. ;
  42. ;Append the character in D to ENCBUF
  43. ;
  44. eaddch: push    af
  45.         push    bc
  46.         push    de
  47.         push    hl
  48.         ld      a,d
  49.         and     1fh
  50.         ld      d,a
  51. ;
  52. ;Append character D to encbuf
  53. ;
  54.         ld      hl,encbuf
  55.         ld      a,(encptr)
  56.         inc     a
  57.         ld      (encptr),a
  58.         dec     a
  59. encoff: cp      3
  60.         jr      c,encmap
  61.         inc     hl
  62.         inc     hl
  63.         sub     3
  64.         jr      encoff
  65. ;
  66. ;HL->correct part of the buffer.
  67. ;
  68. encmap: or      a
  69.         jr      z,eadd0
  70.         dec     a
  71.         jr      z,eadd1
  72. eadd2:  inc     hl
  73.         ld      a,(hl)
  74.         and     0E0h
  75.         or      d
  76.         ld      (hl),a
  77.         jp      popd
  78. ;
  79. eadd0:  ld      a,(hl)
  80.         and     083h
  81.         rlc     d
  82.         rlc     d
  83.         or      d
  84.         ld      (hl),a
  85.         jp      popd
  86. ;
  87. eadd1:  ld      a,d
  88.         rrca
  89.         rrca
  90.         rrca            ;A is now LLL000HH
  91.         ld      e,a
  92.         and     3
  93.         ld      d,a     ;D is 000000HH
  94.         ld      a,e
  95.         and     0E0h
  96.         ld      e,a     ;E is LLL00000
  97.         ld      a,(hl)
  98.         and     07Ch
  99.         or      d
  100.         ld      (hl),a
  101.         inc     hl
  102.         ld      a,(hl)
  103.         and     1Fh
  104.         or      e
  105.         ld      (hl),a
  106.         jp      popd
  107. ;
  108. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  109. ;
  110. ; Encode B ASCII chars at z-address HL to z-chars in encbuf. encbuf
  111. ; holds big-endian words.
  112. ;
  113. encal:  defb    0       ;Encoding alphabet
  114. encptr: defb    0       ;No. of characters in ENCBUF
  115. ;
  116. encode: push    af
  117.         push    bc
  118.         push    de
  119.         push    hl
  120.         xor     a
  121.         ld      (encal),a
  122.         ld      (encptr),a
  123. enchar: call    peek64  ;A = ascii character
  124.         inc     hl
  125.         push    hl
  126. ;
  127. ;See if the character can be found in the alphabets al0, al1, al2
  128. ;
  129.         ld      hl,al0+6
  130.         call    findc
  131.         jr      z,eadd5
  132.         ld      hl,al1+6
  133.         call    findc
  134.         jr      z,eadd6
  135.         ld      hl,al2+7
  136.         call    finda2
  137.         jr      z,eadd7
  138. ;
  139. ;ADD literal character...
  140. ;
  141.         ld      d,5     ;Shift to alphabet 2
  142.         call    eaddch
  143.         ld      e,a     ;E = ASCII character
  144.         ld      d,6     ;ASCII escape
  145.         call    eaddch
  146.         ld      a,e     ;A = HHHLLLLL
  147.         rlca
  148.         rlca
  149.         rlca
  150.         and     7
  151.         ld      d,a
  152.         call    eaddch
  153.         ld      a,e
  154.         and     1fh
  155.         ld      d,a
  156.         call    eaddch
  157.         jr      ence
  158. ;
  159. eadd5:  call    eaddch
  160.         jr      ence
  161. ;
  162. eadd6:  ld      a,d
  163.         ld      d,4
  164.         jp      adds
  165. ;
  166. eadd7:  ld      a,d
  167.         ld      d,5
  168. adds:   call    eaddch
  169.         ld      d,a
  170.         call    eaddch
  171. ence:   pop     hl
  172.         djnz    enchar
  173. ence1:  ld      a,(encptr)
  174.         cp      9
  175.         call    nc,eterm
  176.         jp      nc,popd
  177.         ld      d,5
  178.         call    eaddch
  179.         jr      ence1
  180. ;
  181. finda2: push    bc      ;Special case for alphabet 2.
  182.         ld      c,a
  183.         ld      b,25
  184.         ld      d,7
  185.         jr      findcl
  186.  
  187. findc:  push    bc      ;Returns Zero set if a character matches,
  188.         ld      c,a     ;D = character number
  189.         ld      d,6
  190.         ld      b,26
  191. findcl: ld      a,(hl)
  192.         cp      c
  193.         jr      z,findc2
  194.         inc     d
  195.         inc     hl
  196.         djnz    findcl
  197.         xor     a
  198.         inc     a
  199.         ld      a,c
  200. findc2: pop     bc
  201.         ret
  202. ;
  203. ;
  204. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  205. ;
  206. ;Output a z-char in A.
  207. ;
  208. abbrev: defb    0       ;nonzero if expanding an abbreviation
  209. dalpha: defb    0       ;Default alphabet number
  210. alpha:  defb    0       ;Alphabet number
  211. shift:  defb    0       ;Under shift conditions?
  212. multi:  defb    0       ;IN multi-char sequence?
  213. multw:  defw    0       ;The character to create in multi-char sequence.
  214. ;
  215. op_zchar:
  216.         push    af
  217.         push    bc
  218.         push    de
  219.         push    hl
  220.         ld      c,a
  221.         ld      a,(multi)
  222.         or      a
  223.         jr      nz,nabb2        ;IF in a multi-byte char, don't try to
  224.         ld      a,(abbrev)      ;expand it as an abbreviation
  225.         or      a
  226.         jp      nz,opabb
  227.  
  228.         ld      a,(zver)
  229.         cp      3
  230.         jr      c,nabb1
  231.         ld      a,c
  232.         cp      1       ;1,2,3 are abbreviation characters
  233.         jr      z,abbr
  234.         cp      2
  235.         jr      z,abbr
  236.         cp      3
  237.         jr      z,abbr
  238.         jr      nabb2
  239. ;
  240. nabb1:  cp      2
  241.         jr      c,nabb2
  242. abbr:   ld      a,c
  243.         ld      (abbrev),a
  244.         jp      popd
  245. ;
  246. nabb2:  ld      a,c     ;A = packed char
  247.         call    zchar2
  248.         jp      popd
  249. ;
  250. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  251. ;
  252. ;Expand abbreviation string - A is 1st character, C is second
  253. ;
  254. opabb:  dec     a       ;<< v0.02 thoroughly rewritten
  255.         rlca
  256.         rlca
  257.         rlca
  258.         rlca
  259.         rlca            ;A = (Z - 1) * 32
  260.         and     60h
  261.         add     a,c     ;A = (Z - 1) * 32 + X
  262.         ld      c,a
  263.         ld      b,0     ;BC = abbreviation no.
  264.         push    bc
  265.         ld      hl,18h
  266.         ld      e,0
  267.         call    ZXPKWI  ;BC = base of abbreviation table
  268.         pop     hl
  269.  
  270.         xor     a
  271.         ld      (abbrev),a      ;Reset "expand abbreviation" flag
  272.  
  273.         add     hl,hl
  274.         add     hl,bc
  275.  
  276.         ld      e,0
  277.         call    ZXPKWI  ;BC = address of abbreviation string
  278.         ld      h,b     ;     (word address, so in the bottom 128k)
  279.         ld      l,c
  280.         ld      a,h
  281.         add     hl,hl   ;Convert to byte address
  282.         bit     7,a
  283.         ld      e,0
  284.         jr      z,abblp
  285.         inc     e       ;High byte of address
  286.  
  287. abblp:  call    ZXPKWI
  288.         push    de
  289.         push    hl
  290.         push    bc
  291.         ld      a,b
  292.         rrca
  293.         rrca
  294.         and     01Fh
  295.         call    op_zchar        ;Recursive call.
  296.         ld      a,b             ;According to the Z-Spec, an abbreviation
  297.         rlca                    ;cannot contain other abbreviations.
  298.         rlca                    ;But since Curses (R12) tries to print
  299.         rlca                    ;abbreviations containing abbreviations,
  300.         and     18h             ;we have to support it.
  301.         ld      b,a             ;Otherwise, these calls would be to zchar2.
  302.         ld      a,c
  303.         rlca
  304.         rlca
  305.         rlca
  306.         and     7
  307.         or      b
  308.         call    op_zchar        ;Recursive call.
  309.         ld      a,c
  310.         and     1Fh
  311.         call    op_zchar        ;Recursive call.
  312.         pop     bc
  313.         pop     hl
  314.         pop     de
  315.         bit     7,b
  316.         jr      z,abblp
  317.         call    rshift  ;Swallow any "packing" shift characters
  318.         jp      popd    ;>> v0.02
  319. ;
  320. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  321. ;
  322. ;Output a Z-char, which we know isn't an abbreviation
  323. ;
  324. zchar2: push    hl
  325.         push    bc
  326.         ld      l,a
  327.         ld      a,(multi)
  328.         or      a
  329.         jp      nz,xmult
  330.         ld      a,l
  331.         cp      8
  332.         jp      nc,zch0
  333.         ld      h,0
  334.         add     hl,hl
  335.         ld      bc,chartbl
  336.         add     hl,bc
  337.         ld      e,(hl)
  338.         inc     hl
  339.         ld      d,(hl)
  340.         ex      de,hl
  341.         jp      (hl)
  342. ;
  343. zch6:   ld      l,a
  344.         ld      a,(alpha)
  345.         cp      2
  346.         jr      nz,zch0a
  347.         ld      a,1
  348.         ld      (multi),a
  349.         jr      zcret
  350.  
  351. zch0:   ld      l,a
  352. zch0a:  ld      a,(alpha)
  353.         or      a
  354.         ld      de,al0
  355.         jr      z,xlet
  356.         ld      de,al1
  357.         dec     a
  358.         jr      z,xlet
  359.         ld      de,al2
  360.         ld      a,(zver)
  361.         cp      1
  362.         jr      nz,xlet
  363.         ld      de,al2a
  364. xlet:   ld      h,0
  365.         add     hl,de
  366.         ld      l,(hl)
  367.         ld      h,0
  368.         call    ll_zchr
  369. zcret:  call    rshift
  370. zcr1:   pop     bc
  371.         pop     hl
  372.         ret
  373. ;
  374. rshift: push    af              ;Reset shifts
  375.         xor     a
  376.         ld      (shift),a
  377.         ld      a,(dalpha)
  378.         ld      (alpha),a
  379.         pop     af
  380.         ret
  381. ;
  382. ;;;;;;;;;;;;;;;;;;;;;;
  383. ;
  384. ;Special handlers for the first 8 characters
  385. ;
  386. chartbl:
  387.         defw    zch0, zch1, zch2, zch3, zch4, zch5, zch6, zch0
  388. ;
  389. zch1:   ld      hl,0dh          ;Z-char 1 is a newline in v1
  390.         call    ll_zchr
  391.         jp      zcret
  392. ;
  393. zch2:   ld      a,(dalpha)      ;Z-char 2: shift to next alphabet
  394.         inc     a
  395.         cp      3
  396.         jr      c,zch2a
  397.         xor     a
  398. zch2a:  ;ld     (dalpha),a      ;<< v0.02 >> this is a shift not a lock
  399.         ld      (alpha),a
  400.         jp      zcr1
  401. ;
  402. zch3:   ld      a,(dalpha)      ;Z-char 3: shift to prev alphabet
  403.         dec     a
  404.         jr      z,zch2a
  405.         ld      a,2
  406.         jr      zch2a
  407. ;
  408. zch4:   ld      (shift),a       ;Z-char 4: shift to alphabet 1 (3+)
  409.         ld      a,(zver)        ;or next alphabet (1,2)
  410.         cp      3
  411.         jr      c,zch4a
  412.         ld      a,1
  413.         ld      (alpha),a
  414.         jp      zcr1
  415. ;
  416. zch4a:  ld      a,(alpha)       ;Shift lock to next alphabet
  417.         inc     a
  418.         cp      3
  419.         jr      c,zch4b
  420.         xor     a
  421. zch4b:  ld      (alpha),a
  422.         ld      (dalpha),a      ;<< v0.02 >> this is the shift lock
  423.         jp      zcr1
  424. ;
  425. zch5:   ld      (shift),a       ;Z-char 5: Shift to alphabet 2 (3+)
  426.         ld      a,(zver)        ;or previous alphabet (1,2)
  427.         cp      3
  428.         jr      c,zch5a
  429.         ld      a,2
  430.         ld      (alpha),a
  431.         jp      zcr1
  432. ;
  433. zch5a:  ld      a,(alpha)       ;Shift lock to previous alphabet
  434.         dec     a
  435.         jr      nc,zch4b
  436.         ld      a,2
  437.         jr      zch4b
  438. ;
  439. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  440. ;
  441. ;Alphabets
  442. ;               ;0123456789abcdef0123456789abcdef
  443. al0:    defb    ' *****abcdefghijklmnopqrstuvwxyz'
  444. al1:    defb    ' *****ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  445. al2:    defb    ' ******'
  446.         defb    0dh
  447.         defb    '0123456789.,!?_#'
  448.         defb    027h
  449.         defb    '"/\-:()'
  450. al2a:   defb    ' ******0123456789.,!?_#'
  451.         defb    027h
  452.         defb    '"/\<-:()'
  453. ;
  454. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  455. ;
  456. ;CREATE a multi-byte char. A = 1 or 2; L = character
  457. ;
  458. xmult:  dec     a
  459.         jr      nz,xmult2
  460.         ld      h,0
  461.         add     hl,hl
  462.         add     hl,hl
  463.         add     hl,hl
  464.         add     hl,hl
  465.         add     hl,hl
  466.         ld      (multw),hl
  467.         ld      a,2
  468.         ld      (multi),a
  469.         jp      zcret
  470. ;
  471. xmult2: ld      a,l
  472.         ld      hl,(multw)
  473.         or      l
  474.         ld      l,a
  475.         call    ll_zchr
  476.         xor     a
  477.         ld      (multi),a
  478.         jp      zcret
  479. ;
  480. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  481. ;
  482. ;This code handles buffering and streamed output. Initialise...
  483. ;
  484. inibuf: ld      hl,buffer       ;Initialise buffers and streams
  485.         ld      (bufptr),hl
  486.         ld      hl,0
  487.         ld      (bufcc),hl
  488.         ld      (bufcs),hl
  489.         ld      a,1
  490.         ld      (bufmde),a
  491.         ld      hl,t3ptr
  492.         ld      (t3ptr),hl
  493.         scf
  494.         xor     a
  495.         ld      (strm2),a
  496.         ld      (strm3),a
  497.         ld      (strm4),a
  498.         inc     a
  499.         ld      (strm1),a
  500.         ld      hl,21h
  501.         call    ZXPK64  ;Screen width
  502.         ld      (buf_maxw),a
  503.         ld      a,1
  504.         ld      (cwin),a
  505.         ld      hl,34h  ;<< v0.04 support alphabet table
  506.         ld      e,0
  507.         call    ZXPKWD  ;Get alphabet table address
  508.         ld      a,b
  509.         or      c
  510.         scf
  511.         ret     z       ;Default
  512.         ld      h,b
  513.         ld      l,c
  514.         ld      de,al0+6
  515.         ld      b,26    ;Values for alphabet 0
  516.         call    mcpy
  517.         ld      de,al1+6
  518.         ld      b,26    ;For alphabet 1
  519.         call    mcpy
  520.         ld      de,al2+8
  521.         inc     hl      ;For alphabet 2 (skip nos. 6 & 7)
  522.         inc     hl
  523.         ld      b,24
  524.         call    mcpy
  525.         scf
  526.         ret
  527. ;
  528. mcpy:   call    ZXPK64
  529.         ld      (de),a
  530.         inc     hl
  531.         inc     de
  532.         djnz    mcpy
  533.         ret             ;>> v0.04
  534.  
  535. ;
  536. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  537. ;
  538. ;Write the buffer contents to screen
  539. ;
  540. flush_buf:
  541.         push    af
  542.         push    bc
  543.         push    de
  544.         push    hl
  545. ;
  546. ;The buffer contains a word and some separators. See if the whole lot will fit.
  547. ;
  548.         ld      hl,buffer       ;<< v0.02
  549.         ld      a,(bufcc)
  550.         ld      b,a
  551.         ld      a,(bufcs)
  552.         ld      c,a
  553.         call    ZXBFIT
  554.         cp      2
  555.         jr      c,flushm        ;Yes, it will.
  556.         ld      hl,0Dh          ;No. Write CR; then the whole lot.
  557.         call    char_out        ;Write character
  558. bwrd1:  xor     a
  559. flushm: or      a       ;A = 0: flush all. A = 1: print text, not separators
  560.         ld      hl,(bufcc)
  561.         jr      nz,flush0
  562.         ld      de,(bufcs)
  563.         add     hl,de
  564. flush0: ld      bc,buffer       ;HL = count of chars to print
  565.         ld      (bufptr),bc
  566.         ld      bc,0
  567.         ld      (bufcs),bc      ;Reset buffer counters
  568.         ld      (bufcc),bc
  569.         ld      a,(bufmde)
  570.         or      a
  571.         jr      z,flush1
  572.         ld      a,1
  573.         ld      (bufmde),a
  574. flush1: ld      b,h     ;BC = no. of bytes to print. See if it will fit
  575.         ld      c,l     ;within the margin
  576.         ld      de,buffer
  577. flushlp:
  578.         ld      a,b
  579.         or      c
  580.         jp      z,popd
  581.         dec     bc
  582.         ld      a,(de)
  583.         ld      l,a
  584.         inc     de
  585.         ld      a,(de)
  586.         ld      h,a
  587.         inc     de
  588.         push    de
  589.         push    bc
  590.         call    char_out
  591.         pop     bc
  592.         pop     de
  593.         jr      flushlp
  594. ;
  595. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  596. ;
  597. ;Passed a character in HL, decide where it goes.
  598. ;
  599. ll_zchr:
  600.         ld      a,(strm3)       ;To stream 3?
  601.         or      a
  602.         jp      z,strm_gen
  603. ;
  604. ;Write to stream 3
  605. ;
  606.         push    hl
  607.         ld      hl,(t3ptr)
  608.         ld      e,(hl)
  609.         inc     hl
  610.         ld      d,(hl)  ;DE = address of table
  611.         ld      h,d
  612.         ld      l,e     ;HL = address of table
  613.         call    peek64
  614.         ld      b,a
  615.         inc     hl
  616.         call    peek64
  617.         ld      c,a     ;BC = length of text so far
  618.         inc     hl
  619.         add     hl,bc
  620.         ex      (sp),hl
  621.         ld      a,l     ;A = byte to write
  622.         ex      (sp),hl
  623.         call    ZXPOKE
  624.         inc     bc
  625.         ex      de,hl   ;DE = address of table
  626.         ld      a,b
  627.         call    ZXPOKE
  628.         inc     hl
  629.         ld      a,c
  630.         call    ZXPOKE
  631.         pop     hl
  632.         scf
  633.         ret
  634. ;
  635. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  636. ;
  637. ;Returns Carry set if character in L is a separator
  638. ;
  639. issep:  ld      a,l
  640.         cp      21h
  641.         ret
  642. ;
  643. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  644. ;
  645. ;Write character in HL to its streams, taking account of buffering
  646. ;
  647. strm_gen:
  648.         ld      a,(cwin)        ;Top window?
  649.         or      a
  650.         jp      z,char_out
  651.         ld      a,(bufmde)      ;bufmde is: 1 when reading non-separators
  652.         or      a               ;           2 when reading separators
  653.         jp      z,char_out      ;           0 if not buffered
  654.         cp      2
  655.         jr      nz,bufapp       ;Append non-separator
  656.         call    issep
  657.         call    nc,flush_buf    ;Next word; flush the buffer
  658. bufapp: ld      a,l
  659.         cp      0Dh             ;Newline, flush the buffer.
  660.         jp      z,bufnl
  661.         push    hl              ;Append character in HL to the buffer.
  662.         ex      de,hl
  663.         ld      hl,(bufptr)
  664.         ld      (hl),e
  665.         inc     hl
  666.         ld      (hl),d          ;Character buffered.
  667.         inc     hl
  668.         ld      (bufptr),hl
  669.         ex      de,hl
  670.         call    issep           ;Was it a separator?
  671.         jr      c,isep
  672.         ld      hl,(bufcc)
  673.         inc     hl
  674.         ld      (bufcc),hl
  675.         jr      ckover
  676. ;
  677. isep:   ld      hl,(bufcs)
  678.         inc     hl
  679.         ld      (bufcs),hl
  680.         ld      a,2
  681.         ld      (bufmde),a
  682. ;
  683. ;Check for buffer overflow. This happens when:
  684. ;
  685. ckover: pop     hl      ;The character.
  686. ;
  687. ;* There are <width> non-separators in the buffer.
  688. ;
  689.         call    ZXGETX
  690.         ld      l,a     ;L = total screen width
  691.         ld      a,(bufcc)
  692.         ld      c,a
  693.         cp      l       ;Screen width
  694.         ccf
  695.         jp      c,flush_buf
  696. ;
  697. ;* There are <width> separators in the buffer.
  698. ;
  699.         ld      a,(bufcs)
  700.         ld      b,a
  701.         cp      l
  702.         ccf
  703.         jp      c,flush_buf
  704. ;
  705. ;* There are <width> characters in the buffer in total.
  706. ;  (doing it separately avoids overflow on very wide screens :-) )
  707. ;
  708.         ld      a,b
  709.         add     a,c
  710.         cp      l
  711.         ret     c
  712.         scf
  713.         jp      flush_buf
  714. ;
  715. bufnl:  call    flush_buf
  716.         ld      hl,0dh
  717. ;
  718. ;Fall through to char_out
  719. ;
  720. ;
  721. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  722. ;
  723. ;Write a character in HL to its streams, with no buffering
  724. ;
  725. char_out:
  726.         ld      a,(strm1)
  727.         or      a
  728.         push    hl
  729.         ld      a,1             ;Stream 1
  730.         call    nz,ZXZCHR
  731.         pop     hl
  732.         ld      a,(strm2)
  733.         or      a
  734.         ld      a,2             ;Stream 2
  735.         scf                     ;<< v0.04 support printer abort. IF ZXZCHR
  736.         call    nz,ZXZCHR       ;        returns carry clear, turn off
  737.         ret     c               ;        printer output and reset the
  738.         xor     a               ;        transcript bit.
  739.         ld      (strm2),a
  740.         jp      ts_off          ;>> v0.04
  741. ;
  742. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  743. ;
  744. ;Select output stream.
  745. ;
  746. ll_strm:
  747.         cp      3
  748.         jr      z,sets3
  749.         cp      0FDh
  750.         jp      z,usets3
  751.         bit     7,a
  752.         jr      z,strmon
  753.  
  754. strmoff: push    af      ;Deactivate a stream
  755.          neg
  756.         dec     a
  757.         ld      hl,strm1
  758.         ld      e,a
  759.         ld      d,0
  760.         add     hl,de
  761.         ld      (hl),0
  762.         pop     af
  763.         cp      0FEh            ;Transcript
  764.         jp      nz,ZXSTRM
  765.         call    ZXSTRM
  766.         jr      c,ts_off
  767.         ld      a,1
  768.         ld      (strm2),a
  769.         jp      ts_err
  770. ;
  771. strmon: push    af              ;Activate a stream
  772.         dec     a
  773.         ld      hl,strm1
  774.         ld      e,a
  775.         ld      d,0
  776.         add     hl,de
  777.         ld      (hl),1
  778.         pop     af
  779.         cp      2
  780.         jp      nz,ZXSTRM
  781.         call    ZXSTRM
  782.         jr      c,ts_on
  783.         xor     a
  784.         ld      (strm2),a
  785.         jp      ts_err
  786.  
  787. ts_on:  ld      hl,11h
  788.         call    ZXPK64
  789.         or      1
  790.         call    ZXPOKE
  791.         scf
  792.         ret
  793. ;
  794. ts_off: ld      hl,11h
  795.         call    ZXPK64
  796.         res     0,a
  797.         call    ZXPOKE
  798.         scf
  799.         ret
  800. ;
  801. sets3:  ex      de,hl   ;DE = data address
  802.         ld      a,(strm3)
  803.         cp      16
  804.         ld      hl,s3err
  805.         ret     nc
  806.         ld      hl,(t3ptr)      ;Open a stream 3.
  807.         dec     hl
  808.         ld      (hl),d
  809.         dec     hl
  810.         ld      (hl),e
  811.         ld      (t3ptr),hl
  812.         ld      a,(strm3)
  813.         inc     a
  814.         ld      (strm3),a
  815. ;
  816. ; << v0.04  Reset the "count" to 0 when the stream is selected
  817. ;
  818.         ex      de,hl
  819.         xor     a
  820.         call    ZXPOKE
  821.         inc     hl
  822.         xor     a
  823.         call    ZXPOKE
  824.         dec     hl
  825.         ex      de,hl
  826. ;
  827. ; >> v0.04
  828. ;
  829.         ld      a,3
  830.         jp      ZXSTRM
  831. ;
  832. usets3: ld      a,(strm3)
  833.         or      a
  834.         scf                     ;Close a stream 3.
  835.         ret     z
  836.         dec     a
  837.         ld      (strm3),a
  838.         ld      hl,(t3ptr)
  839.         inc     hl
  840.         inc     hl
  841.         ld      (t3ptr),hl
  842.         ld      a,0FDh
  843.         jp      ZXSTRM
  844. ;
  845. ;Numeric data.
  846. ;
  847. cwin:   defb    0       ;Current output window no.
  848. bufmde: defb    0       ;Buffered?
  849. buffer: defs    512     ;Wordwrap buffer
  850. bufptr: defw    0       ;Pointer into same
  851. bufcc:  defw    0       ;No. of non-separator chars
  852. bufcs:  defw    0       ;No. of separator chars
  853. table3: defs    32      ;Table stack for stream 3 to use
  854. t3ptr:  defw    0       ;Pointer into the table stack
  855. strm1:  defb    1       ;Stream 1 (screen) active?
  856. strm2:  defb    0       ;Stream 2 (transcript) active?
  857. strm3:  defb    0       ;Stream 3 (memory) active?
  858. strm4:  defb    0       ;Stream 4 (scripting) active?
  859. buf_maxw:
  860.         defb    0       ;Screen width
  861. s3err:  defb    'O Stream 3 nestin'     ;Stream 3 nested too deeply.
  862.         defb    0E7h    ;'g'+80h
  863. ;
  864. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  865. ;
  866. ; << v0.04 Validate an input character in A. Invalid characters become " "
  867. ;
  868. valid_char:
  869.         cp      8
  870.         ret     z
  871.         cp      13
  872.         ret     z
  873.         cp      27
  874.         ret     z
  875.         cp      32
  876.         jr      c,valid_c2
  877.         cp      127
  878.         ret     c
  879.         cp      129
  880.         jr      c,valid_c2
  881.         cp      251
  882.         ret     c
  883. valid_c2:
  884.         ld      a,' '
  885.         ret
  886. ;
  887. ; >> v0.04
  888.