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

  1.  
  2.     include    BDSYM.EQU
  3.     include    EPDATA
  4.  
  5.     .comment    `
  6. functions PAPERUP, DOPAGENO
  7.  
  8.  
  9.  
  10. /************************************************/
  11. /* Move print head to beginning of line and down*/
  12. /*   accumulated 'skdots'             */
  13. /************************************************/
  14. paperup(needmore)
  15. int needmore;
  16. {    /* here page    */
  17.  
  18.     if (skdots < 0)
  19.      if (mx) skdots = 0;
  20.      else
  21.      {
  22.         if (vposition + skdots < 0) skdots = -vposition;
  23.         vposition += skdots;
  24.         while (skdots <= -216)
  25.         {    PTESCCH('j'); PTCH(216);
  26.             skdots += 216;
  27.         }
  28.         if (skdots < 0)
  29.         {    PTESCCH('j'); PTCH(-skdots);
  30.         }
  31.         skdots = 0;
  32.      }
  33.  
  34.     if (vposition + skdots + needmore + bm > pl)
  35.     { if (!fm) skdots = pl - vposition  + tm;
  36.       else
  37.       {    skdots = pl - bm + fm - vposition;
  38.         vposition = 0;
  39.         dopageno();
  40.         skdots += bm - vposition + tm;
  41.       }
  42.       vposition = tm;
  43.     }
  44.     else vposition += skdots;
  45.  
  46.  
  47.     while (skdots >= 216)
  48.     {    PTESCCH('J'); PTCH(216);
  49.         skdots -= 216;
  50.     }
  51.  
  52.     if (!skdots) return;
  53.  
  54.     PTESCCH('J'); PTCH(skdots);
  55.  
  56.     skdots = 0;
  57. }            `
  58.  
  59. ;call paperup before printing a line, to do accumulated skips and
  60. ; if necessary, footing and heading lines
  61. paperup::
  62.  
  63.     pop    d
  64.     pop    h
  65.     push    h
  66.     push    d
  67.  
  68. ;if called while doing a title, don't trigger page break
  69.     lda    nospec
  70.     ora    a
  71.     jnz    ejct
  72.  
  73. ;if this will be the first line of a paragraph, add
  74. ; widow threshhold to needmore
  75.     lda    val + 54*('P'-'@') + 2*('P'-'@')
  76.     ora    a
  77.     jz    .ppm1
  78.     xchg
  79.     lhld    val + 54*('W'-'@') + 2*('I'-'@')
  80.     dad    d
  81. .ppm1:
  82.     push    h    ;save needmore
  83.  
  84. ;if vposition is -1, this is the very first time we are being
  85. ; called, so initialize vposition, and do top of page business
  86.     lhld    vposition
  87.     inx    h
  88.     mov    a,h
  89.     ora    l
  90.     jnz    .tti0
  91.  
  92. ;init _savec
  93.     lda    ec
  94.     sta    _savec
  95.  
  96.  
  97.     lhld    tm
  98.     xchg
  99.     lhld    hm
  100.     call    cmh
  101.     dad    d
  102.     shld    vposition
  103.     lhld    skdots
  104.     push    h
  105.     lxi    h,0
  106.     shld    skdots
  107.     call    ttitle
  108.     pop    d
  109.     lhld    skdots
  110.     dad    d
  111.     shld    skdots
  112. .tti0:
  113.     pop    h
  114.     call    ejct
  115.  
  116. ;call ttitle to check if time to print heading, and if so do it
  117. ttitle:
  118.  
  119. ;also, here is a good place to set noprint flag, if pn is out of range
  120. ;(well, it's a place, anyway)
  121.     lhld    pn
  122.     xchg
  123. ; before beginning page?
  124.     lhld    bp
  125.     mov    a,h
  126.     ora    l
  127.     jz    .pchk2
  128.     call    albu
  129.     mvi    a,0
  130.     jc    .pchk3    ;(noprint)
  131. ; after ending page?
  132. .pchk2:    lhld    ep
  133.     mov    a,h
  134.     ora    l
  135.     jz    .pchk4
  136.     call    blau    ;c if pn > ep
  137.     mvi    a,0
  138.     jnc    .pchk4    ;(yes print)
  139. .pchk3: inr    a
  140. .pchk4: sta    noprint
  141.  
  142.  
  143. ;see if time to print heading
  144.     lda    hdgdone
  145.     ora    a
  146.     rnz
  147.  
  148. ;otherwise, if heading is not requested, just skip down to tm
  149.     lhld    hm
  150.     mov    a,h
  151.     ora    l
  152. ;if hm = 0, no heading
  153. ;... (this doesn't seem necessary -- would have done the 'rnc' above)
  154. ;-    jz    .tti1
  155. ;try just ret, instead:
  156.     rz
  157.  
  158.  
  159.  
  160. ;else do heading
  161.  
  162. ;now print the heading
  163.  
  164.     lhld    val + 2*('H'-'@')
  165.     call    dopageno
  166. ;and set the flag
  167.     lxi    h,hdgdone
  168.     inr    m
  169.  
  170. ;here set skips to to tm
  171. .tti1:
  172.     lhld    vposition
  173.     xchg
  174.     lhld    skdots
  175.     dad    d
  176.     call    cmh
  177.  
  178.     xchg
  179.     lhld    tm
  180.     dad    d
  181. ;now HL is additional distance to skip to get down to tm
  182.  
  183. ;don't skip up and print text over heading
  184.     MOV    A,H
  185.     ORA    A
  186.     RM
  187.     xchg
  188.     lhld    skdots
  189.     dad    d
  190.     shld    skdots
  191. ;and go do them
  192.     jmp    .pu9
  193. ;;    jmp    .pu10
  194. ;;??    ret
  195.  
  196. ;call ejct to do a conditional page
  197. ;(called once at very end from epm)
  198. ejct::
  199.  
  200. ;save needmore
  201.     shld    needmore
  202.  
  203.  
  204. ;    if (skdots < 0)
  205. ;     if (mx) skdots = 0;
  206.  
  207.  
  208.     lhld    skdots
  209.     mov    a,h
  210.     ral
  211.     jnc    .pu6
  212.  
  213.     lda    mx
  214.     ora    a
  215.     jz    .pu1
  216.  
  217.     lxi    h,0
  218.     shld    skdots
  219.     jmp    .pu6
  220.  
  221. ;     else
  222. ;     {
  223. ;        if (vposition + skdots < 0) skdots = -vposition;
  224. .pu1:
  225.     lhld    vposition
  226.     xchg
  227.     lhld    skdots
  228.     dad    d
  229.     mov    a,h
  230.     ral
  231.     jnc    .pu2
  232.  
  233.     lhld    vposition
  234.     call    cmh
  235.     shld    skdots
  236.  
  237. ;        vposition += skdots;
  238.  
  239. .pu2:
  240.     lhld    vposition
  241.     xchg
  242.     lhld    skdots
  243.     dad    d
  244.     shld    vposition
  245.  
  246. ;        while (skdots <= -216)
  247. .pu3:
  248.     lhld    skdots
  249.     lxi    d,VINCH-1
  250.     dad    d
  251.     mov    a,h
  252.     ral
  253.     jnc    .pu4
  254.  
  255. ;        {    PTESCCH('j'); PTCH(216);
  256. ;            skdots += 216;
  257. ;        }
  258.  
  259.     mvi    a,'j'
  260.     call    presc1##
  261.     mvi    a,VINCH
  262.     call    pr1##
  263.  
  264.     lhld    skdots
  265.     lxi    d,VINCH
  266.     dad    d
  267.     shld    skdots
  268.     jmp    .pu3
  269.  
  270. ;        if (skdots < 0)
  271. .pu4:    lhld    skdots
  272.     mov    a,h
  273.     ral
  274.     jnc    .pu5
  275. ;        {    PTESCCH('j'); PTCH(-skdots);
  276. ;        }
  277. ;        skdots = 0;
  278. ;     }
  279.  
  280.     mvi    a,'j'
  281.     call    presc1##
  282.  
  283.     lhld    skdots
  284.     call    cmh
  285.     mov    a,l
  286.     call    pr1##
  287.  
  288. .pu5:    lxi    h,0
  289.     shld    skdots
  290.  
  291. ;
  292. ;    if (vposition + skdots + needmore + bm > pl)
  293. ;see if time to do bottom of page action
  294. .pu6:
  295.  
  296. ;never print footing when doing heading or footing
  297.     lda    nospec
  298.     ora    a
  299.     jnz    .pu9
  300.  
  301.     lhld    vposition
  302.  
  303.     xchg
  304.     lhld    skdots
  305.     dad    d
  306.  
  307.     xchg
  308.     lhld    needmore
  309.     dad    d
  310.  
  311.     xchg
  312.     lhld    bm
  313.     dad    d
  314.  
  315.     xchg
  316.     lhld    pl
  317.     call    agbs
  318.     jnc    .pu9
  319.  
  320. ;here it's time for a page break
  321.  
  322. ;signal that we're going to want a heading on next page
  323.     xra    a
  324.     sta    hdgdone
  325.  
  326. ;now see if we have to print a footing
  327. ;    { if (!fm) skdots = pl - vposition  + tm;
  328.  
  329.     lhld    fm
  330.     mov    a,h
  331.     ora    l
  332.     jnz    .pu7
  333.  
  334. ;no, no footing, so set skips to first line of next page
  335. ; (rest of this page and down to hm-tm on next)
  336.     lhld    pl
  337.     xchg
  338.     lhld    vposition
  339.     call    cmh
  340.     dad    d
  341.  
  342.     xchg
  343.     lhld    tm
  344.     dad    d
  345.  
  346.     xchg
  347.     lhld    hm
  348.     call    cmh
  349.     dad    d
  350.  
  351.     shld    skdots
  352. ;now go set vposition
  353.     jmp    .pu8
  354.  
  355. ;      else
  356. ;      {    skdots = pl - bm + fm - vposition;
  357. ;here we have to print a footing, so
  358. ; set skips down to that place
  359. .pu7:
  360.     lhld    pl
  361.     xchg
  362.     lhld    bm
  363.     call    cmh
  364.     dad    d
  365.  
  366.     xchg
  367.     lhld    fm
  368.     dad    d
  369.  
  370.     xchg
  371.     lhld    vposition
  372.     call    cmh
  373.     dad    d
  374.  
  375.     shld    skdots
  376.  
  377. ;        vposition = 0;
  378. ;        dopageno();
  379. ;        skdots += bm - vposition + tm;
  380. ;... and - hm
  381. ;      }
  382. ;now do the footing line
  383.  
  384. ;arg is address of '$f', which if 0 will give def. centered page num.
  385.     lhld    val + 2*('F'-'@')
  386.     call    dopageno
  387.  
  388. ;next page number
  389.     lhld    pn
  390.     inx    h
  391.     shld    pn
  392.  
  393. ;set to skip over rest of this page, and down to first line of next
  394.     lhld    pl
  395.  
  396.     xchg
  397.     lhld    vposition
  398.     call    cmh
  399.     dad    d
  400. ;check over past bm here?
  401.     xchg
  402.     lhld    tm
  403.     dad    d
  404.  
  405.     xchg
  406.     lhld    hm
  407.     call    cmh
  408.     dad    d
  409.  
  410. ;(not this many ADDITIONAL dots  -- just this many)
  411. ;-    xchg
  412. ;-    lhld    skdots
  413. ;-    dad    d
  414.     shld    skdots
  415.  
  416. ;      vposition = tm;
  417. ;... - hm
  418. ;    }
  419. ;now set vposition to what it will be when we're done doing the
  420. ; skips that have accumulated in 'skdots'
  421.  
  422. .pu8:
  423. ;here we're going to be on first line of next page
  424.     lhld    tm
  425.  
  426.     xchg
  427.     lhld    hm
  428.     call    cmh
  429.     dad    d
  430.  
  431.     shld    vposition
  432.     jmp    .pu10
  433.  
  434. ;    else vposition += skdots;
  435. ;here we didn't hit a page break, so just add the skips in
  436. .pu9:
  437.     lhld    vposition
  438.     xchg
  439.     lhld    skdots
  440.     dad    d
  441.     shld    vposition
  442.  
  443.  
  444. ;
  445. ;
  446. ;    while (skdots >= 216)
  447. ;now do the downward skips, first by inches, then the remainder
  448. .pu10:
  449.     lhld    skdots
  450.  
  451.     push    h
  452. .pu10.0:
  453.     lxi    d,-PICA*2
  454.     dad    d
  455.     mov    a,h
  456.     ora    a
  457.     jm    .pu10.1
  458.     push    h
  459.     lxi    h,0
  460.     mvi    a,newlin
  461.     call    termput##
  462.     pop    h
  463.     jmp    .pu10.0
  464. .pu10.1:
  465.     pop    h
  466.  
  467.     lxi    d,-VINCH
  468.     dad    d
  469.     mov    a,h
  470.     ral
  471.     jc    .pu11
  472.  
  473. ;    {    PTESCCH('J'); PTCH(216);
  474. ;        skdots -= 216;
  475. ;    }
  476.     mvi    a,'J'
  477.     call    presc1##
  478.     mvi    a,VINCH
  479.     call    pr1##
  480.  
  481.     lhld    skdots
  482.     lxi    d,-VINCH
  483.     dad    d
  484.     shld    skdots
  485.     jmp    .pu10
  486.  
  487. ;
  488. ;    if (!skdots) return;
  489. .pu11:
  490.     lhld    skdots
  491.     mov    a,h
  492.     ora    l
  493.     rz
  494. ;
  495. ;    PTESCCH('J'); PTCH(skdots);
  496. .pu12:
  497.     mvi    a,'J'
  498.     call    presc1##
  499.     lda    skdots
  500.     call    pr1##
  501.  
  502. ;
  503. ;    skdots = 0;
  504. ;}
  505.     lxi    h,0
  506.     shld    skdots
  507.     ret
  508.  
  509. needmore:    dw    0
  510.  
  511. ;flag to remember whether have put a heading on current page yet
  512. hdgdone:    db    0    ;(initially: no)
  513.  
  514.     .comment    `
  515.     int soutpoint, sglen, slindent, snc, scc, sllength, sdpmode;
  516.     char sepsflag, sgrfflag, sduplflag, stallflag;
  517. dopageno()
  518. {
  519.     outbuf += outpoint+20;
  520.     attrbuf += outpoint+20;
  521.     widbuf += outpoint+20;
  522.     soutpoint = outpoint;
  523.     slindent = lindent[cc];
  524.     sglen    = glen;
  525.     snc = nc; scc = cc;
  526.     sllength = llength;
  527.     sepsflag = epsflag;
  528.     sgrfflag = grfflag;
  529.     stallflag = tallflag;
  530.     sduplflag = duplflag;
  531.  
  532.     glen = outpoint = lindent[0] = nc = cc = 0;
  533.     epsflag = grfflag = tallflag = duplflag = FALSE;
  534.     llength = ll - ir;
  535.  
  536.     sdpmode = mode; mode = 0x100;
  537.  
  538.     stowc(CEFLAG);
  539.     inject(pn);
  540.     gstr();
  541.  
  542.     outbuf = xoutbuf;
  543.     attrbuf = xattrbuf;
  544.     widbuf = xwidbuf;
  545.     outpoint = soutpoint;
  546.     nc = snc; cc = scc;
  547.     lindent[cc] = slindent;
  548.     glen = sglen;
  549.     llength = sllength;
  550.     epsflag = sepsflag;
  551.     grfflag = sgrfflag;
  552.     tallflag = stallflag;
  553.     duplflag = sduplflag;
  554.     mode = sdpmode;
  555.     pn++;    
  556. }            `
  557.  
  558. dopageno::
  559.  
  560. ;    outbuf += outpoint+20;
  561. ;    attrbuf += outpoint+20;
  562. ;    widbuf += outpoint+20;
  563.  
  564. ;save address of heading string
  565.     shld    _hdgstrng
  566.  
  567. ;flag disable global print mode features
  568.     lxi    h,nospec
  569.     mov    a,m
  570.     ora    a
  571.     rnz
  572.     mvi    m,1
  573.  
  574.     lhld    outpoint
  575.     push    h
  576.     xchg
  577.     lhld    endovr
  578.     call    albu
  579.     jnc    $+4
  580.     xchg        ;if outpoint < endovr, use latter
  581.  
  582. ;    lxi    d,20
  583. ;    dad    d
  584. ;    xchg
  585.  
  586.     lhld    outbuf
  587.     push    h
  588.     dad    d
  589.     shld    outbuf
  590.  
  591.     xchg
  592.     dad    h
  593.     xchg
  594.  
  595.     lhld    attrbuf
  596.     push    h
  597.     dad    d
  598.     shld    attrbuf
  599.  
  600.     lhld    widbuf
  601.     push    h
  602.     dad    d
  603.     shld    widbuf
  604.  
  605. ;    soutpoint = outpoint;
  606. ;    slindent = lindent[cc]; (need only save indent[0])
  607. ;    sglen    = glen;
  608.  
  609.     lhld    lindent
  610.     push    h
  611.  
  612.     lhld    glen
  613.     push    h
  614.  
  615. ;    snc = nc; scc = cc;
  616.     lhld    nc
  617.     push    h
  618.     lhld    cc
  619.     push    h
  620.  
  621. ;    sllength = llength;
  622.     lhld    llength
  623.     push    h
  624.  
  625. ;    sepsflag = epsflag;
  626. ;    sgrfflag = grfflag;
  627. ;    stallflag = tallflag;
  628. ;    sduplflag = duplflag;
  629.  
  630.     lda    brkflag
  631.     push    psw
  632.     lxi    h,bkaft
  633.     mov    a,m
  634.     mvi    m,0
  635.     push    psw
  636.     lda    epsflag
  637.     push    psw
  638.     lda    grfflag
  639.     push    psw
  640.     lda    tallflag
  641.     push    psw
  642.     lda    duplflag
  643.     push    psw
  644. ;
  645. ;following added in case of internal break in head or foot
  646.  
  647.     lhld    co
  648.     push    h
  649.     lhld    ju
  650.     push    h
  651.     lhld    endovr
  652.     push    h
  653.     lhld    begovr
  654.     push    h
  655.  
  656. ;and still more
  657.     lhld    bo
  658.     push    h
  659.     lhld    st
  660.     push    h
  661.     lhld    sh
  662.     push    h
  663.     lhld    cheight
  664.     push    h
  665.     lhld    cs
  666.     push    h
  667.     lhld    sl
  668.     push    h
  669.     lhld    ke
  670.     push    h
  671.     lhld    cw
  672.     push    h
  673.     lhld    be
  674.     push    h
  675.     lhld    align
  676.     push    h
  677.     lhld    uc
  678.     push    h
  679.  
  680. ;must have standard escape char
  681.     lhld    ec
  682.     push    h
  683.     lda    _savec
  684.     sta    ec
  685.  
  686. ;
  687. ;    glen = outpoint = lindent[0] = nc = cc = 0;
  688.     lxi    h,0
  689.     shld    co
  690.     shld    ju
  691.     shld    cc
  692.     shld    nc
  693. ;    shld    lindent
  694. ;    shld    outpoint
  695. ;    shld    glen
  696.  
  697.     shld    uc
  698.     shld    align
  699.     shld    be
  700.     shld    cw
  701.     shld    ke
  702.     shld    sh
  703.     shld    st
  704.     shld    bo
  705.  
  706.     lxi    h,POINT
  707.     shld    cs
  708.     dad    h
  709.     shld    sl
  710.     lxi    h,PICA
  711.     shld    cheight
  712.  
  713.  
  714. ;    epsflag = grfflag = tallflag = duplflag = FALSE;
  715. ;(done in newoutline)
  716.  
  717. ;
  718. ;    sdpmode = mode; mode = 0x100;
  719.     lhld    mode
  720.     push    h
  721.  
  722. ;default print mode is font 1 with all style mod's off
  723.     lxi    h,0100H
  724.     shld    mode
  725.  
  726.     call    newoutline##
  727.  
  728. ;if '$footing' or '$heading' defined, use it
  729.     lhld    _hdgstrng
  730.     mov    a,h
  731.     ora    l
  732.     jz    .dpg1
  733.  
  734.     call    shfdirect##
  735.     call    processline##
  736.     call    shfdown##
  737.     jmp    .dpg2
  738. ;
  739. ;    stowc(CEFLAG);
  740.  
  741. .dpg1:
  742. ;    call    newoutline##
  743.     lxi    h,ceflag
  744.     push    h
  745.     call    stowc##
  746.     pop    d
  747.  
  748. ;    inject(pn);
  749.     lhld    pn
  750.     push    h
  751.     call    inject##
  752.     pop    d
  753.  
  754. ;    gstr();
  755. .dpg2:
  756.     call    gstr##
  757.  
  758. ;restoring now done off stack
  759. ;
  760. ;    outbuf = xoutbuf;
  761. ;    attrbuf = xattrbuf;
  762. ;    widbuf = xwidbuf;
  763. ;;etc.
  764.  
  765.     pop    h
  766.     shld    mode
  767.  
  768.     pop    h
  769.     shld    ec
  770.  
  771.     pop    h
  772.     shld    uc
  773.     pop    h
  774.     shld    align
  775.     pop    h
  776.     shld    be
  777.     pop    h
  778.     shld    cw
  779.     pop    h
  780.     shld    ke
  781.     pop    h
  782.     shld    sl
  783.     pop    h
  784.     shld    cs
  785.     pop    h
  786.     shld    cheight
  787.     pop    h
  788.     shld    sh
  789.     pop    h
  790.     shld    st
  791.     pop    h
  792.     shld    bo
  793.  
  794.     pop    h
  795.     shld    begovr
  796.     pop    h
  797.     shld    endovr
  798.     pop    h
  799.     shld    ju
  800.     pop    h
  801.     shld    co
  802.  
  803.     pop    psw
  804.     sta    duplflag
  805.     pop    psw
  806.     sta    tallflag
  807.     pop    psw
  808.     sta    grfflag
  809.     pop    psw
  810.     sta    epsflag
  811.     pop    psw
  812.     sta    bkaft
  813.     pop    psw
  814.     sta    brkflag
  815.  
  816.     pop    h
  817.     shld    llength
  818.     pop    h
  819.     shld    cc
  820.     pop    h
  821.     shld    nc
  822.     pop    h
  823.     shld    glen
  824.     pop    h
  825.     shld    lindent
  826.     pop    h
  827.     shld    widbuf
  828.     pop    h
  829.     shld    attrbuf
  830.     pop    h
  831.     shld    outbuf
  832.     pop    h
  833.     shld    outpoint
  834.  
  835. ;    pn++;    
  836. ;}
  837. ;now incr pn in ejct above
  838. ;    lhld    pn
  839. ;    inx    h
  840. ;    shld    pn
  841.  
  842.  
  843. ;flag re-enable global print mode features
  844.     xra    a
  845.     sta    nospec
  846.  
  847.     ret
  848.  
  849. _hdgstrng:    dw    0
  850. _savec:        db    0
  851.  
  852.     end
  853.  
  854.