home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / programs / list / rap.lbr / RAP.AZM / RAP.ASM
Assembly Source File  |  1989-01-06  |  38KB  |  1,884 lines

  1. ;RAP.ASM       Reroute all printer data into a diskfile.
  2. ;3/07/88
  3. ;            Copyright 1988, Logic Associates
  4. ;            1433 W. Thome, Chicago, IL 60660
  5. ;
  6. ;          Permission is hereby granted only for
  7. ;          non-profit copying and distribution.
  8. ;                All other rights reserved.
  9. ;
  10. vers    equ    10h    ;Version 1.0
  11. ;
  12. ;--------------------------------------------------------
  13. ;
  14. ;     [] For CP/M 2.2.  (Not tested with CP/M+.)
  15. ;
  16. ;==>  [] Instructions on re-assembling RAP.ASM are in RAP.DOC.
  17. ;     PLEASE READ THEM before attempting to re-assemble.
  18. ;     ------ ---- ----
  19. ;
  20. ;--------------------------------------------------------
  21.  
  22.     if    copy1
  23.  
  24. *********************************************************
  25. *        service/loader routines            *
  26. *********************************************************
  27.  
  28.     org     100h
  29.     jmp    begin
  30.  
  31. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32. ;        variables
  33. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  34.  
  35. buffk    equ    1        ;printer buffer size in K (1 - 32).
  36.  
  37. no    equ    0
  38. yes    equ    255
  39.  
  40. version    db    vers
  41. oldver    db    0        ;version of already-installed (if any) RAP.
  42.  
  43. pgplus6    db    no        ;force load point of module
  44.                 ;  to page boundary+6?
  45.  
  46. loadpnt    dw    0        ;entry to module after loading.
  47.  
  48. xtobdos    dw    0        ;RAP exit target.
  49.  
  50. bdosent dw    0        ;entry point to bdos.
  51.  
  52. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  53. ;variables below this point need not be changed
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ;equates
  56.  
  57. reopen    db    no        ;did log file already exist?
  58.  
  59. progcode equ    'R'        ;code that helps test if RAP already installed.
  60.  
  61. boot    equ    0        ;lowest address within CP/M
  62. bdos    equ    boot+5        ;bdos jump vector.
  63. fcb    equ    boot+5ch
  64. filsize    equ    fcb+33
  65. tbuff    equ    boot+80h    ;default buffer.
  66.  
  67. fchrn    equ    2        ;normal console out.
  68. flist    equ    5        ;list to printer.
  69. fchrd    equ    6        ;direct console i/o.
  70. pstr    equ    9        ;print string.
  71. gvers    equ    12        ;get version number.
  72. fdrst    equ    13        ;disk reset.
  73. fslct    equ    14        ;select disk.
  74. fopen    equ    15        ;open file.
  75. fclos    equ    16        ;close.
  76. fsrc1    equ    17        ;search first
  77. fsrc2    equ    18        ;search next
  78. fdelt    equ    19        ;delete
  79. freds    equ    20        ;read seq.
  80. fwseq    equ    21        ;write seq.
  81. fmake    equ    22        ;create
  82. frenm    equ    23        ;rename.
  83. flogv    equ    24        ;get login vector.
  84. fgetd    equ    25        ;get disk name.
  85. fsdma    equ    26        ;set dma
  86. frrov    equ    29        ;get r/o vector.
  87. fattr    equ    30        ;set file attr.
  88. fuser    equ    32        ;set/get user.
  89. frran    equ    33        ;read ran.
  90. fwran    equ    34        ;write ran.
  91. fsize    equ    35        ;compute file size.
  92. fwrnz    equ    40        ;write ran with zero fill.
  93.  
  94. wboff    equ    03h        ;displacement from bios start to various vecs.
  95. coutoff    equ    0ch
  96. lsoff    equ    0fh
  97. sdoff    equ    24h
  98. dsoff    equ    1bh
  99.  
  100. ctlc    equ    3
  101. bell    equ    7
  102. bs    equ    8
  103. tab    equ    9
  104. cr    equ    13
  105. lf    equ    10
  106. ctlz    equ    26
  107.  
  108.  
  109. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  110. ;messages
  111. eom    equ    '$'
  112.  
  113. mlogon    db    0,0,0,0,0    ;leave room for "clear screen" string.
  114.  
  115.  db cr,lf
  116.  db 'IIIIIIIIII      IIIIIII    IIIIIIIIII ',cr,lf
  117.  db ' IIII  IIII    IIII  III    IIII  IIII',cr,lf
  118.  db ' IIII   III    IIII  III    IIII   III',cr,lf
  119.  db ' IIIIIIIIII    IIIIIIIII    IIIIIIIII ',cr,lf
  120.  db ' IIII III      IIII  III    IIII      ',cr,lf
  121.  db 'IIIIII  IIII  IIIII IIIII  IIIIII     ',cr,lf
  122.  db cr,lf
  123.  db 'Copyright 1988, Logic Associates, 60660',cr,lf
  124.  db eom
  125.  
  126. mlogon2:
  127.  db 'RAP '
  128. verloc:
  129.  db     'x.x          Installed at '
  130. site1:
  131.  db                        'xxxx-'
  132. site2:
  133.  db                                    'xxxx',cr,lf
  134.  db cr,lf
  135.  db 'Reroute/append printer data to a file. ',cr,lf
  136.  db cr,lf
  137.  db ' * Execute as--      RAP               ',cr,lf
  138.  db '        or as--      RAP filename      ',cr,lf
  139.  db cr,lf
  140.  db ' * Creates file if absent.             ',cr,lf
  141.  db cr,lf
  142.  db ' * De-installs itself at warmboot.     ',cr,lf
  143.  db '_______________________________________'
  144.  db eom
  145.  
  146. mnoccp
  147.  db cr,lf
  148.  db cr,lf
  149.  db '** ABORT:  Unable to locate CCP.    ***'
  150.  db bell,cr,lf,eom
  151.  
  152. mbadcre:
  153.  db cr,lf
  154.  db cr,lf
  155.  db '** ABORT: Cannot create printfile.  ***'
  156.  db bell,cr,lf,eom
  157.  
  158. mdifver:
  159.  db cr,lf
  160.  db cr,lf
  161.  db '***  ABORT: RAP versions conflict.  ***'
  162.  db bell,cr,lf,eom
  163.  
  164. notinstm:
  165.  db cr,lf
  166.  db cr,lf
  167.  db '** ABORT: Unknown error during install.'
  168.  db bell,cr,lf,eom
  169. ;db '_______________________________________' ;39 chars.
  170.  
  171. mstllon:
  172.  db bell
  173.  db ' already open on '
  174. pdrive1:
  175.  db                  'A'
  176. punum1:
  177.  db                   '00.*',cr,lf,eom
  178. ;db '*  File PRINTER.LOG already open on A00.*'
  179. ;db '_______________________________________' ;39 chars.
  180.  
  181. mreopnd:
  182.  db ' reopened on '
  183. pdrive2:
  184.  db             'A'
  185. punum2:
  186.  db              '00.  *',cr,lf,eom
  187. ;db '*  File PRINTER.LOG reopened on A00.  *'
  188. ;db '_______________________________________' ;39 chars.
  189.  
  190. mopened:
  191.  db ' opened on '
  192. pdrive3:
  193.  db            'A'
  194. punum3:
  195.  db             '00.    *',cr,lf,eom
  196. ;db '*  File PRINTER.LOG opened on A00.    *'
  197. ;db '_______________________________________' ;39 chars.
  198.  
  199. crlf:
  200.  db cr,lf
  201.  db eom
  202.  
  203. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  204. ;work areas
  205.  
  206. bios    dw    0        ;pointer to bios.
  207. ccp    dw    0        ;pointer to ccp.
  208.  
  209. ;values used in patching traps into bios jumptable.
  210. trapex    dw    0
  211. trapent    dw    0
  212. biosoff    dw    0
  213.  
  214. deflt    db    'PRINTER LOG'    ;default print-file name.
  215.  
  216. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  217. ;        mainline
  218. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  219.  
  220. begin    lxi    h,0
  221.     dad    sp
  222.     shld    stack
  223.  
  224.     lxi    sp,stack
  225.  
  226.     call    hskp        ;initialize variables.
  227.     jnz    beginx        ;error-free?  no, quit.
  228.  
  229.     lda    oldver        ;is RAP being installed fresh?
  230.     ora    a
  231.     cz    install        ; yes, install RAP.
  232.  
  233. beginx:
  234.     call    dologon        ;display logon message.
  235.  
  236.     lhld    stack
  237.     sphl
  238.  
  239.     ret
  240.  
  241. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  242. ;        housekeeping
  243. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  244. ;on exit, if error, z=no, (de)=error message.
  245.  
  246. hskp:
  247.     lxi    d,mlogon    ;display first part of logon message.
  248.     call    print
  249.  
  250.     xra    a
  251.     sta    oldver        ;clear version number of "old" RAP.
  252.  
  253.     lxi    h,0        ;initialize for "CCP not found" msg.
  254.     shld    loadpnt
  255.  
  256.     lda    fcb+1        ;print filename missing?
  257.     sui    ' '
  258.     cz    defaultn    ; yes, insert default name.
  259.  
  260.     call    probe        ;if RAP already active?
  261.     jz    hskp9        ;  yes, exit.
  262.  
  263.     lhld    boot+1        ;initialize bios pointer.
  264.     call    isbios        ; 14 jmps in a row?
  265.     jz    hskp4        ;  yes, that's bios.
  266.  
  267.     call    isxsub        ;  no, test if XSUB is hiding it.
  268.     call    isbios
  269.     lxi    d,mnoccp    ;bios found?
  270.     jnz    hskp9        ; no, abort.
  271.  
  272. hskp4:
  273.     shld    bios
  274.     call    getload        ;compute load address, validate if explicit.
  275.                 ;  on return, if error, a<>0, z=no.
  276. hskp9:
  277.     ret            ;  if error, z = "no"
  278.  
  279. ;--------------------------------------------------
  280. ;instert default name into fcb.
  281.  
  282. defaultn:
  283.     lxi    b,11
  284.     lxi    d,fcb+1
  285.     lxi    h,deflt
  286.     call    move
  287.     ret
  288.  
  289. ;--------------------------------------------------
  290. ;assume xsub is present:  get real addr of true coldboot.
  291. ;on exit, if yes, hl = address of bios wboot entry.
  292.  
  293. isxsub:
  294.     lhld    boot+1
  295.  
  296.     dcx    h        ;  get true warmboot into de,
  297.     mov    d,m
  298.     dcx    h
  299.     mov    e,m
  300.  
  301.     xchg            ;  then into hl.
  302.  
  303.     ret
  304.  
  305. ;--------------------------------------------------
  306. ;test if hl points to bios
  307.  
  308. isbios    dcx    h
  309.     dcx    h
  310.     dcx    h
  311.  
  312.     push    h
  313.  
  314.     lxi    d,3        ;test from wboot to write disk.
  315.     mvi    c,14
  316.  
  317. isbios2:
  318.     dad    d
  319.  
  320.     mov    a,m        
  321.     cpi    jmp        
  322.     jz    isbios4        
  323.  
  324.     cpi    ret        
  325.     mvi    a,1
  326.     jnz    isbios9
  327.  
  328. isbios4:            
  329.     dcr    c
  330.     jnz    isbios2
  331.     mov    a,c
  332.  
  333. isbios9:
  334.     pop    h
  335.  
  336.     ret        ;if bios, z = yes, a=0
  337.  
  338.  
  339. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  340. ;        compute load address
  341. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  342. ;find bdos, then ccp, then adjust down for length of module.
  343. ;on exit, if error, z = no.
  344.  
  345. getload:
  346.     call    locbdos        ;find bdos.
  347.     lxi    b,mnoccp
  348.     jnz    getlod9        ;  not found?  abort.
  349.  
  350.     call    locccp        ;find ccp.
  351.     lxi    b,mnoccp
  352.     jnz    getlod9        ;  not found?  abort.
  353.  
  354.     lhld    ccp        ;point again to start of ccp.
  355.     lda    bdos+2
  356.     sub    h        ;ccp page < = address-5 page?
  357.     jnc    getlod1        ;  yes, save ccp as tpatop
  358.     lhld    bdos+1        ;  no, save location 5 as tpatop.
  359.  
  360. getlod1:            ;compute load point
  361.     lxi    d,-modlen
  362.     dad    d
  363.  
  364.     lda    pgplus6
  365.     cpi    no
  366.     jz    getlod2
  367.  
  368.     lxi    d,-6
  369.     dad    d
  370.  
  371.     mvi    l,6
  372.  
  373. getlod2:
  374.     shld    loadpnt        ;tentative new loadpnt...
  375.  
  376.     lhld    bdos+1        ;  and tobdos.
  377.     shld    xtobdos
  378.  
  379.     xra    a        ;"no error"
  380.  
  381. getlod9:
  382.     ret            ;on exit, z set.
  383.  
  384. ;-------------------------------------------------------
  385. ;locate beginning instruction of bdos.
  386. ;on exit, if found, z  = yes
  387. ;            hl = bdos start (offset 6)
  388.  
  389. locbdos:
  390.     lhld    bios
  391.     lxi    d,-100h
  392.     mvi    b,31h        ;check for max of 3000h below bios
  393.  
  394. locbd2:
  395.     dcr    b
  396.     jz    locbd6        ;exhausted search, no success:  abort.
  397.  
  398.     mvi    l,6        ;set for offset to bdos start.
  399.     dad    d        ;compute bdos start
  400.  
  401.     shld    bdosent        ;save in case found
  402.  
  403.     mov    a,m        ;is this bdos location?
  404.     cpi    jmp        ;at page plus 6, is there a "jmp"...
  405.     jnz    locbd2
  406.  
  407.     inx    h
  408.     mov    a,m
  409.     cpi    11h
  410.     jz    locbd4        ;  ...followed by an 11h (if CP/M)...
  411.  
  412.     ora    a        ;  ...or a null (if bdos already patched)?
  413.     jnz    locbd2        ;   no, try next lower page in memory.
  414.  
  415. locbd4:
  416.     mvi    b,1        ;  yes, set to "found"
  417.     jmp    locbd9
  418.  
  419. locbd6:
  420.     lhld    boot+6        ;points to offset 6?
  421.     cpi    6
  422.     shld    bdosent        ;  yes, assume it's bdos, since
  423.     jz    locbd4        ;      other attempt failed.
  424.  
  425. locbd9:
  426.     dcr    b        ;set z flag to "yes" (found) or "no" (missing)
  427.     mov    a,b
  428.  
  429.     ret
  430.  
  431.  
  432. ;------------------------------------------------
  433. ;check for ccp
  434. ;on exit, if ccp found, z  = yes
  435. ;            hl = ccpstart
  436.  
  437. locccp:
  438.     lhld    bdosent
  439.     mvi    b,31h        ;check no more than 3000h below bdos.
  440.     lxi    d,-100h
  441.  
  442. loccp2:
  443.     dcr    b
  444.     jz    loccp9
  445.  
  446.     mvi    l,0        ;correct to bdos start.
  447.     dad    d        ;advance to next lower page
  448.  
  449.     call    isitjmp        ;check for two jmp instructions.
  450.     jnz    loccp2
  451.  
  452.     call    isitjmp        ;found?
  453.     jnz    loccp2        ;  no, abort.
  454.  
  455.     call    isitjmp        ;a third found?
  456.     jz    loccp2        ;  yes, abort.
  457.  
  458.     mvi    l,0        ;correct to ccp start.
  459.     shld    ccp
  460.  
  461.     mvi    b,1        ;set for "found"
  462.  
  463. loccp9:
  464.     dcr    b        ;set z flag.
  465.     mov    a,b
  466.  
  467.     ret
  468.  
  469. ;---------------------------------------------------
  470. ;check for jump instruction
  471.  
  472. isitjmp:
  473.     mov    a,m
  474.     cpi    jmp
  475.  
  476.     inx    h
  477.     inx    h
  478.     inx    h
  479.  
  480.     ret
  481.  
  482.  
  483. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  484. ;        install module
  485. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  486. ;move it into place.
  487. ;if error, exit with z = no.
  488.  
  489. install:
  490.     call    chgaddr        ;convert to true addresses.
  491.  
  492.     call    customz        ;install runtime values.
  493.     jnz    installx    ;  exit if error
  494.  
  495.     call    doprot        ;patch this module in.
  496.  
  497.     call    movemod        ;move module to load address.
  498.  
  499.     call    dopatch        ;patch bios for moved module.
  500.  
  501.     call    probe        ;now detectably installed, as it should be?
  502.     jz    installx    ; yes, exit.
  503.     lxi    d,notinstm    ; no, say "unknown error."
  504.  
  505. installx:
  506.     ret            ;if error, a<>0, z=no.
  507.  
  508. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  509. ;        convert module2 to true addresses    ;
  510. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  511.  
  512. ; change pseudo addresses to true addresses
  513. chgaddr    lxi    b,loadlen
  514.     lxi    d,module2
  515.     lxi    h,module1
  516.  
  517. truloop    ldax    d
  518.     cmp    m
  519.     cnz    convert
  520.  
  521.     inx    h
  522.     inx    d
  523.     dcx    b
  524.  
  525.     mov    a,b
  526.     ora    c
  527.     jnz    truloop
  528.  
  529.     ret
  530.  
  531. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  532. ;    convert displacement into address
  533. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  534.  
  535. convert    push    b        ;length of module not yet processed
  536.     push    h        ;module1 character position
  537.  
  538. ; get displacement from instruction, put into bc.
  539.     ldax    d
  540.     mov    b,a
  541.  
  542.     dcx    d
  543.     ldax    d
  544.     mov    c,a
  545.  
  546.     lxi    h,-module2    ;normalize displacement to zero
  547.     dad    b
  548.     push    h
  549.     pop    b
  550.  
  551.     lhld    loadpnt        ;add load point for true addr
  552.     dad    b
  553.  
  554. ; move true address to instruction
  555.     mov    a,l
  556.     stax    d
  557.  
  558.     inx    d
  559.     mov    a,h
  560.     stax    d
  561.  
  562.     pop    h
  563.     pop    b
  564.  
  565.     ret
  566.  
  567. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  568. ;    customize module2 at run time
  569. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  570. ;on exit, if error, z = no, a<>0.
  571.  
  572. customz:
  573.     lxi    h,0
  574.     shld    fcb+12
  575.     shld    fcb+14
  576.     shld    fcb+16
  577.  
  578.     call    insertd        ;insert drive name into module 2.
  579.  
  580.     call    insertu        ;insert user number into module 2.
  581.  
  582.     call    tryreop        ;file already there?
  583.     mvi    a,yes
  584.     jz    custmz4        ; yes, skip and say "reopened file."
  585.  
  586.     call    trymake        ;successful creation of new file?
  587.     lxi    d,mbadcre
  588.     jnz    custmzx        ; no, abort
  589.  
  590.     mvi    a,no        ; yes, say "not reopened file."
  591. custmz4:
  592.     sta    reopen
  593.  
  594.     lxi    b,36
  595.     lxi    d,bfcb+module2    ;copy fcb to trap module.
  596.     lxi    h,fcb
  597.     call    move
  598.  
  599.     xra    a        ;no error
  600. custmzx:
  601.     ret            ;if error, a<>0, z=no.
  602.  
  603. ;--------------------------------------------------
  604. ;insert drive name into module 2.
  605.  
  606. insertd:
  607.     lda    fcb
  608.     sui    1
  609.     mvi    c,fgetd        ;get curdrv, put into fcb, if
  610.     cc    bdos        ; fcb is asking for default drive.
  611.     inr    a
  612.     sta    fcb
  613.  
  614.     adi    '@'        ;store drive name in module.
  615.     sta    pdrive1
  616.     sta    pdrive2
  617.     sta    pdrive3
  618.     sta    pdrive+module2
  619.  
  620.     ret
  621.  
  622. ;--------------------------------------------------
  623. ;insert user number into module 2.
  624.  
  625. insertu:
  626.     mvi    e,255        ;save current user number.
  627.     mvi    c,fuser        ;(= user number for printfile).
  628.     call    bdos
  629.     sta    user+module2
  630.  
  631.     mvi    b,'0'             ;default high-digit of unum.
  632.     jmp    instu6
  633.  
  634. instu4:
  635.     inr    b
  636. instu6:
  637.     sui    10        ;unum < 10?
  638.     jnc    instu4        ; yes, skip
  639.  
  640.     adi    10+'0'        ;compute low digit.
  641.     mvi    h,'.'        ;initialize ascii unum,
  642.     mov    l,a        ; in case unum < 10.
  643.  
  644.     mov    a,b        ;hi digit 0?
  645.     cpi    '0'
  646.     mvi    b,' '
  647.     jz    instu8        ; yes, skip.
  648.  
  649.     mov    h,l        ; no, put it in front of lo digit.
  650.     mov    l,a
  651.     mvi    b,'.'
  652. instu8:
  653.     shld    punum+module2    ;update module 2.
  654.     mov    a,b
  655.     sta    punum+module2+2
  656.  
  657.     shld    punum1        ;update messages
  658.     shld    punum2        ; in loader section.
  659.     shld    punum3
  660.  
  661.     sta    punum1+2
  662.     sta    punum2+2
  663.     sta    punum3+2
  664.  
  665.     ret
  666.  
  667. ;--------------------------------------------------
  668. ;reuse old log file, if any.
  669. tryreop:
  670.     lxi    d,fcb        ;a successful reopen?
  671.     mvi    c,fopen
  672.     call    bdos
  673.     ani    0f0h
  674.     jnz    tryreopx    ;  no, skip
  675.  
  676.     lxi    d,fcb        ;address the end of file.
  677.     mvi    c,fsize
  678.     call    bdos
  679.  
  680.     lhld    filsize        ;empty file?
  681.     mov    a,h
  682.     ora    l
  683.     jz    tryreopx    ; yes, exit.
  684.  
  685.     dcx    h
  686.     shld    filsize
  687.     lxi    d,fcb        ; no, get last record in file.
  688.     mvi    c,frran
  689.     call    bdos
  690.  
  691.     lxi    b,80h        ;copy it to module2.
  692.     lxi    d,buffer+module2
  693.     lxi    h,tbuff
  694.     call    move
  695.  
  696.     lxi    h,buffer+module2 ;adjust buffer pointer
  697.     mvi    b,0         ; to point to terminal control-Z.
  698. tryreop4:
  699.     mov    a,m
  700.     cpi    ctlz        ;got it?
  701.     jz    tryreop8    ; yes, skip.
  702.  
  703.     inx    h
  704.     inr    b
  705.     jp    tryreop4
  706.  
  707.     mvi    m,ctlz        ;make up for the missing control-z at end.
  708.  
  709. tryreop8:
  710.     mov    l,b        ;save the adjusted buffer-char pointer.
  711.     mvi    h,0
  712.     shld    bptr+module2
  713.  
  714.     xra    a        ;"file reopened".
  715. tryreopx:
  716.     ret
  717.  
  718. ;--------------------------------------------------
  719. ;try to create a new log file.
  720.  
  721. trymake:
  722.     lxi    d,fcb
  723.     mvi    c,fmake
  724.     call    bdos
  725.     ani    0f0h        ;successful?
  726.  
  727.     ret            ;if yes, a=0
  728.  
  729. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  730. ;        set all traps                ;
  731. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  732. ;set trap for wboot (after module moved into place).
  733.  
  734. dopatch:
  735.     lxi    b,trpwbx+1    ;warmboot vector.
  736.     lxi    d,trpwb
  737.     lxi    h,wboff
  738.     call    settrap
  739.  
  740.     lxi    b,trpsdx+1    ;set-dma vector.
  741.     lxi    d,trpsd
  742.     lxi    h,sdoff
  743.     call    settrap
  744.  
  745.     lxi    b,trplsx+1    ;list vector.
  746.     lxi    d,trpls
  747.     lxi    h,lsoff
  748.     call    settrap
  749.  
  750.     lxi    b,trpdsx+1    ;drive select vector.
  751.     lxi    d,trpds
  752.     lxi    h,dsoff
  753.     call    settrap
  754.  
  755.     ret
  756.  
  757. ;--------------------------------------------------------
  758. ;set a trap
  759. ;on entry, bc=trapex
  760. ;       de=trapent
  761. ;       hl=biosoff
  762.  
  763. settrap:
  764.     shld    biosoff
  765.     xchg
  766.     shld    trapent
  767.     mov    h,b
  768.     mov    l,c
  769.     shld    trapex
  770.  
  771.     lhld    loadpnt        ;get address of moved module
  772.     push    h
  773.     pop    b        ;save in bc
  774.  
  775.     lhld    biosoff        ;get displace for bios jmptable into de
  776.     push    h
  777.     pop    d
  778.  
  779. ;get contents of bios jumptable entry
  780.     lhld    bios
  781.     mvi    l,0
  782.     dad    d        ;address bios jumptable entry
  783.     inx    h
  784.     push    h        ;...save pointer to table entry
  785.  
  786.     mov    e,m        ;...and get contents
  787.     inx    h
  788.     mov    d,m
  789.  
  790. ;store bios entry into trap savearea
  791.     lhld    trapex        ;save bios contents into trap mod
  792.     dad    b
  793.     mov    m,e
  794.     inx    h
  795.     mov    m,d
  796.  
  797. ;set bios entry to trap entry
  798.     lhld    trapent        ;get addr of appropriate trap into de
  799.     dad    b
  800.     xchg
  801.  
  802.     pop    h        ;store trap addr in bios jmptab
  803.     mov    m,e
  804.     inx    h
  805.     mov    m,d
  806.  
  807.     ret
  808.  
  809. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  810. ;        move module into place
  811. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  812.  
  813. movemod:
  814.  
  815. ;move module to load point.
  816.     lxi    b,loadlen+129        ;include potential last record of
  817.     lhld    loadpnt            ; old prinfile + potential ctl-Z.
  818.     xchg                ;destination.
  819.     lxi    h,module2        ;source.
  820.     call    move
  821.  
  822.     ret
  823.  
  824. ;--------------------------------------------------------
  825. ;move block:  source in hl, destination in de, length in bc.
  826.  
  827. move0
  828.     mov    a,m
  829.     stax    d
  830.  
  831.     inx    d
  832.     inx    h
  833.  
  834.     dcx    b
  835.  
  836. move    mov    a,b
  837.     ora    c
  838.     jnz    move0
  839.  
  840.     ret
  841.  
  842. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  843. ;    install security, describe in message
  844. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  845.  
  846. ;move the new secured address to de, then store wherever needed
  847.  
  848. ; secure the module
  849. doprot:
  850.     lhld    xtobdos
  851.     shld    tobdos+module2+1
  852.  
  853.     lhld    loadpnt
  854.     shld    bdos+1        ;protect module  by altering location 5.
  855.  
  856.     xra    a        ;say "ok"
  857.  
  858.     ret
  859.  
  860. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  861. ;        test if reinstallation
  862. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  863. ;is RAP already installed?
  864. ;on exit, if yes,   z = yes,
  865. ;                loadpnt is updated with addr of loaded module.
  866.  
  867. probe:
  868.     lxi    d,0        ;initialize de to 0000.
  869.     mvi    c,flogv
  870.     mvi    b,progcode    ;ask "RAP recursion?"
  871.     call    bdos        ;"get login vector".
  872.  
  873.     mov    a,d        ;de still 0000?
  874.     ora    e        ;("RAP uninstalled?")
  875.     mvi    a,1
  876.     jz    probe9        ;  yes, exit.
  877.  
  878.     xchg
  879.     shld    loadpnt
  880.  
  881.     mov    a,b
  882.     sta    oldver        ;save version number of old RAP.
  883.  
  884.     xra    a        ;say "already installed"
  885.  
  886. probe9:
  887.     ora    a
  888.     ret            ;if z=yes, RAP installed.
  889.  
  890. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  891. ;        display messages
  892. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  893.  
  894. print0:
  895.     push    d
  896.     call    charout
  897.     pop    d
  898.  
  899.     inx    d
  900. print:
  901.     ldax    d
  902.     cpi    eom
  903.     jnz    print0
  904.  
  905.     ret
  906.  
  907. ;....................................................
  908. ;use direct console out, to allow ctrl-s.
  909.  
  910. charout:            ;display buffer char, save z-flag.
  911.     ani    7fh
  912.     mov    e,a        ;display the character.
  913.     mvi    c,fchrn
  914.     call    bdos
  915.  
  916.     ret
  917.  
  918. ;....................................................
  919. dologon:
  920.     push    psw
  921.  
  922.     call    parm2m        ;insert parmeters into logon message.
  923.  
  924.     lxi    d,mlogon2    ;display logon message2.
  925.     call    print
  926.  
  927.     pop    psw        ;regular finish?
  928.     jz    dologon4    ; yes, display rest of normal-end message.
  929.  
  930.     lda    oldver        ;is this first execution of RAP since w-boot?
  931.     ora    a
  932.     jz    dologon9    ;  yes, normal error:  exit and print err msg.
  933.  
  934.     cpi    vers        ;old version same as this version?
  935.     lxi    d,mdifver    ; no, say "mismatched versions."
  936.     jnz    dologon9
  937.  
  938.     lhld    loadpnt        ;copy current printfile name to default name.
  939.     lxi    d,bfcb
  940.     dad    d
  941.     lxi    d,fcb
  942.     lxi    b,12
  943.     call    move
  944.  
  945.     lhld    loadpnt        ;get unum of active file,
  946.     lxi    d,punum
  947.     dad    d
  948.  
  949.     mov    e,m
  950.     inx    h
  951.     mov    d,m
  952.  
  953.     xchg
  954.     shld    punum1        ; store it in "still on" message.
  955.  
  956.     inx    d
  957.     ldax    d        ;get '.' or ' ',
  958.     sta    punum1+2    ; store it in "still on" message.
  959.  
  960.     lxi    d,mstllon    ;say "still on."
  961.     jmp    dologon6
  962.  
  963. dologon4:
  964.     lda    reopen        ;display "opened" or "reopened",
  965.     cpi    yes        ; as appropriate.
  966.     lxi    d,mreopnd
  967.     jz    dologon6
  968.     lxi    d,mopened
  969.  
  970. dologon6:
  971.     push    d
  972.     call    dispname    ;display filename.
  973.     pop    d
  974.  
  975. dologon9:
  976.     call    print
  977.  
  978. dologonx:
  979.     ret
  980.  
  981. ;---------------------------------------------------------
  982. ;display filename from fcb, including a "." if appropriate.
  983.  
  984. dispname:
  985.     lxi    d,fileoff+module2
  986.     call    print
  987.  
  988.     lxi    h,fcb+1
  989.     mvi    b,8
  990.     call    segout
  991.  
  992.     mov    a,m
  993.     cpi    ' '
  994.     jz    dispnamx
  995.  
  996.     mvi    a,'.'
  997.     push    h
  998.     call    charout
  999.     pop    h
  1000.  
  1001.     mvi    b,3
  1002.     call    segout
  1003.  
  1004. dispnamx:
  1005.     ret
  1006.  
  1007. ;---------------------------------------------------------
  1008. segout:
  1009.     push    h
  1010.     push    b
  1011.  
  1012.     mov    a,m
  1013.     cpi    ' '
  1014.     cnz    charout
  1015.  
  1016.     pop    b
  1017.     pop    h
  1018.  
  1019.     inx    h
  1020.     dcr    b
  1021.     jnz    segout
  1022.  
  1023.     ret
  1024.  
  1025. ;---------------------------------------------------------
  1026. ;insert parms into message.
  1027.  
  1028. ;install version number.
  1029. parm2m:
  1030.     lhld    version
  1031.     mov    a,l
  1032.     ani    0fh
  1033.     ori    '0'        ;build and store lower digit of version number.
  1034.     sta    verloc+2
  1035.  
  1036.     mvi    h,3
  1037.     dad    h
  1038.     dad    h
  1039.     dad    h
  1040.     dad    h
  1041.     mov    a,h        ;build and store hi digit of version number.
  1042.     sta    verloc
  1043.  
  1044.     lhld    loadpnt
  1045.     lxi    d,site1        ;loadpoint
  1046.     call    hexinsrt
  1047.  
  1048.     lhld    loadpnt        ;endpoint (if loaded)
  1049.     xchg
  1050.     lxi    h,modlen-1
  1051.     dad    d
  1052.  
  1053.     mov    a,d        ;loaded?
  1054.     ora    e
  1055.     jnz    parm2m2        ;  yes, skip
  1056.  
  1057.     lxi    h,0        ;set endpoint to 0
  1058.  
  1059. parm2m2:
  1060.     lxi    d,site2        ;endpoint
  1061.     call    hexinsrt
  1062.  
  1063.     ret
  1064.  
  1065. ;---------------------------------------------------------
  1066. hexinsrt:
  1067.     mov    a,h
  1068.     call    nibsert1
  1069.  
  1070.     mov    a,h
  1071.     call    nibsert2
  1072.  
  1073.     mov    a,l
  1074.     call    nibsert1
  1075.  
  1076.     mov    a,l
  1077.     call    nibsert2
  1078.  
  1079.     ret
  1080.  
  1081. nibsert1:
  1082.     rar
  1083.     rar
  1084.     rar
  1085.     rar
  1086.  
  1087. nibsert2:
  1088.     ani    0fh
  1089.     adi    '0'
  1090.     cpi    '9'+1
  1091.     jc    nibsert3
  1092.     adi    7
  1093.  
  1094. nibsert3:
  1095.     stax    d
  1096.     inx    d
  1097.  
  1098.     ret
  1099.  
  1100. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1101. ;            stack                ;
  1102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1103.  
  1104.     ds    40    ;internal stack area.
  1105. stack    dw    0    ;savearea for CCP stack pointer.
  1106.  
  1107. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1108. ;        end of service routines            ;
  1109. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1110.     endif
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116. *********************************************************
  1117. *********************************************************
  1118. *    beginning of movable module            *
  1119. *********************************************************
  1120. *********************************************************
  1121.  
  1122.     org    ($+0ffh)/100h*100h    ;must be page boundary
  1123. adjust    set    $
  1124.  
  1125.     if    copy1
  1126. module1    equ    $
  1127.     endif
  1128.  
  1129.     if    not copy1
  1130. module2    equ    $
  1131.     endif
  1132.  
  1133. ;--------------------------------------------------------
  1134. tentry    equ    $-adjust
  1135.     jmp    trmain+adjust
  1136.  
  1137. tobdos    equ    $-adjust
  1138.     jmp    $-$
  1139.  
  1140.     db    '<RAP   >'        ;locator for debugging.
  1141.  
  1142. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1143. ;        bdos trap                ;
  1144. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1145. ;beginning of trap module.  Uses a max of two levels of
  1146. ; caller's stack.
  1147.  
  1148. trmain    equ    $-adjust
  1149.     mov    a,c
  1150.  
  1151.     cpi    flogv        ;trap login vector.
  1152.     jz    trplog+adjust
  1153.  
  1154.     cpi    fchrn        ;trap normal conout.
  1155.     jz    docl+adjust    ; (control-P may be active.)
  1156.  
  1157.     cpi    flist        ;trap list-to-printer.
  1158.     jz    docl+adjust
  1159.  
  1160.     cpi    pstr        ;trap "print-string."
  1161.     jz    dops2+adjust
  1162.  
  1163.     cpi    fsrc1        ;search first?
  1164.     jz    dosrchf+adjust    ; yes, go process.
  1165.  
  1166.     cpi    fsrc2        ;search next?
  1167.     jz    dosrchn+adjust    ; yes, go process.
  1168.  
  1169.     jmp    tobdos+adjust    ; none of the above?  exit to bios.
  1170.  
  1171. ;--------------------------------------------------------------------
  1172. ;do conout or list.
  1173.  
  1174. docl    equ    $-adjust
  1175.     lxi    h,0        ;save caller's stack,
  1176.     dad    sp        ; use local stack.
  1177.     lxi    sp,rstack+adjust
  1178.     push    h
  1179.  
  1180.     call    process+adjust    ;output the char.
  1181.  
  1182.     pop    h        ;restore caller's stack,
  1183.     sphl            ; then return.
  1184.     ret
  1185.  
  1186. ;--------------------------------------------------------------------
  1187. ;do print-string function.
  1188.  
  1189. dops2    equ    $-adjust
  1190.     lxi    h,0        ;save caller's stack,
  1191.     dad    sp        ; use local stack.
  1192.     lxi    sp,rstack+adjust
  1193.     push    h
  1194.  
  1195.     jmp    dops6+adjust
  1196.  
  1197. dops4    equ    $-adjust
  1198.     push    d
  1199.     mvi    c,fchrn
  1200.     mov    e,a
  1201.     call    process+adjust    ;output the char.
  1202.     pop    d
  1203.  
  1204.     inx    d
  1205. dops6    equ    $-adjust
  1206.     ldax    d        ;all done?
  1207.     cpi    eom
  1208.     jnz    dops4+adjust    ; no, loop.
  1209.  
  1210.     pop    h        ;restore caller's stack,
  1211.     sphl            ; then return.
  1212.     ret
  1213.  
  1214. ;------------------------------------------------------------------
  1215. ;do "search first".
  1216.  
  1217. dosrchf    equ    $-adjust
  1218.     xchg
  1219.     shld    oldde+adjust    ;save fcb.
  1220.     xchg
  1221.  
  1222.     lxi    h,0        ;clear "search next" count.
  1223.     shld    srchncnt+adjust
  1224.  
  1225.     lxi    h,nwflush+adjust ;clear "fresh buffer activity" flag.
  1226.     mvi    m,no
  1227.  
  1228.     call    tobdos+adjust    ;do the search.
  1229.  
  1230.     ret            ;return with register a intact.
  1231.  
  1232. ;------------------------------------------------------------------
  1233. ;do "search next".
  1234.  
  1235. dosrchn    equ    $-adjust
  1236.     lhld    srchncnt+adjust    ;update count of "srch next" calls
  1237.     inx    h        ;since last "search first".
  1238.     shld    srchncnt+adjust
  1239.  
  1240.     lda    nwflush+adjust    ;buffer flushed since latest "search first"?
  1241.     cpi    yes
  1242.     jnz    tobdos+adjust    ; no, exit to bios.
  1243.  
  1244.     lxi    h,0        ;save caller's stack,
  1245.     dad    sp        ; use local stack.
  1246.     lxi    sp,rstack+adjust
  1247.     push    h
  1248.  
  1249.     lhld    oldde+adjust    ;get fcb from latest "search first".
  1250.     xchg
  1251.     lhld    srchncnt+adjust    ;get current count of "srch next" calls
  1252.     mvi    c,fsrc1        ;do one "search first"...
  1253.     inx    h        ;(don't count the "search first".)
  1254.  
  1255. dosrchn4 equ    $-adjust
  1256.     push    h
  1257.     call    tobdos+adjust    ;(keep register a intact.)
  1258.     pop    h
  1259.  
  1260.     mvi    c,fsrc2        ; ...and repeat all the "search nexts"s.
  1261.     dcx    h
  1262.  
  1263.     inr    l
  1264.     dcr    l
  1265.     jnz    dosrchn4+adjust
  1266.  
  1267.     inr    h
  1268.     dcr    h
  1269.     jnz    dosrchn4+adjust
  1270.  
  1271.     lxi    h,nwflush+adjust ;clear "fresh buffer activity" flag.
  1272.     mvi    m,no
  1273.  
  1274.     pop    h        ;restore caller's stack
  1275.     sphl
  1276.  
  1277.     ret            ;return with register a intact.
  1278.  
  1279. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1280. ;process character that may go into disk buffer.    ;
  1281. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1282.  
  1283. process    equ    $-adjust
  1284.     call    tobdos+adjust    ;output char to console or "list" device.
  1285.  
  1286.     lda    bptr+adjust+1    ;get hi byte of buffer pointer.
  1287.     cpi    bufflen/256    ;buffer full?
  1288.     cnc    wrbuff+adjust    ; yes, write out buffer and update
  1289.                 ;      directory entry.
  1290.     ret
  1291.  
  1292. ;----------------------------------------------------------------------------
  1293. ;write used portion of buffer to disk.
  1294.  
  1295. wrbuff    equ    $-adjust
  1296.     lda    ok+adjust        ;disk file still enabled?
  1297.     cpi    yes
  1298.     jnz    wrbuffx+adjust        ; no, exit.
  1299.  
  1300.     mvi    c,fuser            ;get and save latest user number.
  1301.     mvi    e,255
  1302.     call    tobdos+adjust
  1303.     sta    olduser+adjust
  1304.  
  1305.     lda    user+adjust        ;set to printfile's user number.
  1306.     mov    e,a
  1307.     mvi    c,fuser
  1308.     call    tobdos+adjust
  1309.  
  1310.     lxi    h,nwflush+adjust    ;set "fresh buffer activity" flag.
  1311.     mvi    m,yes
  1312.  
  1313.     call    testdir+adjust        ;is the directory entry still there?
  1314.     jnz    wrbuff9+adjust        ; no, exit with printing disabled.
  1315.  
  1316.     lhld    bptr+adjust        ;get hi byte of buffer pointer.
  1317.     mov    a,h
  1318.     cpi    bufflen/256        ;buffer full?
  1319.     jnc    wrbuff4+adjust        ; yes, convert into records (no incr).
  1320.  
  1321.     ora    l            ;buffer empty?
  1322.     jnz    wrbuff2+adjust        ; no, increment by one record.
  1323.  
  1324.     lda    buffer+adjust        ;is buffer in pristine, unused state?
  1325.     ora    a
  1326.     jz    wrbuff9+adjust        ; yes, exit, don't write any records.
  1327.  
  1328. wrbuff2    equ    $-adjust
  1329.     lxi    d,128            ;"add" one record to buffer.
  1330.     dad    d
  1331.  
  1332. wrbuff4    equ    $-adjust
  1333.     mvi    a,0
  1334.     dad    h
  1335.     aci    0
  1336.     mov    b,a
  1337.     mov    c,h            ;allows up to a 64K buffer.
  1338.  
  1339. wrbuff6    equ    $-adjust
  1340.     push    b
  1341.  
  1342.     lhld    dma+adjust        ;adjust buffer dma.
  1343.     xchg
  1344.     lxi    h,128
  1345.     dad    d
  1346.     shld    dma+adjust
  1347.  
  1348.     mov    b,d            ;set dma directly to bios,
  1349.     mov    c,e            ; bypassing update of "olddma."
  1350.     call    trpsdx+adjust
  1351.  
  1352.     lxi    d,bfcb+adjust        ;write a record.
  1353.     mvi    c,fwseq
  1354.     call    tobdos+adjust
  1355.  
  1356.     pop    b
  1357.     ora    a            ;error free?
  1358.     jnz    wrbuff8+adjust        ; no, abort
  1359.  
  1360.     dcx    b
  1361.     mov    a,b
  1362.     ora    c
  1363.     jnz    wrbuff6+adjust
  1364.  
  1365. wrbuff8    equ    $-adjust
  1366.     lxi    d,badwmes+adjust
  1367.     cnz    errmess+adjust        ;if error, deactivate further printing.
  1368.  
  1369.     call    closeb+adjust        ;update disk directory. (ignore error.)
  1370.  
  1371.     lxi    h,0            ;reset buffer char-count.
  1372.     shld    bptr+adjust
  1373.  
  1374.     lxi    h,buffer+adjust        ;reset buffer dma.
  1375.     shld    dma+adjust
  1376.  
  1377.     mvi    m,ctlz            ;insure initial control-z at buffhead.
  1378.  
  1379.     lhld    olddma+adjust
  1380.     mov    b,h            ;restore caller's dma.
  1381.     mov    c,l
  1382.     call    trpsdx+adjust
  1383.  
  1384. wrbuff9    equ    $-adjust
  1385.     lda    olduser+adjust        ;restore caller's user number.
  1386.     mov    e,a
  1387.     mvi    c,fuser
  1388.     call    tobdos+adjust
  1389.  
  1390. wrbuffx    equ    $-adjust
  1391.     ret
  1392.  
  1393. ;-----------------------------------------------------------------------
  1394. ;close buffer
  1395.  
  1396. closeb    equ    $-adjust
  1397.     lxi    d,bfcb+adjust
  1398.     mvi    c,fclos
  1399.     call    tobdos+adjust
  1400.  
  1401.     push    psw
  1402.     lda    bs2+adjust
  1403.     ori    80h
  1404.     sta    bs2+adjust
  1405.     pop    psw
  1406.  
  1407.     ret
  1408.  
  1409. ;-----------------------------------------------------------------------
  1410. ;test if current directory entry on disk.
  1411. ;on exit, if error, z = no.
  1412.  
  1413. testdir    equ    $-adjust
  1414.     mvi    b,32        ;copy current fcb to work area.
  1415.     lxi    d,bfcb2+adjust
  1416.     lxi    h,bfcb+adjust
  1417.  
  1418. testdr2    equ    $-adjust
  1419.     mov    a,m
  1420.     stax    d
  1421.     inx    h
  1422.     inx    d
  1423.     dcr    b
  1424.     jnz    testdr2+adjust
  1425.  
  1426.     lxi    d,bfcb2+adjust    ;is file's directory entry on disk?
  1427.     mvi    c,fopen
  1428.     call    tobdos+adjust
  1429.     ani    0f0h
  1430.     jnz    testd9+adjust    ; no, abort.
  1431.  
  1432.     mvi    b,32        ;examine all but drive bytes for exact match.
  1433.     lxi    d,bfcb+adjust
  1434.     lxi    h,bfcb2+adjust
  1435.  
  1436. testd2    equ    $-adjust
  1437.     dcr    b
  1438.     jz    testd9+adjust
  1439.  
  1440.     inx    h        ;(ok to skip compare of the drive bytes.)
  1441.     inx    d
  1442.  
  1443.     ldax    d        ;match?
  1444.     cmp    m
  1445.     jz    testd2+adjust    ; yes, continue.
  1446.  
  1447. testd9    equ    $-adjust
  1448.     lxi    d,badmmes+adjust
  1449.     cnz    errmess+adjust
  1450.  
  1451.     ret
  1452.  
  1453. ;-----------------------------------------------------------------------
  1454. ;tell user disk file has been prematurely closed.
  1455.  
  1456. errmess    equ    $-adjust
  1457.     mvi    c,pstr
  1458.     call    tobdos+adjust
  1459.  
  1460.     lxi    d,dablmes+adjust
  1461.     mvi    c,pstr
  1462.     call    tobdos+adjust
  1463.  
  1464.     mvi    a,no
  1465.     sta    ok+adjust
  1466.  
  1467.     ori    1        ;say "error".
  1468.  
  1469.     ret
  1470.  
  1471. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1472. ;trap "get login vector", and make de point to old-RAP entry point.
  1473. ;(Tells new RAP that old copy is already installed and operating.)
  1474.  
  1475. trplog    equ    $-adjust
  1476.     mov    a,b        ; "RAP recursion?"
  1477.     cpi    progcode
  1478.     jnz    tobdos+adjust
  1479.  
  1480.     call    tobdos+adjust
  1481.  
  1482.     mvi    b,vers
  1483.     lxi    d,tentry+adjust    ;change to entry addr, to indicate RAP active.
  1484.  
  1485.     ret
  1486.  
  1487. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1488. ;        bios traps                ;
  1489. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1490.  
  1491. ;-------------------------------------------------------;
  1492. ;        trap bios warmboot            ;
  1493. ;-------------------------------------------------------;
  1494.  
  1495. trpwb    equ    $-adjust
  1496.     lxi    sp,tbuff+80h
  1497.  
  1498.     call    tstpat+adjust        ;patches available for removal?
  1499.     lxi    d,filecon+adjust
  1500.     jnz    trpwb9+adjust        ; no, say "file active", try later.
  1501.  
  1502. ;    lda    bptr+adjust        ;is last record completely filled?
  1503. ;    ani    7fh
  1504. ;    jnz    trpwb4+adjust        ; no, skip.
  1505. ;
  1506. ;    lhld    bptr+adjust        ; yes, make one more record, with ctlz.
  1507. ;    inx    h
  1508. ;    shld    bptr+adjust
  1509.  
  1510. trpwb4    equ    $-adjust
  1511.     call    wrbuff+adjust        ;flush buffer, update dir, ignore errs.
  1512.  
  1513.     call    remtrps+adjust        ;remove all traps.
  1514.  
  1515.     lxi    d,fileoffx+adjust    ;say "file closed."
  1516. trpwb9    equ    $-adjust
  1517.     call    notify+adjust
  1518.  
  1519. trpwbx    equ    $-adjust
  1520.     jmp    $-$
  1521.  
  1522. ;-----------------------------------------------------------------------
  1523. ;remove all bios traps.
  1524.  
  1525. remtrps    equ    $-adjust
  1526.     lhld    boot+1
  1527.     xchg
  1528.  
  1529.     lhld    trpwbx+1+adjust        ;unpatch bios warmboot vector.
  1530.     mvi    e,wboff
  1531.     call    unpatch+adjust
  1532.  
  1533.     lhld    trplsx+1+adjust        ;unpatch bios list vector.
  1534.     mvi    e,lsoff
  1535.     call    unpatch+adjust
  1536.  
  1537.     lhld    trpsdx+1+adjust        ;unpatch bios setdma vector.
  1538.     mvi    e,sdoff            ;(do this one last, since it's
  1539.     call    unpatch+adjust        ; the one that provides protection.
  1540.  
  1541.     lhld    trpdsx+1+adjust        ;unpatch bios drive select.
  1542.     mvi    e,dsoff            ;(do this one last, since it's
  1543.     call    unpatch+adjust        ; the one that provides protection.
  1544.  
  1545.     ret
  1546.  
  1547. ;-----------------------------------------------------------------------
  1548. ;unpatch bios vector.
  1549.  
  1550. unpatch    equ    $-adjust
  1551.     xchg
  1552.     inx    h
  1553.     mov    m,e
  1554.     inx    h
  1555.     mov    m,d
  1556.     xchg
  1557.  
  1558.     ret
  1559.  
  1560.  
  1561. ;-----------------------------------------------------------------------
  1562. ;say "file closed." or "file active."
  1563.  
  1564. notify    equ    $-adjust
  1565.     push    d
  1566.     lxi    d,fileoff+adjust    ;output "* File"
  1567.     mvi    c,pstr
  1568.     call    bdos
  1569.  
  1570.     call    nameshow+adjust        ;output file name.
  1571.  
  1572.     pop    d            ;output "closed on" or "active on"
  1573.     mvi    c,pstr
  1574.     call    bdos
  1575.  
  1576.     lxi    d,pdrive+adjust        ;output "on A0."
  1577.     mvi    c,pstr
  1578.     call    bdos
  1579.  
  1580.     ret
  1581.  
  1582. ;-----------------------------------------------------------------------
  1583. ;are patches available for removal?
  1584.  
  1585. tstpat    equ    $-adjust
  1586.     lhld    boot+1            ;make sure warmboot vector has not
  1587.     xchg                ; been repatched by another program.
  1588.     lxi    h,trpwb+adjust
  1589.     call    tstvec+adjust
  1590.  
  1591.     mvi    e,sdoff
  1592.     lxi    h,trpsd+adjust
  1593.     cz    tstvec+adjust
  1594.  
  1595.     mvi    e,lsoff
  1596.     lxi    h,trpls+adjust
  1597.     cz    tstvec+adjust
  1598.  
  1599.     mvi    e,dsoff
  1600.     lxi    h,trpds+adjust
  1601.     cz    tstvec+adjust
  1602.  
  1603.     ret                ;if ok to remove, z = "yes."
  1604.  
  1605. ;-----------------------------------------------------------------------
  1606. ;does (de) = hl?
  1607.  
  1608. tstvec    equ    $-adjust
  1609.     inx    d
  1610.     ldax    d            ;still intact as we left it?
  1611.     sub    l
  1612.     mov    b,a
  1613.  
  1614.     inx    d
  1615.     ldax    d
  1616.     sbb    h
  1617.  
  1618.     ora    b
  1619.     ret                ; set z = "yes" or "no".
  1620.  
  1621. ;-------------------------------------------------------;
  1622. ;        trap bios "list output"            ;
  1623. ;-------------------------------------------------------;
  1624. ;prevent any actual output to printer.
  1625. ;on exit, bptr points to next empty byte position.
  1626.  
  1627. trpls    equ    $-adjust
  1628.     lda    ok+adjust    ;disk file operational?
  1629.     cpi    yes
  1630.     jnz    trpls9+adjust    ; no, ignore char.
  1631.  
  1632.     lhld    bptr+adjust
  1633.     mov    a,h
  1634.     cpi    bufflen/256    ;buffer limit reached (full)?
  1635.     jnc    trpls9+adjust    ; yes, ignore char.
  1636.  
  1637.     xchg
  1638.     lxi    h,buffer+adjust    ;point to current unused buff-position.
  1639.     dad    d
  1640.  
  1641.     mov    a,c        ;if ctl-z, convert to ctl-y.
  1642.     ani    7fh
  1643.     cpi    ctlz
  1644.     jnz    trpls4+adjust
  1645.     dcr    c
  1646.  
  1647. trpls4    equ    $-adjust
  1648.     mov    m,c
  1649.     inx    h
  1650.     mvi    m,ctlz        ;insure ctlz at end of file.
  1651.  
  1652.     xchg
  1653.     inx    h
  1654.     shld    bptr+adjust    ;point to new unused buff-position.
  1655.  
  1656. trpls9    equ    $-adjust
  1657.     ret
  1658.  
  1659. ;--------------------------------------------------------
  1660. ;next instruction is used only when unpatching bios.
  1661.  
  1662. trplsx    equ    $-adjust
  1663.     jmp    $-$
  1664.  
  1665.  
  1666. ;-------------------------------------------------------;
  1667. ;        trap bios setdma            ;
  1668. ;-------------------------------------------------------;
  1669.  
  1670. trpsd    equ    $-adjust
  1671.     mov    h,b
  1672.     mov    l,c
  1673.     shld    olddma+adjust
  1674.  
  1675. trpsdx    equ    $-adjust
  1676.     call    $-$
  1677.  
  1678.     call    reprot+adjust
  1679.  
  1680.     ret
  1681.  
  1682. ;--------------------------------------------------------
  1683. ;reprotect RAP if necessary.
  1684.  
  1685. reprot    equ    $-adjust
  1686.     lxi    d,trmain+adjust        ;insure that trap module is protected.
  1687.     lhld    bdos+1
  1688.  
  1689.     mov    a,e
  1690.     sub    l
  1691.     mov    a,d
  1692.     sbb    h
  1693.     jnc    reprotx+adjust
  1694.  
  1695.     xchg
  1696.     shld    bdos+1
  1697.  
  1698. reprotx    equ    $-adjust
  1699.     ret
  1700.  
  1701. ;-------------------------------------------------------;
  1702. ;        trap bios "select drive"        ;
  1703. ;-------------------------------------------------------;
  1704.  
  1705. trpds    equ    $-adjust
  1706. trpdsx    equ    $-adjust
  1707.     call    $-$
  1708.  
  1709.     push    h
  1710.     call    reprot+adjust    ;reprotect RAP, if necessary.
  1711.     pop    h
  1712.  
  1713.     ret
  1714.  
  1715. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1716. ;          conout routines            ;
  1717. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1718.  
  1719. ;display filename from fcb, including a "." if appropriate.
  1720.  
  1721. nameshow equ    $-adjust
  1722.     lxi    h,bfcb+adjust+1
  1723.     mvi    b,8
  1724.     call    namseg+adjust
  1725.  
  1726.     mov    a,m
  1727.     cpi    ' '
  1728.     jz    nameshwx+adjust
  1729.  
  1730.     mvi    a,'.'
  1731.     push    h
  1732.     call    outchar+adjust
  1733.     pop    h
  1734.  
  1735.     mvi    b,3
  1736.     call    namseg+adjust
  1737.  
  1738. nameshwx equ    $-adjust
  1739.     ret
  1740.  
  1741. ;---------------------------------------------------------
  1742. namseg    equ    $-adjust
  1743.     push    h
  1744.     push    b
  1745.  
  1746.     mov    a,m
  1747.     cpi    ' '
  1748.     cnz    outchar+adjust
  1749.  
  1750.     pop    b
  1751.     pop    h
  1752.  
  1753.     inx    h
  1754.     dcr    b
  1755.     jnz    namseg+adjust
  1756.  
  1757.     ret
  1758.  
  1759. ;....................................................
  1760. outchar    equ    $-adjust    ;display buffer char, save z-flag.
  1761.     ani    7fh
  1762.     mov    e,a
  1763.     mvi    c,fchrn
  1764.     call    tobdos+adjust
  1765.  
  1766.     ret
  1767.  
  1768. *********************************************************
  1769.  
  1770.  
  1771. *********************************************************
  1772. *             data areas                *
  1773. *********************************************************
  1774.  
  1775. ok    equ    $-adjust    ;is output file ok?
  1776.     db    yes
  1777.  
  1778. dma    equ    $-adjust
  1779.     dw    buffer+adjust
  1780. olddma    equ    $-adjust    ;restore this after writing records to disk.
  1781.     dw    0
  1782.  
  1783. user    equ    $-adjust
  1784.     db    0
  1785. olduser    equ    $-adjust    ;restore this after writing records to disk.
  1786.     db    0
  1787.  
  1788. nwflush    equ    $-adjust    ;was buffer recently flushed?
  1789.     db    no
  1790.  
  1791. srchncnt equ    $-adjust    ;how many consecutive calls to "search next"?
  1792.     dw    0
  1793.  
  1794. oldde    equ    $-adjust    ;fcb used in latest "search first"
  1795.     dw    0
  1796.  
  1797. ;-------------------------------------------------------
  1798. badmmes    equ    $-adjust
  1799.  db cr,lf,bell
  1800.  db '>>ERROR:  Printfile absent or altered<<',cr,lf,eom
  1801.  
  1802. badwmes    equ    $-adjust
  1803.  db cr,lf,bell
  1804.  db '>>ERROR:  Printfile disk is full.    <<',cr,lf,eom
  1805.  
  1806. dablmes    equ    $-adjust
  1807.  db '>>        Printing is now disabled.  <<',cr,lf,eom
  1808.  
  1809. fileoff    equ    $-adjust
  1810.  db cr,lf
  1811.  db cr,lf
  1812.  db '*  File '
  1813.  db eom
  1814. ;db         'xxxxyyyy.zzz'
  1815.  
  1816. fileoffx equ    $-adjust
  1817.  db                     ' closed on ',eom
  1818. pdrive    equ    $-adjust
  1819.  db                                'A'
  1820. punum    equ    $-adjust
  1821.  db                                 '00.    *',cr,lf,eom
  1822.  
  1823. ;db '*  File PRINTER.LOG closed on A00.    *'
  1824. ;db '_______________________________________',cr,lf
  1825. filecon    equ    $-adjust
  1826.  db                     ' active on ',eom
  1827.  
  1828.  
  1829.  
  1830. ;-------------------------------------------------------
  1831. ;fcbs
  1832.  
  1833. bfcb    equ    $-adjust        ;36 bytes
  1834.     dw    0,0,0,0,0,0,0,0
  1835.     dw    0,0,0,0,0,0,0,0
  1836.     dw    0,0
  1837. bs2    equ    bfcb+14
  1838. brcnt    equ    bfcb+15
  1839.  
  1840. bfcb2    equ    $-adjust        ;36 bytes
  1841.     dw    0,0,0,0,0,0,0,0
  1842.     dw    0,0,0,0,0,0,0,0
  1843.     dw    0,0
  1844.  
  1845. ;-------------------------------------------------------
  1846. ;buffer.
  1847.  
  1848. bptr    equ    $-adjust    ;pointer to next empty char in printer buff.
  1849.     dw    0
  1850.  
  1851. loadlen    equ    $-adjust+1    ;end of initialized ram for RAP module.
  1852.  
  1853. buffer    equ    $-adjust
  1854.     db    0        ;if null, no printer data yet received.
  1855. ;    ds    bufflen        ;bufflen+1 leaves room for terminal control-Z.
  1856. ;                ;(adjusted for below).
  1857.  
  1858. bufflen    equ    buffk*1024
  1859. buffend    equ    buffer+bufflen+1
  1860.  
  1861. ;-------------------------------------------------------
  1862. rstack    equ    buffend+40
  1863. modend    equ    rstack
  1864.  
  1865. modlen    equ    modend+6    ;total length of installed RAP module.
  1866.                 ;(extra 6 bytes leaves space for CP/M
  1867.                 ; serial #, which may be poked in by EX15.)
  1868.  
  1869. *********************************************************
  1870. *        end of relocatable routines        *
  1871. *********************************************************
  1872.  
  1873. ;flip the copy1/copy2 toggle
  1874. copy1    set    not copy1
  1875.  
  1876. ;link a second copy, if this was the first copy
  1877.     if    not copy1
  1878.     link    RAP
  1879.     endif
  1880.  
  1881. progend    equ    $    ;end of assembled program.
  1882.  
  1883.     end
  1884.