home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / rcpm / run201.lbr / RUN201.AZM / RUN201.ASM
Assembly Source File  |  1987-08-28  |  7KB  |  232 lines

  1. ;RUN.ASM
  2. ;
  3. ;Charles E. Horn,PE
  4. ;Horn Engineering Associates
  5. ;Garland, TX
  6. ;28 April 1984
  7. ;(No rights reserved)
  8. ;
  9. ;======================================================================
  10. ;REVISION HISTORY
  11. ;
  12. ;06/11/85    Corrected error in computation of load address in
  13. ;        code as noted. [CEH 06/11/85]
  14. ;======================================================================
  15. ;RUN is a variation of the original RUNFILE program by Phil Cary.  That
  16. ;program was designed for use on an RBBS and permits one to execute
  17. ;a selected program from a selected high user area, even though the
  18. ;file is not normally accessible to the user or caller.  With this
  19. ;technique, the file can be executed without alteration of the wheel
  20. ;byte.
  21. ;
  22. ;RUN is somewhat different.  RUNFILE loads the program loader just
  23. ;below the BDOS and over a portion of the CCP.    This is no problem if
  24. ;the executed program (such as RBBS) exits with a warmboot, which
  25. ;reloads the CCP.  However, some programs exit directly to CP/M without
  26. ;a warmboot (such as SD.COM).  If it is allowed to do this when called
  27. ;from RUNFILE, the CCP will remain corrupt.  RUN solves this problem
  28. ;by locating the program loader just below the CCP.
  29. ;
  30. ;RUN requires specification of a file name in the command line.  This can
  31. ;be at least as secure as an 8-character password because the file in
  32. ;the high user area can be named anything and will not be accessible for
  33. ;view by directory if the BBS does not normally permit a user to access
  34. ;these high areas.  This is the purpose of MAXUSR and MAXDRV in the
  35. ;various RBBS utilities, such as NZCPR.
  36. ;
  37. ;The command syntax is: A>RUN <filename>
  38. ;
  39. ;The program will also support the usual command line extensions if the
  40. ;target program normally extracts them from the CP/M default DMA area.
  41. ;For example, RUN SD $A would work.  RUN SD B: $A would not work because
  42. ;the extra $A entry would clobber the CP/M secondary FCB.  However, the
  43. ;variation RUN B:SD $A would cause the target file, SD in user 14, for
  44. ;example, to go to drive B: and display all files in all user areas.
  45. ;This program also offers an option to build the target file name into
  46. ;the program so that it will operate in the same mode as the RUNFILE
  47. ;program.  In this case the command would simply be RUN.
  48. ;
  49. ;
  50. WRCON:    EQU    2        ;Console output
  51. PRINTF:    EQU    9        ;Print string
  52. BDOS:    EQU    5        ;Bdos Call
  53. SELDRV: EQU    14        ;Select Default Drive
  54. OPEN:    EQU    15        ;Open file
  55. READ:    EQU    20        ;Read sequential
  56. SETDMA:    EQU    26        ;Set DMA Address
  57. USER:    EQU    32        ;Set user area
  58. RDS:    EQU    13        ;Reset disk system
  59. ;
  60. CPMFCB: EQU    5CH        ;CP/M primary FCB address
  61. CP2FCB: EQU    6CH        ;CP/M secondary FCB address
  62. ;
  63. ;MISC EQUATES
  64. ;
  65. CR:    EQU    0DH
  66. LF:    EQU    0AH
  67. BLANK:    EQU    20H
  68. ;
  69. ;
  70.     ORG    100H
  71. ;
  72. ;
  73.     JMP    START        ;Skip following data
  74. ;
  75. ;
  76. ;CHANGE THE FOLLOWING TO MEET YOUR REQUIREMENTS
  77. ;
  78. RETDRV: EQU    0        ;Exit to Drive A
  79. RETUSR: EQU    0        ;..and User 0
  80. DEFDRV:    EQU    'A'-'@'        ;Drive containing the COM file you want
  81. DEFUSR:    EQU    14        ;User area "     "     "      "    "
  82. ;
  83. RUNFIL: DB    'XFILE   '    ;Filename you are CALLING
  84. ;Eight Chars-->> ^^^^^^^^<<    ; 
  85. ;
  86. ;NOTE:    If it desired to build the target file name into this program
  87. ;    without using the command line technique, change the code in
  88. ;    the program as noted below.  In this case, the user can not
  89. ;    use RUN to execute any arbitrary file, but is stuck with the
  90. ;    one that is built in above.
  91. ;
  92. ERRMSG:    DB    CR,LF        
  93.     DB    'You must be Kidding.....',CR,LF,'$'     ;Print Error Message
  94. ;
  95. ;NOTE:    The above message gives the user no idea of what RUN does.
  96. ;
  97. START:    MVI    C,8        ;Move the filename into fcb
  98.     LXI    H,CPMFCB+1    ;location of filename
  99. ;
  100. ;NOTE:    Replace the operand "CPMFCB+1" in the above instruction with
  101. ;    "RUNFIL" if the internal name at the label RUNFIL is going to
  102. ;    be the target file.
  103. ;
  104.     LXI    D,FCB+1        ;destination
  105.     CALL    MOVE        ;8 bytes
  106. ;
  107.     MVI    C,11        ;Clear the primary CP/M FCB
  108.     LXI    H,CPMFCB+1    ;Destination
  109.     CALL    BLANKS        ;Put in blanks
  110.     MVI    C,11        ;Clear the secondary CP/M FCB
  111.     LXI    D,CP2FCB+1    ;Destination
  112.     CALL    BLANKS        ;Put in blanks
  113. ;
  114. ;       If you need to reset the default drive back to 'A' then
  115. ;    include the next three lines of code.
  116. ;
  117.     MVI    C,SELDRV    ;If necessary to locate BRUN, for example
  118.     MVI    E,00H        ;Set Default Drive back to A
  119.     CALL    BDOS        ;Set it
  120. ;
  121.     MVI    C,USER        ;set up area of the target file
  122.     MVI    E,DEFUSR    ;Desired user area
  123.     CALL    BDOS        ;do it
  124. ;
  125.     LHLD    BDOS+1        ;get BDOS entry address [ver201 fixes]
  126.     lxi    b,-6-2048    ;offset to start of ccp
  127.     dad    b        ;pointer to ccp in HL
  128.     LXI    B,-CODELN    ;Subtract length of code to be moved
  129.     DAD    B        ;To make room at top of TPA
  130.     SHLD    JMPR+1        ;Fill in jump address below
  131.     PUSH    H        ;Save relocated loader address
  132. ;
  133. ;    Code to cause loader to return to drive and user designated
  134. ;    by RETDRV and RETUSR per EQUates at top, in case loaded program
  135. ;    returns to CP/M without a warmboot.
  136. ;
  137.     XCHG
  138.     LXI    H,SETRET-LOADER ;Distance between start of loader
  139.                 ;..and RET jump address
  140.     DAD    D        ;Compute relocated address
  141.     SHLD    JMPRET+1    ;..and plant it in loader
  142.     POP    H        ;Recover relocated loader address
  143. ;
  144.     PUSH    H        ;Save code address for RET
  145.     XCHG            ;And use to calculate final location of FCB
  146.     LXI    H,FCB-LOADER    ;Distance between start of loader and FCB
  147.     DAD    D        ;Add address computed above
  148.     SHLD    FCBR+1        ;And put in LXI below for eventual file read
  149.     PUSH    H        ;Save FCB destination address
  150.     LXI    H,LOADER    ;Point to start of loader
  151.     MVI    C,CODELN    ;Length of loader
  152.     CALL    MOVE        ;Destination still in DE from above
  153.     POP    D        ;Recover FCB address (saved as push H above)
  154.     MVI    C,OPEN        ;
  155.     CALL    BDOS        ;Open file
  156.     INR    A        ;
  157.     JZ    ERROR        ;signal if error
  158.     LXI    H,100H        ;Point to start of TPA for set DMA below
  159.     RET            ;To address on stack which is start of loader
  160. ;
  161. LOADER:    PUSH    H        ;DMA address at start of TPA
  162.     XCHG            ;Put in DE for DMA set
  163.     MVI    C,SETDMA
  164.     CALL    BDOS        ;Set DMA address
  165. ;
  166. FCBR:    LXI    D,$-$        ;Address of moved FCB filled in earlier
  167.     MVI    C,READ        ;
  168.     CALL    BDOS        ;Read next record
  169.     ORA    A        ;Check for end of file
  170.     POP    H
  171. JMPRET: JNZ    $-$        ;EOF -> JMP to SETRET (address patched above)
  172.     LXI    D,128        ;....and bump DMA address
  173.     DAD    D
  174. ;
  175. JMPR:    JMP    $-$        ;jump to loader address filled in earlier
  176. ;
  177. ;    If the loaded program exits without a warmboot, the following
  178. ;    code will assure that we are not left in the user area that
  179. ;    the loaded program normally resides.
  180. ;
  181. SETRET: MVI    C,RDS        ;Reset disk system and restore default DMA
  182.     CALL    BDOS
  183.     MVI    C,SELDRV    ;Set default drive before return
  184.     MVI    E,RETDRV
  185.     CALL    BDOS
  186.     MVI    C,USER        ;Set default user before return
  187.     MVI    E,RETUSR
  188.     CALL    BDOS
  189.     JMP    100H        ;Go run the program in memory
  190. ;
  191. FCB:    DB    DEFDRV        ;drive code
  192.     DS    8        ;room for filename
  193.     DB    'COM'        ;File type
  194.     DB    0,0,0,0,0,0    ;Zero out remaining 24 bytes of FCB
  195.     DB    0,0,0,0,0,0
  196.     DB    0,0,0,0,0,0
  197.     DB    0,0,0,0,0,0
  198. ;
  199. CODELN: EQU    $-LOADER    ;computes size of loader code for move
  200. ;
  201. MOVE:    ; C= # Bytes,  HL= Source, DE= Destination
  202. ;
  203.     MOV    A,M
  204.     STAX    D
  205.     INX    H
  206.     INX    D
  207.     DCR    C
  208.     JNZ    MOVE
  209.     RET
  210. ;
  211. BLANKS: ; C= # blanks, HL = Destination
  212. ;
  213.     MVI    A,BLANK
  214.     MOV    M,A
  215.     INX    H
  216.     DCR    C
  217.     JNZ    BLANKS
  218.     RET
  219. ;
  220. ERROR:    LXI    D,ERRMSG
  221.     CALL    PRNMSG
  222.     JMP    0
  223. ;
  224. ;Write a string of characters to the CRT
  225. ;
  226. PRNMSG:    MVI    C,PRINTF
  227.     CALL    BDOS
  228.     RET
  229. ;
  230.     END
  231. ;
  232. S