home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / z3util / jltools.lbr / RCPSAMPL.AZM / RCPSAMPL.ASM
Encoding:
Assembly Source File  |  1993-06-07  |  10.3 KB  |  507 lines

  1. title    RCPSAMPL.ASM 7/8/88
  2. ;
  3. .xlist
  4. ; Author:    Bridger Mitchell (Plu*Perfect Systems)
  5. ; Program:    RCPSAMPL.ASM
  6. ; Date:        7/8/88
  7. ; Systems:    Z-Systems on CP/M 2.2 or CP/M Plus
  8. ;
  9. ;
  10. ; This is a small, sample Resident Command Processor source file.
  11. ; Its purpose is to illustrate the use of named-common relocation
  12. ; bases to create Z-System Relocatable (ZRL) files for use on any
  13. ; Z-System.
  14. ;
  15. ; The basic routines are somewhat modified from those in the
  16. ; RCP package supplied with ZCPR33, (c) 1987 Jay Sage.
  17. ;
  18. ; Significant changes from Jay's code are marked in the right
  19. ; margin with "++".
  20. ;
  21. ; The key points are:
  22. ;   1. All intersegment references must either --
  23. ;      a. be computed from an address in the external environment
  24. ;      e.g. whl address
  25. ;
  26. ;      b. or be obtained from a named-common relocation base equate.
  27. ;      e.g. z3env
  28. ;
  29. ;   2. The address of the ccp is obtained from the extended environment.
  30. ;
  31. ;   3. For CP/M Plus (CP/M 3) compatibility, disk space must
  32. ;      be calculated by using the bdos function #46 for that purpose.
  33. ;      (Joe Wright contributed the compact divide-by-eight routine).
  34. ;
  35. ;  The resulting REL file can be loaded with JetLDR.  For easy
  36. ;  identification it should be renamed to type ZRL.
  37. ;
  38. ;  See JetLDR.MMO for information about named-commons.
  39. ;
  40. ;
  41. ;  Declare the module name: "RCP" plus version/feature characters.
  42. ;
  43. name    RCP000                            ;    ++
  44. ;
  45. ;
  46. ;  The _ID_ common data are embedded in the ZRL file and displayed by
  47. ;  JetLDR.  Terminate the information with a nul byte.  Don't
  48. ;  exceed 255 bytes.
  49. ;
  50. ;
  51. COM    /_ID_/                            ;    ++
  52. ;                                ;    ++
  53.  db    'RCPSAMPL - example of an RCP in named-common ZRL form.';    ++
  54.  db    CR,LF                            ;    ++
  55.  db    'Also CP/M 3-compatible SP and H commands'        ;    ++
  56.  db    CR,LF                            ;    ++
  57.  db    'SP, WHL, H',0                        ;    ++
  58. ;
  59. ;
  60. ; Include the named-common relocation base declarations.
  61. ;
  62. maclib    Z3COMMON                        ;    ++
  63. ;
  64. ;
  65. CR    equ    0dh
  66. LF    equ    0ah
  67. ;
  68. bdos    equ    5
  69. fcb1    equ    5ch
  70. tbuff    equ    80h
  71.  
  72. offcmd        equ    25    ; Offset to command table
  73. cmdsline    equ    5    ; # commands per line
  74. cmdspace    equ    8    ; MUST BE > # chars in a command!
  75.  
  76. CSEG
  77. origin:
  78.     db    'Z3RCP'        ; Package ID
  79.     db    4        ; Length of each command name
  80. ;
  81.     db    'SP  '        ; first command
  82.     dw    space        ; address
  83.     db    'H   '
  84.     dw    clist
  85.     db    'WHL '
  86.     dw    whl
  87.     db    0        ; NUL marks end of command jump table
  88.  
  89. ; Name of RCP
  90. ;
  91. rcpname:
  92.     db    'RCP-sample ZRL segmen','t'+80h
  93.  
  94. ;
  95. ;----------------------------------------
  96. page
  97. ;
  98. ;    D I S K    S P A C E    C O M M A N D
  99. ;
  100. ; Command:    SP (CP/M 2 and CP/M 3 compatible)            ++
  101. ; Function:    Shows space remaining on designated drive
  102. ; Syntax:    SP [DIR:|DU:]
  103.  
  104. space:    ld    a,(fcb1)    ; Determine requested drive
  105.     or    a        ; If drive explicitly selected
  106.     jr    nz,space1    ; ..then skip
  107. ;
  108.     ld    c,25        ; BDOS get current drive function
  109.     call    bdos
  110.     inc    a        ; Shift to range 1..16
  111. ;
  112. space1:    dec    a        ; Shift to range 0..15
  113.     ld    e,a        ; Save in E for selecting disk below
  114.     ld    (spacedrv),a    ; save for cp/m 3             ++
  115.     add    'A'        ; Convert to letter and
  116.     ld    (seldrv),a    ;   save in message string below
  117.     ld    c,14        ; BDOS select disk function
  118.     call    bdos        ; Not needed if no drive selected, but
  119.                 ; .. smallest possible code size this way.
  120. ;
  121. ; check for cp/m 3        ;                    ++
  122. ;
  123.     ld    c,12        ; get bdos version            ++ 
  124.     call    bdos        ; if not cp/m 3 system            ++
  125.     cp    30h        ;                    ++
  126.     jr    c,dparams    ; ..jump to calculate from alv        ++
  127. ;
  128.     ld    de,0080h    ; set default dma at 0080h        ++
  129.     ld    c,26        ;                    ++
  130.     call    bdos        ;                    ++
  131.     ld    c,46        ; get disk freespace             ++
  132. spacedrv equ    $+1        ;                    ++
  133.     ld    e,00        ; ..on this drive            ++
  134.     call    bdos        ;                    ++
  135. ;
  136. ; Disk space is returned by CPM+ at tbuff for 3 bytes.            ++
  137. ;
  138.     ld    hl,(tbuff)    ; Low to L, Mid to H            ++
  139.     ld    a,(tbuff+2)    ; High to A                ++
  140.     ld    b,3        ; Divide by 8 (SHR 3)            ++
  141. ;
  142. ; Shift everything right into HL (64 MB max reportable) [jww]        ++
  143. ;
  144. div:    or    a        ; Clear carry                ++
  145.     rra            ; High                    ++
  146.     rr    h        ; Mid                    ++
  147.     rr    l        ; Low                    ++
  148.     djnz    div        ; Again?                ++
  149. ;
  150.     jr    free6        ; result: hl = space free in Kbytes    ++
  151. ;
  152. ; For CP/M 2 use this method:    ;                    ++
  153. ; Here we extract the following disk parameter information from the disk
  154. ; parameter block (DPB):
  155. ;    BLKSHF: block shift factor (1 byte)
  156. ;    BLKMAX:    max number of blocks on disk (2 bytes)
  157.  
  158. dparams:
  159.     ld    c,31        ; BDOS get disk parameters function
  160.     call    bdos
  161.     inc    hl        ; Advance to block shift factor byte
  162.     inc    hl
  163.     ld    a,(hl)        ; Get value and
  164.     ld    (blkshf),a    ; ..save it in code below
  165.     inc    hl        ; Advance to max block number word
  166.     inc    hl
  167.     inc    hl
  168.     ld    e,(hl)        ; Get value into HL
  169.     inc    hl
  170.     ld    d,(hl)
  171.     inc    de        ; Add 1 for max number of blocks
  172.  
  173. ; Compute amount of free space left on disk
  174.  
  175. dfree:
  176.     ld    c,27        ; BDOS get allocation vector function
  177.     push    de        ; Save BLKMAX value
  178.     call    bdos        ; Get allocation vector into HL
  179.     ld    b,h        ; Copy allocation vector to BC
  180.     ld    c,l
  181.     pop    hl        ; Restore MAXBLK value to HL
  182.     ld    de,0        ; Inititialize count of free blocks
  183.  
  184. ; At this point we have
  185. ;    BC = allocation vector address
  186. ;    DE = free block count
  187. ;    HL = number of blocks on disk
  188.  
  189. free1:
  190.     push    bc        ; Save allocation address
  191.     ld    a,(bc)        ; Get bit pattern of allocation byte
  192.     ld    b,8        ; Set to process 8 blocks
  193. free2:
  194.     rla            ; Rotate allocated block bit into carry flag
  195.     jr    c,free3        ; If set (bit=1), block is allocated
  196.     inc    de        ; If not set, block is not allocated, so
  197.                 ; ..increment free block count
  198. free3:
  199.     ld    c,a        ; Save remaining allocation bits in C
  200.     dec    hl        ; Count down number of blocks on disk
  201.     ld    a,l        ; See if we are down to zero
  202.     or    h
  203.     jr    z,free4        ; Branch if no more blocks to check
  204.     ld    a,c        ; Get back current allocation bit pattern
  205.     djnz    free2        ; Loop through 8 bits
  206.     pop    bc        ; Get pointer to allocation vector
  207.     inc    bc        ; Point to next allocation byte
  208.     jr    free1        ; Continue by processing next allocation byte
  209.  
  210. free4:
  211.     pop    bc        ; Clean up stack
  212.     ex    de,hl        ; Free block count to HL
  213. blkshf    equ    $+1        ; Pointer for in-the-code modification
  214.     ld    a,0        ; Get block shift factor
  215.     sub    3        ; Convert to log base 2 of K per block
  216.     jr    z,free6        ; Done if single density (1k per block)
  217.  
  218. ; Convert for blocks of more than 1K each
  219.  
  220. free5:
  221.     add    hl,hl
  222.     dec    a
  223.     jr    nz,free5
  224.  
  225. ;
  226. ; At this point HL = amount of free space on disk in K
  227.  
  228. free6:
  229.     call    print
  230.     db    ' Space on '
  231. seldrv:    db    0        ; Modified above to contain drive letter
  232.     db    ':',[' '+80h]
  233.  
  234. ; Display decimal value of HL
  235.  
  236.     ld    b,0        ; Initialize count of digits already printed
  237.     ld    de,10000    ; Divisor in DE
  238.     call    decdsp        ; Print digit (or space if leading '0')
  239.     ld    de,1000
  240.     call    decdsp
  241.     call    decdsp3        ; Display hundreds, tens, and units
  242.     ld    a,'K'
  243.     jp    conout        ; Final return from space routine
  244.  
  245.  
  246. ;----------------------------------------
  247. page
  248. ;Command: WHL/WHLQ
  249. ;Function:  Set the Wheel Byte on or off
  250. ;
  251. ;Form:
  252. ;    WHL        -- turn Wheel Byte OFF
  253. ;    WHL password    -- turn Wheel Byte ON if password is correct
  254. ;    WHLQ        -- find out status of Wheel Byte
  255. ;
  256. whl:
  257.     ld    hl,fcb1+1    ; Pt to first char
  258.     ld    a,(hl)        ; Get it
  259.     cp    ' '        ; Turn byte off if no password
  260.     jr    z,whloff
  261.     ld    de,whlpass
  262.     ld    b,8        ; Check 8 chars
  263.     call    comp        ; Compare
  264.     jr    nz,whlmsg
  265.  
  266. ; TURN ON WHEEL BYTE
  267.  
  268.     ld    a,0ffh        ; Turn on wheel byte
  269.     jr    whlset
  270.  
  271. ; TURN OFF WHEEL BYTE
  272.  
  273. whloff:
  274.     xor    a        ; Turn off wheel byte
  275. whlset:
  276.     ld    hl,(z3env+29h)    ; Set wheel byte and print message    ++
  277.     ld    (hl),a        ;                    ++
  278.  
  279. ; PRINT WHEEL BYTE MESSAGE
  280.  
  281. whlmsg:
  282.     call    print
  283.     db    ' Wheel Byte',' '+80h
  284.     call    testz3whl    ; Get wheel byte            ++
  285.     jr    z,offm        ; Zero is off
  286.     call    print
  287.     db    'O','N'+80h
  288.     ret
  289. offm:
  290.     call    print
  291.     db    'OF','F'+80h
  292.     ret
  293.  
  294. ;
  295. ; Test wheel byte
  296. ;
  297. testz3whl:
  298.     push    hl        ;                    ++
  299.     ld    hl,(z3env+29h)    ;                    ++
  300.     ld    a,(hl)        ;                    ++
  301.     or    a        ;                    ++
  302.     pop    hl        ;                    ++
  303.     ret            ;                    ++
  304.  
  305.     db    'Z'-'@'        ; Leading ^z to block attempt to type rcp file
  306. whlpass:
  307.     db    'PASSWORD'
  308. ;
  309. ;
  310. ;----------------------------------------
  311.     page
  312. ;
  313. ;    H E L P    C O M M A N D
  314. ;
  315. ; This command displays a list of all resident commands that are supported,
  316. ; including those in the CPR (command processor), RCP, and FCP.
  317.  
  318. ;
  319. ; All inter-segment references are obtained from named-common bases
  320. ; (z3env, ccp).
  321. ;
  322. clist:
  323.  
  324. ; Print the FCP-resident command names
  325.  
  326.     call    print
  327.     db    lf
  328.     db    'FC','P'+80h
  329.     ld    hl,(z3env+12h)    ; Point to FCP command table        ++
  330.     ld    de,5
  331.     add    hl,de
  332.     call    cmdlist
  333. ;
  334. ; Print the CPR-resident command names
  335.  
  336.     call    print
  337.     db    lf
  338.     db    'CP','R'+80h
  339.     ld    hl,(z3env+3fh)    ; Point to command table in CPR        ++
  340.     ld    de,offcmd    ;                    ++
  341.     add    hl,de        ;                    ++
  342.     call    cmdlist
  343.  
  344. ; Print the RCP-resident command names
  345.  
  346.     call    crlf        ; Skip a line
  347.     ld    hl,rcpname    ; Print RCP name
  348.     call    printhl
  349.     ld    hl,(z3env+0ch)    ; Point to RCP command table        ++
  350.     ld    de,5
  351.     add    hl,de
  352.  
  353. cmdlist:
  354.     call    crlf
  355.     ld    e,(hl)
  356.     ld    d,0
  357.     inc    hl
  358.     ld    c,cmdsline    ; Set names-per-line value
  359.  
  360. cmdlist1:
  361.     ld    a,(hl)
  362.     or    a
  363.     jr    nz,cmdlist1a
  364.     ld    a,cmdsline
  365.     cp    c
  366.     call    nz,crlf
  367.     ret
  368.  
  369. cmdlist1a:
  370.     rla
  371.     jr    nc,cmdlist2
  372.     call    testz3whl
  373.     jr    nz,cmdlist2
  374.     add    hl,de
  375.     jr    cmdlist5
  376.  
  377. ; Print leading spaces between names
  378.  
  379. cmdlist2:
  380.     ld    a,cmdspace    ; Spacing between command names
  381.     sub    e
  382.     ld    b,a
  383.     ld    a,' '
  384. cmdlist3:
  385.     call    conout
  386.     djnz    cmdlist3
  387.  
  388. ; Print name of command
  389.  
  390.     ld    b,e
  391. cmdlist4:
  392.     ld    a,(hl)
  393.     call    conout
  394.     inc    hl
  395.     djnz    cmdlist4
  396.  
  397.     dec    c
  398.     jr    nz,cmdlist5
  399.     call    crlf
  400.     ld    c,cmdsline
  401.  
  402. ; Skip to next command name
  403.  
  404. cmdlist5:
  405.     inc    hl
  406.     inc    hl
  407.     jr    cmdlist1
  408.  
  409. ;----------------------------------------
  410.  
  411. ; Subroutines extracted from rcpsubs.lib for zcpr33.
  412. ; (c)  1987 Jay Sage
  413. ;
  414. crlf:
  415.     call    print
  416.     db    cr,lf+80h
  417.     ret
  418.  
  419. decdsp3:
  420.     ld    de,100
  421.     call    decdsp
  422.     ld    e,10
  423.     call    decdsp
  424.     ld    a,l
  425.     add    '0'
  426.     jr    conout
  427.  
  428. decdsp:
  429.     ld    c,'0'-1
  430.     xor    a
  431.  
  432. decdsp1:
  433.     inc    c
  434.     sbc    hl,de
  435.     jr    nc,decdsp1
  436.     add    hl,de
  437.     ld    a,c
  438.     cp    '0'
  439.     jr    nz,decdsp2
  440.     ld    a,b
  441.     or    a
  442.     ld    a,' '
  443.     ret    z
  444. decdsp2:
  445.     inc    b
  446.     ld    a,c
  447. ;
  448. ; fall thru to conout
  449.  
  450. ;  Console Output Routine
  451.  
  452. conout:
  453.     push    bc
  454.     push    de
  455.     push    hl
  456.     push    af
  457.     and    7fh
  458.     ld    e,a
  459.     ld    c,2
  460.     call    bdos
  461.     pop    af
  462.     pop    hl
  463.     pop    de
  464.     pop    bc
  465.     ret
  466.  
  467. print:
  468.     ex    (sp),hl
  469.     call    printhl
  470.     ex    (sp),hl
  471.     ret
  472.  
  473. printhl:
  474.     ld    a,(hl)
  475.     inc    hl
  476.     or    a
  477.     ret    z
  478.     call    conout
  479.     ret    m
  480.     jr    printhl
  481.  
  482. ;
  483. ;  comp compares de w/hl for b bytes; ret w/carry if de<hl
  484. ;    msb is disregarded
  485. ;
  486. comp:
  487.     ld    a,(hl)
  488.     and    7fh
  489.     ld    c,a
  490.     ld    a,(de)
  491.     and    7fh
  492.     cp    c
  493.     ret    nz
  494.     inc    hl
  495.     inc    de
  496.     djnz    comp
  497.     ret
  498. ;
  499.  
  500.     end
  501. 
  502.     inc    hl
  503.     inc    hl
  504.     jr    cmdlist1
  505.  
  506. ;---------------------------------