home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / mslang / as / load.asm < prev   
Assembly Source File  |  1985-01-29  |  6KB  |  235 lines

  1. ;  LOAD.ASM - DKeels                        07/09/84
  2. ;----------------------------------------------------------------------------
  3. ;  This program is a driver for all processes within the application.  It
  4. ;  gets loaded by DOS, and then loads the program specified in the command
  5. ;  line and gives it control.  For example, if "LOAD MAINMENU.EXE" is entered
  6. ;  at the command line (or in a batch file), then DOS loads LOAD, and LOAD
  7. ;  loads MAINMENU.EXE.  When MAINMENU terminates, control is returned to LOAD,
  8. ;  who will then try to execute the first command in the SYSPARM parameter
  9. ;  block.  If the first command is null (1st byte=space) then it will try the
  10. ;  second command.  If the second command is null, then LOAD will terminate
  11. ;  and return control to DOS.  Commands can be placed in the SYSPARM parameter
  12. ;  block by application programs to effectively control program chaining, or
  13. ;  to execute a DOS command such as "COPY A: B:", and get control back when
  14. ;  finished.  (The returned-to program is reloaded from disk.)
  15. ;
  16. ;  Note that this program uses the SYSPARM parameter block via interrupt 77H.
  17. ;  SYSPARM, a resident process, must be executed before LOAD can operate.
  18. ;----------------------------------------------------------------------------
  19.  
  20.  
  21. CGROUP        GROUP STACK,DATA,CODE        ;all addressing based on CS
  22.  
  23. MEMORY_SIZE    EQU    80H            ;NOTE!!! value is dependent
  24.                         ;on size of LOAD, but only
  25.                         ;approximately.
  26.  
  27. STACK        SEGMENT STACK 'STACK'        ;----------------- stack
  28.         DB    16 DUP('dkstack ')
  29. TOP_OF_STACK    LABEL    BYTE
  30. STACK        ENDS
  31.  
  32.  
  33. DATA        SEGMENT                ;------------------- data
  34.  
  35. PARM_BLOCK    EQU    $
  36. ENV_ADDR    DW    0
  37. CMD_ADDR    DW    0,0
  38. FCB_ADDR1    DW    0,0
  39. FCB_ADDR2    DW    0,0
  40.  
  41. FILE_NAME    DB    80 DUP(' '),0
  42.  
  43. COMMAND_STRING    EQU    $
  44. COMMAND_LEN    DB    0
  45. COMMAND        DB    80 DUP(' ')
  46.         DB    13
  47.  
  48. ERROR_MSG    DB    '** LOAD ERROR **     CODE=$'
  49.  
  50. SAVE_ES        DW    ?
  51. SAVE_SS        DW    ?
  52. SAVE_SP        DW    ?
  53.  
  54. PARM_TBL_SEG_ADDR    DW    ?        ;address of system parameter
  55.  
  56. DATA        ENDS
  57.  
  58.  
  59. CODE        SEGMENT
  60. LOAD        PROC    FAR            ;--------------------- code
  61.         ASSUME    CS:CGROUP,DS:CGROUP,ES:CGROUP
  62.  
  63.     ;prologue
  64.         PUSH    CS        ;establish data addressability
  65.         POP    DS        ;DS -> data
  66.         MOV    SAVE_ES,ES    ;ES -> psp
  67.         MOV    SAVE_SS,SS    ;SS -> stack
  68.  
  69.     ;get file name to load from psp
  70.         PUSH    DS        ;swap DS/ES
  71.         PUSH    ES
  72.         POP    DS        ;DS -> psp
  73.         POP    ES        ;ES -> data
  74.         MOV    CL,BYTE PTR DS:[80H]    ;get psp command line length
  75.         MOV    CH,0        ;cx has length of psp command
  76.         MOV    SI,82H        ;source offset - psp command line
  77.         LEA    AX,FILE_NAME
  78.         MOV    DI,AX        ;destination offset
  79.         CLD
  80.         REP    MOVSB        ;move psp command line to file name
  81.         DEC    DI        ;backup one byte to carraige return
  82.         MOV    BYTE PTR ES:[DI],0    ;make it asciiz string
  83.  
  84.     ;modify allocated memory blocks to make room for new program(s)
  85.     ;  ES must have segment of block to modify
  86.     ;  BX must have new size of block in paragraphs
  87.         PUSH    ES        ;ES -> data
  88.         PUSH    DS        ;DS -> psp
  89.         POP    ES        ;ES -> psp
  90.  
  91.         MOV    BX,MEMORY_SIZE
  92.         MOV    AH,4AH
  93.         INT    21H        ;free memory
  94.         JC    ERROR
  95.         POP    ES        ;ES -> data
  96.         PUSH    ES        ;ES -> data
  97.         POP    DS        ;DS -> data
  98.  
  99.     ;get and save address of parameter table
  100.         MOV    DX,'dk'
  101.         INT    77H            ;get address of parameter tbl
  102.         MOV    PARM_TBL_SEG_ADDR,AX    ;save ax (tbl segment address)
  103.  
  104.     ;execution loop - repeat until no more commands, or error occurs
  105. EXEC:
  106.         CALL    EXEC_COMMAND    ;execute requested command
  107.         CALL    GET_NEXT_CMD    ;else prepare to execute next command
  108.         JMP    EXEC
  109.  
  110.  
  111. ;-------------- error routine
  112. ERROR:
  113.         POP    DS            ;DS -> data
  114.         LEA    DX,ERROR_MSG        ;display error message
  115.         MOV    AH,9
  116.         INT    21H
  117.         MOV    DX,AX            ;display DOS error code
  118.         ADD     DL,64            ;  as alpha character
  119.         MOV     AH,2
  120.         INT     21H
  121.         MOV     DL,0DH            ;carriage return
  122.         MOV     AH,2
  123.         INT     21H
  124.         MOV     DL,0AH            ;line feed
  125.         MOV     AH,2
  126.         INT     21H
  127.         MOV     AL,99            ;set errorlevel to 99
  128.         MOV     AH,4CH            ;terminate with error
  129.         INT     21H
  130.  
  131.  
  132. ;-------------- exit routine
  133. EXIT_LOAD:
  134.         MOV     AL,0            ;set error level to 0
  135.         MOV     AH,4CH            ;terminate without error
  136.         INT     21H
  137.  
  138.  
  139. LOAD     ENDP
  140.  
  141.  
  142. ;---------------------------------------------------------------------------
  143. ;call DOS EXEC function
  144. ;---------------------------------------------------------------------------
  145.  
  146. EXEC_COMMAND    PROC
  147.  
  148.     ;point DS:DX to name of file to load and execute
  149.              LEA     DX,FILE_NAME
  150.  
  151.     ;point cmd_addr in parmblok to COMMAND_STRING
  152.         MOV    AX,ES
  153.         MOV    CMD_ADDR+2,AX
  154.         LEA    AX,COMMAND_STRING
  155.         MOV    CMD_ADDR,AX
  156.  
  157.     ;point ES:BX to parameter list.
  158.         LEA    BX,PARM_BLOCK
  159.  
  160.     ;save stack pointer (should be top minus 3 words)
  161.         MOV    SAVE_SP,SP
  162.  
  163.     ;here we go
  164.         MOV     AH,4BH        ;EXEC function call
  165.         MOV    AL,0        ;load and execute function
  166.         INT    21H
  167.  
  168.     ;return from call
  169. ;        MOV    AH,4DH        ;get completion code
  170. ;        INT    21H
  171. ;        CMP    AH,0        ;ah is zero for normal completion
  172. ;        JNE    EXIT_LOAD    ;if not zero, error in loaded program
  173.  
  174.         MOV    AX,CS        ;restore segment registers
  175.         MOV    DS,AX        ;DS -> data
  176.         MOV    ES,AX        ;ES -> data
  177.         MOV    SS,SAVE_SS
  178.         MOV    SP,SAVE_SP
  179.  
  180.         RET
  181.  
  182. EXEC_COMMAND    ENDP
  183.  
  184.  
  185. ;---------------------------------------------------------------------------
  186. ;get next command to execute
  187. ;---------------------------------------------------------------------------
  188.  
  189. GET_NEXT_CMD    PROC
  190.  
  191.         PUSH    DS
  192.         MOV    AX,ES:PARM_TBL_SEG_ADDR    ;address system parm table
  193.         MOV    DS,AX            ;DS -> system parm table
  194.         MOV    AL,BYTE PTR DS:[0]    ;get 1st byte of 1st file name
  195.         CMP    AL,' '            ;if space, assume no name,
  196.         JE    SEC_COMMAND        ;  try second file name
  197.  
  198.         MOV    SI,0            ;move file name into position
  199.         LEA    DI,FILE_NAME
  200.         MOV    CX,81
  201.         CLD
  202.         REP    MOVSB
  203.         LEA    DI,COMMAND_STRING    ;move command line parameters
  204.         MOV    CX,82
  205.         REP    MOVSB
  206.  
  207.         MOV    BYTE PTR DS:[0],' '    ;render 1st file name useless
  208.  
  209.         JMP    GET_NEXT_RET        ;return
  210.  
  211. SEC_COMMAND:
  212.         MOV    AL,BYTE PTR DS:[163]    ;get 1st byte of 2nd file name
  213.         CMP    AL,' '            ;if space, assume no name,
  214.         JE    EXIT_LOAD        ;then quit
  215.         MOV    SI,163            ;move file name into position
  216.         LEA    DI,FILE_NAME
  217.         MOV    CX,81
  218.         CLD
  219.         REP    MOVSB
  220.         MOV    SI,244            ;move command line parameters
  221.         LEA    DI,COMMAND_STRING
  222.         MOV    CX,82
  223.         REP    MOVSB
  224.  
  225.         MOV    BYTE PTR DS:[163],' '    ;render 2nd file name useless
  226.  
  227. GET_NEXT_RET:
  228.         POP    DS
  229.         RET
  230.  
  231. GET_NEXT_CMD    ENDP
  232.  
  233. CODE     ENDS
  234.          END     LOAD
  235.