home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / list / ep-src.ark / STOWC.MAC < prev    next >
Text File  |  1988-05-21  |  14KB  |  954 lines

  1.  
  2.     include    BDS.LIB
  3.     include    EPDATA.MAC
  4.  
  5.     .comment    `
  6.  
  7. /************************************************/
  8. /* Put char in outbuf, and record width & mode    */
  9. /************************************************/
  10.  
  11. stowc(c)
  12. char c;
  13. {    int /* stowlen,*/ font;
  14.     char hyflag;
  15.  
  16.     if (mode & IGNORE) return;
  17.  
  18.     /* check BS                */
  19.     if (c == '\b')
  20.     {    if (outpoint) bsflag = TRUE;
  21.         return;
  22.     }
  23.  
  24.     /* if several spaces between words, it's possible to
  25.        get a SP at beginning of line during concatenation --
  26.        but we don't want that        */
  27.     if (!outpoint && c == ' ') return;
  28.  
  29.     /* store the character            */
  30.     outbuf[outpoint] = c;
  31.  
  32.     /* check soft hyphen            */
  33.     if (c == SOFTHY) {c = '-'; hyflag = TRUE; }
  34.     else hyflag = FALSE;
  35.  
  36.     /* check flag character and required blank            */
  37.     if (c >= 0x7F || c == rb) c = ' ';
  38.  
  39.     /* if graphic char or font undefined, look at earlier fonts    */
  40.     font = (mode >> 8) & 7;
  41.     while
  42.     (    font
  43.         && !(    (stowlen = ftlen[font-1][c])
  44.               && ftname[font-1][0]
  45.            )
  46.     ) font--;
  47.  
  48.     stowmode = mode;
  49.     stowkern = cs - val['K'-'@']['E'-'@'];
  50.  
  51.  
  52.     /* flag "have one char in output line"    */
  53.     if (font)
  54.     {    grfflag = TRUE;
  55.  
  56.         stowmode = fix[font-1][0];
  57.         if (stowmode & 0xFF00)
  58.         {    if (stowmode < 0) stowkern -= stowmode >> 8;
  59.             else    stowkern += stowmode >> 8;
  60.             stowmode &= 0x00FF;
  61.         }
  62.         if (stowmode & PRPTNL)
  63.         {    stowmode &= ~PRPTNL;
  64.             stowmode |= TALL;
  65.             duplflag = TRUE;
  66.         }
  67.         stowmode |= mode;
  68.  
  69.         if (stowmode & TALL) tallflag = TRUE;
  70.     }
  71.     else epsflag = TRUE;
  72.  
  73.  
  74.     /* determine width            */
  75.     if (bsflag)     stowlen = 0;
  76.     else if (font) {if (cw) stowlen = cw;
  77.             else if (stowlen + stowkern >  0)
  78.                 stowlen += stowkern;
  79.             }
  80.     else if (!(stowlen = modelen[mode & 63]))
  81.             stowlen = pmlen[c];
  82.  
  83.     /* font number to b8-b10        */
  84.     attrbuf[outpoint] =  (stowmode & 0xF8FF) | (font << 8);
  85.  
  86.     bsflag = FALSE;
  87.  
  88.     /* adjust for expanded, etc.        */
  89.     if (stowmode & EXPNDD) stowlen <<= 1;
  90.     if (font)
  91.     {    if (stowmode & CMPRSSD) stowlen -= stowlen >> 2;
  92.         if (stowmode & ELITE)   stowlen -= stowlen / 5;
  93.         if (st)            stowlen += stowlen / st;
  94.         if (sh)            stowlen -= stowlen / sh;
  95.         if (stowmode & EMPHSZD && bo)
  96.                     stowlen += bo << 1;
  97.     }
  98.  
  99.     /* record width and inc't pointers    */
  100.     widbuf[outpoint++] = stowlen;
  101.     if (!hyflag) glen += stowlen;
  102. }
  103.  
  104.             `
  105.  
  106. stowc::
  107.     pop    d
  108.     pop    h
  109.     push    h
  110.     push    d
  111.  
  112. ;c argument kept in reg. C
  113. ; and (later) font kept in reg. B
  114.     push    b
  115.     mov    c,l
  116.  
  117. ;back to here if repeat-char
  118. .stc00:
  119. ;    if (mode & IGNORE) return;
  120.     lda    mode+1
  121.     ani    IGNORE shr 8
  122.     jnz    .stcxt
  123. ;
  124. ;    /* check BS                */
  125. ;    if (c == '\b')
  126. ;    {    if (outpoint) bsflag = TRUE;
  127. ;        return;
  128. ;    }
  129.     lhld    outpoint    ;for a bit later
  130.  
  131.     mov    a,c
  132. ;special characters C1-FF give automatic backspace
  133.     cpi    0C1H
  134.     jc    .stbs1
  135.     ani    3FH
  136.     mov    c,a
  137.     sta    bsflag
  138. .stbs1:    cpi    BCKFLAG        ;was 8
  139.     jnz    .stc1
  140.     mov    a,h
  141.     ora    l
  142.     jz    .stcxt
  143.     mvi    a,1
  144.     sta    bsflag
  145.     jmp    .stcxt
  146.  
  147.  
  148. ;logic for punctuation factor
  149. ;(1) if SP ' " ) leave p_space as is
  150. punctset:
  151.     cpi    ' '
  152.     rz
  153.     cpi    27
  154.     rz
  155.     cpi    '"'
  156.     rz
  157.     cpi    ')'
  158.     rz
  159. ;(2) if . ! ? set p_space = p.f.
  160.     lda    pf
  161.     sta    p_space
  162.     mov    a,c
  163.     cpi    '.'
  164.     rz
  165.     cpi    '!'
  166.     rz
  167.     cpi    '?'
  168.     rz
  169. ;(3) otherwise reset
  170.     xra    a
  171.     sta    p_space
  172.     ret
  173. p_space:    db    0
  174. ;
  175. ;    /* if several spaces between words, it's possible to
  176. ;       get a SP at beginning of line during concatenation --
  177. ;       but we don't want that        */
  178. ;    if (!outpoint && c == ' ') return;
  179. .stc1:
  180.     call    punctset
  181.  
  182.  
  183. ;    lhld    outpoint
  184.     mov    a,h
  185.     ora    l
  186.     jnz    .stc2
  187.  
  188. ;(better do the following in newoutline -- here is not foolproof)
  189. ;reset punctuation space
  190.     sta    p_space
  191.  
  192. ;except if we're just putting to the terminal, go ahead
  193.     lda    val + 54*('P'-'@') + 2*('T'-'@')
  194.     ora    a
  195.     jnz    .stc2
  196.     mov    a,c
  197.     cpi    ' '
  198.     jz    .stcxt
  199. ;
  200. ;    /* store the character            */
  201. ;    outbuf[outpoint] = c;
  202. .stc2:
  203. ;check for upper-case
  204.     lda    val + 54*('U'-'@') + 2*('C'-'@')
  205.     ora    a
  206.     mov    a,c
  207.     cnz    mapuc
  208.     mov    c,a
  209.  
  210.     xchg
  211.     lhld    outbuf
  212.     xchg
  213. ;    lhld    outpoint
  214.     dad    d
  215.     mov    m,c
  216.  
  217.     dcx    h
  218.     mov    a,m
  219.     inx    h
  220.     sta    laststow
  221.  
  222. ;
  223. ;    /* check soft hyphen            */
  224. ;    if (c == SOFTHY) {c = '-'; hyflag = TRUE; }
  225. ;    else hyflag = FALSE;
  226.     mov    a,c
  227.     cpi    SOFTHY
  228.     mvi    a,0
  229.     jnz    .stc3
  230.     mvi    c,'-'
  231.     inr    a
  232. .stc3:    sta    hyflag
  233.  
  234. ;if it's a from-flag, make it a RA & remember outpoint
  235.     mov    a,c
  236.     cpi    FRFLAG
  237.     jnz    .stc3a
  238.     mvi    m,RAFLAG
  239.     lhld    outpoint
  240.     shld    frplace
  241. .stc3a:
  242. ;
  243. ;    /* check flag character and required blank            */
  244. ;    if (c >= 0x7F || c == rb) c = ' ';
  245.  
  246.     mov    a,c
  247.     inr    a
  248.     jm    .stc4
  249.     lda    rb
  250.     cmp    c
  251.     jnz    .stc5
  252. .stc4:    mvi    c,' '
  253. .stc5:
  254.  
  255. ;Here put it to the console, if appropriate
  256.  
  257.     lda    val + 54*('P'-'@') + 2*('T'-'@')
  258.     ora    a
  259.  
  260.     .comment    `
  261. have to keep glen up for templates
  262.     jz    .stc5a
  263.  
  264.     mov    a,c
  265.     call    termput##
  266. ;if put-terminal, don't actually store it
  267.     jmp    .stcxt
  268.             `
  269.     mov    a,c
  270.     cnz    termput##
  271.  
  272. .stc5a:
  273. ;
  274. ;    /* if graphic char or font undefined, look at earlier fonts    */
  275. ;    font = (mode >> 8) & 7;
  276.  
  277.     lda    mode+1
  278.     ani    7
  279.     mov    b,a    ;henceforth B = font
  280.  
  281. ;    while
  282. ;    (    font
  283. ;        && !(    (stowlen = ftlen[font-1][c])
  284. ;              && ftname[font-1][0]
  285. ;           )
  286. ;    ) font--;
  287.  
  288. .stc6:
  289.     mov    a,b
  290.     ora    a
  291.     jz    .stc8
  292.  
  293.     mov    l,b
  294.     dcr    l
  295.     mvi    h,0
  296. ;HL = (font-1)*100H
  297. ;    lxi    d,128
  298. ;    call    usmul
  299.  
  300.     dad    h
  301.     dad    h
  302.     dad    h
  303.     dad    h
  304.     dad    h
  305.     dad    h
  306.     dad    h
  307.  
  308.     lxi    d,ftlen
  309.     dad    d
  310.     mov    e,c
  311.     mvi    d,0
  312.     dad    d
  313.     mov    l,m
  314.     mvi    h,0
  315.     shld    stowlen
  316.  
  317.     mov    a,h
  318.     ora    l
  319.     jz    .stc7
  320.  
  321.     dcr    b
  322.     call    getftn##
  323.     inr    b
  324.  
  325.     mov    a,m
  326.     ora    a
  327.     jnz    .stc8
  328. .stc7:
  329.     dcr    b    ;font--
  330.     jmp    .stc6
  331. ;end while
  332. .stc8:
  333.  
  334. ;
  335. ;    stowmode = mode;
  336.  
  337.     lhld    mode
  338.     shld    stowmode
  339.  
  340. ;    stowkern = cs - val['K'-'@']['E'-'@'];
  341.     lhld    cs
  342.     xchg
  343.     lhld    ke
  344.     call    cmh
  345.     dad    d
  346.  
  347. ;check for graphics font char
  348.     lda    stowlen
  349.     cpi    0ffh
  350.     jnz    .stc8a
  351.     lxi    h,450
  352.     shld    stowlen
  353.     lxi    h,0
  354. .stc8a:
  355.     shld    stowkern
  356. ;
  357. ;
  358. ;    /* flag "have one char in output line"    */
  359. ;    if (font)
  360.     mov    a,b
  361.     ora    a
  362.     jz    .stc12
  363. ;    {    grfflag = TRUE;
  364.     mvi    a,1
  365.     sta    grfflag
  366. ;
  367. ;        stowmode = fix[font-1][0];
  368.     mov    h,b
  369.     dcr    h
  370.     mvi    l,0    ;(font-1)*100h
  371.     lxi    d,fix
  372.     dad    d
  373.     mov    a,m
  374.     inx    h
  375.     mov    h,m
  376.     mov    l,a
  377.     shld    stowmode
  378. ;        if (stowmode & 0xFF00)
  379. ;        {    if (stowmode < 0) stowkern -= stowmode >> 8;
  380. ;            else    stowkern += stowmode >> 8;
  381. ;            stowmode &= 0x00FF;
  382. ;        }
  383. ;    lhld    stowmode
  384.     mov    a,h
  385.     ora    a
  386.     jz    .stc10
  387.  
  388. ;DE = stowmode >> 8
  389.     mov    e,h
  390.     mvi    d,0
  391.  
  392. ;    lhld    stowmode
  393. ;    mov    a,h
  394.     ral
  395.     jnc    .stc9
  396. ;here stowmode < 0
  397.     call    cmd
  398. .stc9:    lhld    stowkern
  399.     dad    d
  400.     shld    stowkern
  401.  
  402.     xra    a
  403.     sta    stowmode+1
  404.  
  405. ;        if (stowmode & PRPTNL)
  406. ;        {    stowmode &= ~PRPTNL;
  407. ;            stowmode |= TALL;
  408. ;            duplflag = TRUE;
  409. ;        }
  410. .stc10:    lhld    stowmode
  411.     mov    a,l
  412.     ani    PRPTNL
  413.     jz    .stc11
  414.  
  415.     mov    a,l
  416.     ani    UNDRLN
  417.     jz    .stc10.1
  418.     mov    a,c
  419.     cpi    ' '
  420.     jc    .stc7
  421.     cpi    60H
  422.     jnc    .stc7
  423.  
  424. .stc10.1:
  425.     mov    a,h
  426.     ori    TALL shr 8
  427.     mov    h,a
  428.     mov    a,l
  429. ;;    ani    not (PRPTNL or UNDRLN)
  430.     ani    not UNDRLN
  431.     mov    l,a
  432.  
  433.     mvi    a,1
  434.     sta    duplflag    ;?? was 'hycorrect'
  435. ;        stowmode |= mode;
  436. .stc11:
  437.     xchg
  438.     lhld    mode
  439.     mov    a,h
  440.     ora    d
  441.     mov    h,a
  442.     mov    a,l
  443.     ora    e
  444.     mov    l,a
  445.     shld    stowmode
  446. ;
  447. ;        if (stowmode & TALL) tallflag = TRUE;
  448. ;    lhld    stowmode
  449.     mov    a,h
  450.     ani    TALL shr 8
  451.     jz    .stc11.1
  452.     mvi    a,1
  453.     sta    tallflag
  454.  
  455. ;and ... if ' ' && p_space, add it in
  456. .stc11.1:
  457.     mov    a,c
  458.     cpi    ' '
  459.     jnz    .stc13
  460.     lxi    h,p_space
  461.     mov    a,m
  462.     ora    a
  463.     jz    .stc13
  464.     mov    e,a
  465.     xra    a
  466.     mov    m,a
  467.     mov    d,a
  468.     lhld    stowlen
  469.     push    h
  470.     dad    h
  471.     xchg
  472.     call    usdiv
  473.     pop    d
  474.     dad    d
  475.     shld    stowlen
  476. ;    }
  477.     jmp    .stc13
  478.  
  479.  
  480. ;    else epsflag = TRUE;
  481. .stc12:    mvi    a,1    ;(if not font)
  482.     sta    epsflag
  483. ;
  484. ;
  485. ;    /* determine width            */
  486. ;    if (bsflag)     stowlen = 0;
  487. ;    else if (font) {if (cw) stowlen = cw;
  488. ;            else if (stowlen + stowkern >  0)
  489. ;                stowlen += stowkern;
  490. ;            }
  491. ;    else if (!(stowlen = modelen[mode & 63]))
  492. ;            stowlen = pmlen[c];
  493. .stc13:    lda    bsflag
  494.     ora    a
  495.  
  496.     mvi    l,0
  497.     jnz    .stc17
  498. ;;    jz    .stc14
  499. ;;    lxi    h,0
  500. ;;    shld    stowlen
  501. ;;    jmp    .stc18
  502.  
  503. .stc14:
  504.     mov    a,b
  505.     ora    a
  506.     jz    .stc16
  507.  
  508.     lhld    cw
  509.     mov    a,h
  510.     ora    l
  511. ;;    jz    .stc15
  512. ;;    lhld    cw
  513. ;;    shld    stowlen
  514. ;;    jmp    .stc18
  515.     jnz    .stc17a
  516.  
  517. .stc15:    lhld    stowlen
  518.     xchg
  519.     lhld    stowkern
  520.     dad    d
  521.  
  522. ;(space-caps now separate)
  523. ;-    lda    val + 54*('U'-'@') + 2*('C'-'@')
  524. ;-    mov    e,a
  525. ;-    mvi    d,0
  526. ;-    dad    d
  527.  
  528.     dcx    h
  529.     mov    a,h
  530.     inx    h
  531.     ora    a
  532.     jm    .stc18
  533. ;;    shld    stowlen
  534. ;;    jmp    .stc18
  535.     jmp    .stc17a
  536.  
  537.  
  538.  
  539. ;(if not font)
  540. .stc16:    lda    mode
  541.     ani    63
  542.     mov    e,a
  543.     mvi    d,0
  544.  
  545.     lxi    h,modelen
  546.     dad    d
  547.     mov    l,m
  548.  
  549.     mov    a,l
  550.     ora    a
  551.     jnz    .stc17
  552.  
  553.     mov    l,c
  554.     mvi    h,0
  555.     lxi    d,pmlen
  556.     dad    d
  557.     mov    l,m
  558. .stc17:    mvi    h,0
  559. .stc17a:
  560.     shld    stowlen
  561. ;
  562. ;    /* font number to b8-b10        */
  563. ;    attrbuf[outpoint] =  (stowmode & 0xF8FF) | (font << 8);
  564. .stc18:    lhld    attrbuf
  565.     xchg
  566.     lhld    outpoint
  567.     dad    h
  568.     dad    d
  569.  
  570.     xchg
  571.     lhld    stowmode
  572.     mov    a,h
  573.     ani    0f8h
  574.     ora    b
  575.     mov    h,a
  576.     xchg
  577.  
  578.     mov    m,e
  579.     inx    h
  580.     mov    m,d
  581.  
  582. ;no correction for native font
  583.     mov    a,b
  584.     ora    a
  585.     jz    .stcNIT
  586. ;no correction for graphic font
  587.     lda    stowlen+1
  588.     ora    a
  589.     jm    .stcNIT
  590. ;no correction if cw
  591.     lda    cw
  592.     ora    a
  593.     jnz    .stcNIT
  594.  
  595.     call    .italcorr
  596.     call    .kerncorr
  597.     call    .capcorr
  598.     jmp    .stcNIT
  599.  
  600. .capcorr:
  601.     lda    val + 54*('S'-'@') + 2*('C'-'@')
  602.     ora    a
  603.     rz
  604.     mov    l,a
  605.     mov    a,c
  606.     cpi    'A'
  607.     rc
  608.     cpi    'Z'+1
  609.     rnc
  610.     lda    laststow
  611.     cpi    'A'
  612.     rc
  613.     cpi    'Z'+1
  614.     rnc
  615.     pop    d
  616.     mvi    h,0
  617.     jmp    .lastwch
  618.  
  619. .kerncorr:
  620. ;high byte of last attr left in E by italcorr
  621.     mov    a,e
  622.     ani    7
  623.     cmp    b    ;not if fonts differ
  624.     rnz
  625.  
  626. ;font in B
  627.     mov    a,b
  628.     dcr    a
  629. ;(should also compare last font)
  630.     mov    l,a
  631.     mvi    h,0
  632.     dad    h
  633.     lxi    d,klist
  634.     dad    d
  635.     mov    e,m
  636.     inx    h
  637.     mov    d,m
  638.     xchg
  639.     mov    a,h
  640.     ora    l
  641.     rz
  642.  
  643.     mvi    e,0
  644.     push    b
  645.     lda    laststow
  646.     mov    b,a
  647. .kc1:    call    .ksearch
  648.     ora    a
  649.     jnz    .kc1
  650.     pop    b
  651.     mov    d,a
  652.     mov    a,e
  653.     ora    a
  654.     rz
  655.     pop    h    ;escape from call
  656.     xchg
  657.     dad    h    ;? 2 dots per mention
  658.     call    cmh
  659.     jmp    .lastwch
  660.  
  661. .ksearch:
  662.     mov    a,m
  663.     ora    a
  664.     rz
  665.     mov    d,a
  666.     inx    h
  667.     mov    a,m
  668.     ora    a
  669.     rz
  670.     inx    h
  671.     cmp    c
  672.     rnz
  673.     mov    a,b
  674.     cmp    d
  675.     rnz
  676.     inr    e
  677.     ret
  678.  
  679.  
  680. .italcorr:
  681. ;italic correction for non-italic char preceded by italic
  682. ;(does not take account of bending, or expanded, or stretching)
  683.     mov    a,e
  684.     ani    ITALIC
  685.     mov    e,a
  686.     mov    a,d
  687.     ani    BENT shr 8
  688.     ora    e
  689. ;(wait)    rnz    ;no correction if this is italic
  690.  
  691. ;step back in attrbuf to previous char
  692. ;(if outpoint = 0, invalid -- check later)
  693.     dcx    h
  694.     dcx    h
  695.     mov    e,m    ;get last font for kerncorr
  696.     rnz        ;NOW ret if this is italic or bent
  697.     dcx    h
  698.     mov    a,m
  699.     ani    ITALIC
  700. ;if that was not italic, no correction
  701.     jnz    $+7
  702.     mov    a,e
  703.     ani    BENT shr 8
  704.     rz
  705.     mov    d,e
  706.     mov    e,m
  707. ;last mode in DE
  708.  
  709. ;now do correction
  710. ;first, escape from caller so other corrections not done
  711.     pop    h
  712.  
  713. ;;    lxi    h,8
  714.     xchg
  715.     call    endcorr##
  716.     xchg
  717. .lastwch:
  718.     shld    deltaL
  719.     lxi    h,.stcNIT
  720.     push    h
  721.  
  722. ;now make sure not at beginning of output line
  723.     lhld    outpoint
  724.     mov    a,h
  725.     ora    l
  726.     rz
  727.  
  728. ;here we have to correct
  729.     dcx    h    ;point last
  730.     dad    h    ;word array
  731.     xchg
  732.     lhld    widbuf
  733.     dad    d
  734.  
  735. ;a little patchwork -- if current is space, add width to it,
  736. ; instead of last, to prevent double corrections at end of line
  737.     mov    a,c
  738.     cpi    ' '
  739.     jnz    $+6
  740.     lxi    h,stowlen
  741.  
  742. ;save array index
  743.     push    h
  744. ;get previous width of last char in DE
  745.     mov    e,m
  746.     inx    h
  747.     mov    d,m
  748. ;add the correction -- 1 dot per point, assuming 8 points high
  749. ;(change here for other correction: 'lhld deltal')
  750.     lhld    deltaL
  751.     dad    d
  752.     xchg
  753. ;and enter it
  754.     pop    h
  755.  
  756. ;check for small width
  757.     mov    a,d
  758.     ora    a
  759.     rm
  760.     ora    e
  761.     rz
  762.  
  763.     mov    m,e
  764.     inx    h
  765.     mov    m,d
  766.  
  767. ;now adjust glen, unless adding to current SP
  768.     mov    a,c
  769.     cpi    ' '
  770.     rz
  771.  
  772.     lhld    glen
  773. ;(change here for other correction: 'deltal equ $+1')
  774. deltaL    equ    $+1
  775.     lxi    d,8
  776.  
  777.     dad    d
  778.     shld    glen
  779.     ret
  780.  
  781.  
  782.  
  783.  
  784. .stcNIT:
  785. ;
  786. ;    bsflag = FALSE;
  787.     xra    a
  788.     sta    bsflag
  789.     mov    a,c
  790.     sta    laststow
  791. ;
  792. ;    /* adjust for expanded, etc.        */
  793. ;    if (stowmode & EXPNDD) stowlen <<= 1;
  794.  
  795.     push    b
  796.  
  797.     lda    stowmode
  798.     mov    c,a
  799. ;from here, keep low byte of stowmode in C
  800.     lhld    stowlen
  801. ;... and stowlen in HL
  802.  
  803.     ani    EXPNDD
  804.     jz    .stc19
  805. ;;    lhld    stowlen
  806.     dad    h
  807.     shld    stowlen
  808. ;    if (font)
  809. .stc19:
  810.     mov    a,b
  811.     ora    a
  812.     jz    .stc24
  813. ;    {    if (stowmode & CMPRSSD) stowlen -= stowlen >> 2;
  814.  
  815.     mov    a,c
  816.     ani    CMPRSSD
  817.     jz    .stc20
  818.  
  819. ;;    lhld    stowlen
  820.     push    h
  821. ;;    lhld    stowlen
  822.     lxi    d,2
  823.     call    shlrbe
  824.     pop    d
  825.     call    cmh
  826.     dad    d
  827.     shld    stowlen
  828.  
  829. ;        if (stowmode & ELITE)   stowlen -= stowlen / 5;
  830. .stc20:
  831.     mov    a,c
  832.     ani    ELITE
  833.     jz    .stc21
  834.  
  835. ;;    lhld    stowlen
  836.     push    h
  837. ;;    lhld    stowlen
  838.     lxi    d,5
  839.     xchg
  840.     call    sdiv
  841.     pop    d
  842.     call    cmh
  843.     dad    d
  844.     shld    stowlen
  845.  
  846. ;        if (st)            stowlen += stowlen / st;
  847. .stc21:
  848.     lhld    st
  849.     mov    a,h
  850.     ora    l
  851.     jz    .stc22
  852.  
  853.     xchg
  854.     lhld    stowlen
  855.     push    h
  856.     xchg
  857.     call    sdiv
  858.     pop    d
  859.     dad    d
  860.     shld    stowlen
  861.  
  862. ;        if (sh)            stowlen -= stowlen / sh;
  863. .stc22:    lhld    sh
  864.     mov    a,h
  865.     ora    l
  866.     jz    .stc23
  867.  
  868.     xchg
  869.     lhld    stowlen
  870.     push    h
  871.     xchg
  872.     call    sdiv
  873.     pop    d
  874.     call    cmh
  875.     dad    d
  876.     shld    stowlen
  877. ;        if (stowmode & EMPHSZD && bo)
  878. ;                    stowlen += bo << 1;
  879. ;    }
  880. .stc23:
  881.     lhld    bo
  882.     mov    a,h
  883.     ora    l
  884.     jz    .stc24
  885.     mov    a,c
  886.     ani    EMPHSZD
  887.     jz    .stc24
  888.  
  889.     lhld    stowlen
  890.     xchg
  891.     lhld    bo
  892.     dad    h
  893.     dad    d
  894.     shld    stowlen
  895. ;
  896. ;    /* record width and inc't pointers    */
  897. ;    widbuf[outpoint++] = stowlen;
  898. .stc24:
  899. ;get back char in c
  900.     pop    b
  901.  
  902.     lhld    widbuf
  903.     xchg
  904.     lhld    outpoint
  905.     inx    h
  906.  
  907. ;is this right?
  908.     lda    val + 54*('P'-'@') + 2*('T'-'@')
  909.     ora    a
  910.     jnz    $+6
  911.  
  912.     shld    outpoint
  913.     dcx    h
  914.     dad    h
  915.     dad    d
  916.  
  917.     xchg
  918.     lhld    stowlen
  919.     xchg
  920.     mov    m,e
  921.     inx    h
  922.     mov    m,d
  923.  
  924. ;    if (!hyflag) glen += stowlen;
  925.     lda    hyflag
  926.     ora    a
  927.     jnz    .stcxt
  928.  
  929.     lhld    glen
  930.     dad    d
  931.     shld    glen
  932. ;}
  933. .stcxt:
  934.     lxi    h,val + 54*('R'-'@') + 2*('C'-'@')
  935.     mov    a,m
  936.     ora    a
  937.     jz    .stxxt
  938.     dcr    m
  939.     jnz    .stc00    ;go back and do it all again
  940. .stxxt:
  941.     pop    b
  942.     ret
  943.  
  944. hyflag:        db    0
  945. laststow:    db    0
  946.  
  947. stowlen:    dw    0
  948. stowmode:    dw    0
  949. stowkern:    dw    0
  950.  
  951.  
  952.     end
  953.  
  954.