; Copyright Christopher Evans
; email:   teknopup@lycos.com
; Website: http://nxdos.sourceforge.net/
;                                                                           ;
;       This program is copyrighted, but may be freely distributed          ;
;       under the terms of the Free Software Foundation's GNU General       ;
;       Public License v2 (or later.)  See the file COPYING for the         ;
;       legalities.  If you did not receive a copy of COPYING, you          ;
;       may request one from the Free Software Foundation, Inc.,            ;
;       59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           ;
;       ABSOLUTELY NO WARRANTY -- use it at your own risk!                  ;
;                                                                           ;

.286c
.287

code            segment byte public
                assume  cs:code, ds:code
		org	100h
nxdos             proc    far

ProgramStart EQU $

start:          jmp     initialize
include         \nxdos\src\kernel\nxdos.equ
include         \nxdos\src\toolbox.asm
initialize:
     push cs
     pop  es
     mov  bx, (((Programend)+16)/16)
     call memresize
     jc   frerr8
           call cs:main
     jc   exitptr
frerr8:
     _print enuff_mem, 1
     mov  ax, 8               
exitptr:
     call dosexit
     int 20h

_run macro _rprog
     push ds
     pop  es
     lea  dx, _rprog
     lea  bx, pspexec
     call spawn
     endm

; ===========================================================================
loadshell proc far
; ===========================================================================
          _fileexist nxdos_sem
          jnc  lfreewin
          _fileexist nxbio_com
          jnc  lfreewin 

          push ds
          pop  es
          lea  dx, nxbio_com
          lea  bx, pspexec
          call spawn
          jnc  ls_ne

lfreewin:
          _fileexist frnxdos_exe
          jnc  loadlist 
          push ds
          pop  es
          lea  dx, frnxdos_exe
          lea  bx, pspexec
          call spawn
          jnc  ls_ne
          ;

loadlist:
          _fileexist list_com
          jnc  loadcommand 
          push ds
          pop  es
          lea  dx, list_com
          lea  bx, pspexec
          call spawn
          jnc  ls_ne
loadcommand:
          _fileexist command_com
          jnc  loadcmd 
          push ds
          pop  es
          lea  dx, command_com
          lea  bx, pspexec
          call spawn
          jnc  ls_ne
loadcmd:
          push ds
          pop  es
          lea  dx, cmd_com
          lea  bx, pspexec
          call spawn
          jnc  ls_ne
ls_e1:
          stc
          mov  ax, 2
          ret
ls_ne:
          clc
          ret
loadshell endp

; ===========================================================================
main proc far
; ===========================================================================
     xor  ax, ax
     mov  ah, 01h
     call videomode
     xor  ax, ax
     mov  al, 03h
     call videomode
     ;
     call checkcpu
     call putnum
     _echo '8'
     _echo '6'
     _echo ' '
     call detect_os
     osname
     _newline
     call show_videohardware
     _newline

;     _run ms_com
;     _run drvtype_exe

     _print loadnx, 1
     _readkey
     cmp  al, 'Y'
     je   m_load
     cmp  al, 'y'
     je   m_load
m_nload:
     _newline 
     _print userabort, 1
     mov  ax, 1
     jmp  _m_ls_n
m_load:
     ;
     call cs:loadshell
     jnc  _m_ls_ok
frerr:
     _print cannotload, 1
     call pauseprompt
     mov  ax, 2
_m_ls_n:
     stc
     jmp _m_lsx
_m_ls_ok:
     clc
_m_lsx:
     ret
main endp


altintr     db '[W#001] Loading alternative...',0ffh,0
cannotload  db '[E#002] Cannot load free windows.',0ffh,0
userabort   db '[W#001] User abort.',0ffh,0
enuff_mem   db '[E#008] Out of memory!',0ffh,0
loadnx      db 'Load NX? [y/N]',0

nxdos_sem   db '\nxdos.smf',0,24,0
command_com db '\nxdos\src\utils\command\command.com',0,24h,0
nxbio_sys   db '\nxdos\src\kernel\nxbio.sys',0,24h,0
nxbio_com   db '\nxdos\src\kernel\nxbio.com',0,24h,0
frnxdos_exe db '\nxdos\src\utils\frw.exe',0,24h,0
list_com    db '\UTILS\LIST.COM',0,24h,0
cmd_com     db '\COMMAND.COM',0,24h,0
ms_com      db '\utils\ms.com',0,24h,0
drvtype_exe db '\UTILS\DRVTYPE.EXE',0,24h,0

commandline db ' ',0,24h,0

include     \nxdos\src\docs\copy.txt

pspexec     db 14 dup(0)

nxdos             endp

code            ends

ProgramEnd      EQU $-01h

		end	start
