Re: Returned Exit Code

Area:    Quik_Bas
  Msg:    #362
 Date:    12-19-92 21:47 (Public) 
 From:    Rob McKee                
 To:      Peter Barney             
 Subject: Re: Returned Exit Code   
 >  my ERLV.COM debug source
 >  debug <erlv.src
 >  -----------------------8<-----------------------------
 >  a      ; v----  change this to reflect your system
 >  MOV AX,054B   ; Hard coded for my system.  &h2b3 after the start of
 >  PUSH    DS    ; first listed from "mem /d"

 PB> Wouldn't you want to use the SECOND  If not, 
 PB> couldn't you just look at the PSP's Parent_Id (word at 
 PB> offset 16h) to tell you where the original is located?

 >   I want to be able to read the list of list and have the program
 > automatically go to the right byte and get it on any Dos 5 computer,
 > though...

 PB> What is the list of lists?

 DOS keeps a masterlist of the start of many things like Memory control 
blocks MCB, pointers to device drivers, etc...  MCB are 
better suited for finding COMMAND than PSP.  a MCB preceeds 
each PSP and it easier to step through them.  The following 
is the New and better ERLV.COM which runs on any Dos 5 w/ 
COMMAND.COM platform.  I've tested it on a 286/20, IBM XT, 
Zenith 150, and a 486-DX2.  It works inside batch files, it 
works outside. it works shelled even..  Although it does 
return the Errorlevel given by the previos program.  The 
parent hasn't exited yet so no errorlevel from them yet.  
It works when shelled into with or without a 
batch file.  Supports redirection even... into a file  '>', 
 not out off one '<'.  Some one with MASM experiance should 
be able to modify the code so it could be a Obj.. then a 
Lib function.
 Erlv.a86 used by A86.COM the shareware Assembler.
 ORG 0100
     jmp main
     Cur_Blk DW ?
     MCB_Seg dw ?
     Last_CMD dw ?
     Next_MCB dw ?
     out_100 db 0
     out_10  db 0
     out_1   db 0
     out_str db 0d,0a,024
     ErrorLevel db 00
     NotDos5msg db 'This Program Only runs with'
     ContNotDos5 db ' Dos5 and COMMAND.COM',0d,0a,024
     OopsMsg db 'This Program Has problems',0d,0a,024
     push ds
     push ds
     push ds
     push ds
     push ds
     mov ah,030
     int 33
     cmp ax,5
     je isDos5
     mov dx,offset NotDos5msg
     Call outstr
     jmp exit0
     mov dx,offset OopsMsg
     call outStr
     jmp exit0
     mov ah,9
     int 33
     mov ax,04c00
     int 33
     ; Get list of lists
     mov ah,052
     int 33    ; int 021xh
     ; es:bx-2 has list of lists
     dec bx
     dec bx
     mov si,bx
     mov ax,[si]    ; save a copy of MCB segment
     mov MCB_Seg,ax
     mov ds,ax
     mov cs:Cur_blk,ax
     mov ds:ah,[0]      ; get first byte of MCB
     mov bx,ds          ; Start of block
     add bx,w[3]        ; add Size of Block controled by MCB
     add bx,1           ; add 1 to give start of next MCB
     cmp ah,05a         ; Last one??
     je Chk_Lst_CMD     ; If yes then go do it.
     cmp ah,04d         ; if it's  a &h4d then it's a MCB
     je isMCB
     jmp Oops        ; looks like we're in lala land EXIT! EXIT!

     pop ds           ; lets get the data segment right!
     push ds
     mov Next_MCB,bx  ; Save the start of next MCB
     mov ax,Cur_blk   ; Restore Cur_Blk
     mov es,ax        ; setup Aux segment register
     es:              ; use it.
     cmp byte [8],043        ; I could have done this differently but hey!
     jne getNextMCB          ; the program is still less than 1 sector...
     cmp byte [9],04f      ; does it say 'COMMAND'
     jne getNextMCB
     cmp byte [10],04d
     jne getNextMCB
     cmp byte [11],04d
     jne getNextMCB
     cmp byte [12],041
     jne getNextMCB
     cmp byte [13],04e
     jne getNextMCB
     cmp byte [14],044
     jne getNextMCB
     mov ax,Cur_Blk    ; Yep, it says 'COMMAND' what the segement again?
     mov Last_CMD,ax   ; save it
 GetNextMCB:           ; check the next MCB for 'COMMAND'
     mov ax,Next_MCB
     jmp MCB_Next
     push cs
     pop ds
     mov ax,Last_CMD    ; Check to see if we found one.
     cmp ax,0
     jg  AddCur         ; If yes do it to it.
     jmp long Exit0
     mov ax,Last_CMD    ; get the last cmd segemnt again
     add ax,02b         ; add the offset
     mov es,ax
     es:                ; use it
     mov al,b[3]        ; get the Errorlevel
     ds:                ; restore the data segemnt
     mov byte ErrorLevel,al      ; save it
     push cs
     pop ds
     MOV CL,030                  ; setup for addition
     CMP AL,00                   ; Is the Errorlevel 0
     JZ  JMP2                    ; if it is don't divide jump to the adding
     XOR AH,AH
     MOV BX,000A        ; divide by 10
     DIV BL
     MOV Out_1,AH       ; remainder is the 1's digit
     XOR AH,AH          ; zero out ah
     DIV BL             ; divide again
     MOV Out_10,AH      ; move the 10's digit
     MOV Out_100,AL     ; all thats left is the 100's digit
      ADD Out_1,CL      ; make the remainders ASCII
      ADD Out_10,CL
      ADD Out_100,CL
      MOV DX,Offset Out_100       ; setup the offset to string
     Call OutStr                  ; display it
      MOV AL,ErrorLevel           ; restore Errorlevel
      MOV AH,04c                  ; so when we exit the IF ERRORLEVEL x
      INT 021                     ; in the Batch file will work

--- EZPoint V2.2
 * Origin: Flyer Proof Computer Services (1:125/1212.13)

Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET