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

LOADSEG    EQU 8000h

start:          jmp     main

;
include \nxdos\src\toolbox.asm
include \nxdos\src\crclib.asm
;
include \nxdos\src\kernel\dma.asm
include \nxdos\src\kernel\filesys.asm
;

commandline     db 'COMMAND.COM',0
errorlevel      db 0
main:
         ; load filesystem handlers and system device drivers
         mov  dl, 0
         call diskopen
         jnc  mounted
mounterror:
         _print filesysnotmounted, 1
         ret
mounted:
         lea  di, commandline   ; try current path
bootfile:
         call FS_SEARCH
         jc   load_file_error

         ; clear PSP memory

         mov  ax, FCB_Cluster
         call putnum

         mov  bx, LOADSEG
         push bx
         pop  es
         mov  bx, 0100h
         call loadimage
         jc   load_file_error
         ;
         mov  ax, cx
         call putnum
         _newline
         push ds
         mov  bx, LOADSEG
         mov  ds, bx
         mov  bx, 0100h
         mov  si, bx
         mov  cx, 15958    ; command.com size
         call crc16
         mov  ax, dx
         call put_hex
         _newline
         pop  ds
         ;
         mov  bx, LOADSEG
         mov  es, bx
         mov  bx, 0200h
         mov  si, bx
         mov  cx, 128
         call debugdump
         ;
run_file:
         push cs
         push offset lf_ret
         mov  bx, LOADSEG
         push bx
         mov  bx, 0100h
         push bx
         retf
lf_ret   db   90h
         mov  errorlevel, al
         jmp  kernelprompt
load_file_error:
         ; the endless loop, we are at a form of command prompt
         _print badormissingci, 1
         mov  ah, 1
         mov  errorlevel, al
kernelprompt:
;'
;'          _newline
;                push cs
;                pop  es
;                lea  si, filename
;                mov  cx, 128
;                call cs:debugdump

exit: ;          call dosexit
                int 20h      
badormissingci    db 'Bad or missing.',0ffh,0
filesysnotmounted db 'Not mounted.',0ffh,0
testprog        endp
;slen            dw ?
;sbuf            db 255 dup(0),0
;filename        db 'user.dat',0
;_filemissing    db 'Missing.',0
;handle          dw ?


code            ends

ProgramEnd      EQU $-01h

        	end	start
