home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / LOADER.ASM < prev    next >
Assembly Source File  |  1992-08-16  |  7KB  |  246 lines

  1. .MODEL TINY
  2.  
  3.  
  4.  
  5. .CODE
  6.         org     100h
  7.  
  8.  
  9. start:
  10.         jmp     start1
  11.  
  12.  
  13.  
  14. flag    db      0                       ; set to 1 if rerun BBS
  15. prog_name:                              ; store secondary program to run
  16.         db      81 dup (0)
  17.  
  18. bbs_name:                               ; name of the BBS executable
  19.         db      'BBS.EXE',0
  20.  
  21. path_ptr:
  22.         dw      0                       ; pointer into pathname
  23.  
  24. bbs_path:                               ; full pathname of BBS executable
  25.         db      'A:\'
  26.         db      81 dup (0)
  27.  
  28.  
  29. ;
  30. ; Set up stack and release extra memory
  31. ;
  32.  
  33. start1:
  34.         mov     ax,cs
  35.         mov     ss,ax
  36.         mov     sp,OFFSET stack_top     ; set the stack
  37.  
  38.         mov     es,ax
  39.         mov     bx,OFFSET stack_top     ; last byte used
  40.         mov     cl,4
  41.         shr     bx,cl                   ; get paragraph count
  42.         add     bx,1                    ; add 1 for luck
  43.         mov     ah,4ah                  ; func 4AH = SETBLOCK
  44.         int     21h                     ; give back most of memory to DOS
  45.  
  46. ;
  47. ; Make all our segments equal to CS
  48. ;
  49.         push    cs
  50.         push    cs
  51.         pop     ds
  52.         pop     es
  53.  
  54.  
  55. ;
  56. ; Set up full pathname of bbs
  57. ;
  58.  
  59.         mov     ah,19h                  ; get current disk
  60.         int     21h
  61.  
  62.         add     byte ptr[bbs_path],al   ; set current disk in path
  63.         mov     ah,47h                  ; Get current directory
  64.         mov     dl,0                    ; current disk
  65.         mov     si,OFFSET bbs_path
  66.         add     si,3                    ; skip "X:\"
  67.         int     21h                     ; get pathname
  68.  
  69.         mov     di,OFFSET bbs_path
  70.  
  71. loop1:                                  ; search for end of pathname
  72.         inc     di
  73.         cmp     byte ptr [di],0
  74.         jne     loop1                   ; find end of path
  75.  
  76.         mov     ah,[di - 1]             ; see if there is a backslash on end
  77.         cmp     ah,'\'
  78.         je      yes
  79.  
  80.         mov     byte ptr[di],'\'        ; add a backslash
  81.         mov     word ptr[path_ptr],di   ; store pointer to backslash
  82.         inc     di
  83.  
  84. yes:
  85.  
  86.         mov     si,OFFSET bbs_name      ; point to BBS.EXE
  87.  
  88. loop2:
  89.         mov     ah,[si]                 ; copy over a char
  90.         mov     [di],ah
  91.         inc     si
  92.         inc     di
  93.         cmp     ah,0                    ; at the end of it?
  94.         jne     loop2
  95.  
  96.         push    cs
  97.         pop     ax
  98.         mov     word ptr [parm_block+4],ax ; Set CS in parm_block
  99.  
  100. ;
  101. ; Run the BBS
  102. ;
  103.  
  104. exec_bbs:
  105.         push    cs                      ; set all the segments to CS again
  106.         push    cs
  107.         pop     ds
  108.         pop     es
  109.  
  110.         mov     byte ptr [flag],0       ; clear flag
  111.  
  112. ;
  113. ; Add on the argument "/Xssss:oooo" where ssss:oooo points to "flag"
  114. ;
  115.  
  116.         mov     si,80h
  117.         mov     al,byte ptr[si]         ; get length of BBS.EXE arguments
  118.         mov     ah,0
  119.         mov     di,81h
  120.         add     di,ax                   ; point di to end of BBS.EXE args
  121.  
  122.         mov     byte ptr[di],' '        ; add on " /X"
  123.         inc     di
  124.         mov     byte ptr[di],'/'
  125.         inc     di
  126.         mov     byte ptr[di],'X'
  127.         inc     di
  128.  
  129.         push    cs                      ; convert CS to hex
  130.         pop     bx
  131.         call    hex_cnv
  132.  
  133.         mov     byte ptr[di],':'        ; add in ":"
  134.         inc     di
  135.  
  136.         mov     bx,OFFSET flag          ; convert offset of flag into nex
  137.         call    hex_cnv
  138.  
  139.         mov     byte ptr[di],0          ; null terminate args
  140.         sub     di,81h
  141.         mov     ax,di
  142.         mov     byte ptr[si],al         ; store length
  143.  
  144.  
  145. ;
  146. ; Set the default drive and path correctly
  147. ;
  148.  
  149.         mov     dl,byte ptr[bbs_path]   ; get disk
  150.         sub     dl,'A'
  151.         mov     ax,0e00h                ; select disk
  152.         int     21h
  153.  
  154.         mov     di,word ptr[path_ptr]   ; point to backslash
  155.         mov     byte ptr[di],0          ; null terminate path
  156.         mov     dx,OFFSET bbs_path
  157.         add     dx,2                    ; point to backslash for full path
  158.         mov     ax,3b00h                ; chdir
  159.         int     21h
  160.  
  161.         mov     di,word ptr[path_ptr]
  162.         mov     byte ptr[di],'\'        ; add back backslash
  163. ;
  164. ; Actually run the BBS
  165. ;
  166.  
  167.         mov     dx,OFFSET bbs_path
  168.         mov     bx,OFFSET parm_block
  169.         mov     ax,4b00h
  170.         int     21h                     ; run the BBS
  171.  
  172.  
  173.         push    cs                      ; reset args after spawn call
  174.         push    cs
  175.         pop     ds
  176.         pop     es
  177.  
  178.         cmp     byte ptr [flag],0       ; see if we're done
  179.         je      terminate               ; yep, exit
  180.  
  181. ;
  182. ; Now run the secondary program, and then re-run the BBS
  183. ;
  184.  
  185.         mov     dx,OFFSET prog_name     ; get program name offset
  186.         mov     bx,OFFSET parm_block    ; get offset of parm block
  187.         mov     ax,4b00h                ; fun 4b00 is exec
  188.         int     21h                     ; run the secondary program
  189.  
  190.         mov     di,80h
  191.         mov     byte ptr cs:[di],0      ; clear the arguments
  192.         jmp     exec_bbs                ; rerun the BBS
  193.  
  194.  
  195. ;
  196. ; Convert bx to a hex ASCII string, store in di and increment di to end
  197. ;
  198.  
  199.  
  200. hex_cnv:
  201.         mov     dx,4                    ; number of hex digits
  202.         mov     cl,4                    ; number of bits in hex digit
  203.  
  204. loop_cnv:
  205.         mov     al,bh                   ; get the high order byte
  206.         shr     al,cl                   ; get high nybble in low nybble of al
  207.         cmp     al,0ah
  208.         jl      hex_num                 ; in the range 0..9
  209.         sub     al,0ah                  ; in range A..F
  210.         add     al,'A'
  211.         jmp     hex_pt
  212.  
  213. hex_num:
  214.         add     al,'0'
  215.  
  216. hex_pt:
  217.         mov     byte ptr[di],al         ; store the char
  218.         inc     di                      ; point to next location
  219.         shl     bx,cl                   ; rip off nybble we converted
  220.         dec     dx                      ; one less to go
  221.         jnz     loop_cnv                ; done?
  222.         ret
  223.  
  224. terminate:
  225.         mov     ah,4dh
  226.         int     21h                     ; get return code
  227.         mov     ah,4ch                  ; terminate
  228.         int     21h
  229.  
  230. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  231.  
  232. parm_block      dw      0               ; environment
  233.                 dw      80h             ; CMD line offset
  234.                 dw      0               ; CMD line seg, set to CS
  235.                 dd      0               ; who cares about the FCB's?
  236.                 dd      0
  237.  
  238.  
  239.  
  240.  
  241. stack_bottom    db 128 dup (0)
  242. stack_top:
  243.  
  244. END start
  245.  
  246.