;        include \nxdos\src\kernel\taskmgr\taskmgr.asm

parse_command proc far
; ... parse and run command ...
       lea  si, _buffer
       mov  bl, 20h
       mov  cx, 0ffh
       call upstr
       clc
_chkrestart:
       lea  si, _RESTART    
       lea  di, _buffer
       mov  cx, 255
       mov  dh, ' '
       mov  dl, 0ah
       call compare
       or   bx, bx
       jnz  _chkcls 
            call reset
            call reboot
       jmp  _processed
_chkcls:
       lea  si, _CLS    
       lea  di, _buffer
       mov  cx, 255
       mov  dh, ' '
       mov  dl, 0ah
       call compare
       or   bx, bx
       jnz  _chkver 
            mov  ax, 07h
            call textcolor
            call clrscr
       jmp  _processed
_chkver:
       lea  si, _VER    
       lea  di, _buffer
       mov  cx, 255
       mov  dh, ' '
       mov  dl, 0ah
       call compare
       or   bx, bx
       jnz  _chkmemwalk
            call cs:about
       jmp  _processed
_chkmemwalk:
       lea  si, _MEMWALK 
       lea  di, _buffer
       mov  cx, 255
       mov  dh, ' '
       mov  dl, 0ah
       call compare
       or   bx, bx
       jnz  _chkhelp
            call memwalk
       jmp  _processed
_chkhelp:
       lea  si, _HELP    
       lea  di, _buffer
       mov  cx, 255
       mov  dh, ' '
       mov  dl, 0ah
       call compare
       or   bx, bx
       jnz  _chknext
            _display cs:KERNELHELP, 0
       jmp  _processed
; did not find a command AL = 0
_chknext:
       xor  ax, ax
       jmp short pc_x
; Found a command AL = 1
_processed:
       mov  ax, 1
pc_x:
       ret
parse_command endp

; ===========================================================================
userprompt proc far
; ===========================================================================
      _print cs:bootprompt, 1
      lea  di, _buffer
      mov  cx, 127
      call getdata
      mov  cs:ui_size, cx
      _newline
      cmp  cx, 0
      je   getaclue
      call cs:parse_command
      or   ax, ax
      jnz  _ui_x
ui_chk_size:
      mov  ax, cs:ui_size
      or   ax, ax
      jz   _ui_x
ui_run_prog:

IFDEF (FILESYS)
      lea  di, _buffer
      call cs:FS_RUN
ELSE

      stc
ENDIF
      jnc  _ui_x

nodataentered:
      _print cs:ErrMsg0011, 1

getaclue:
      ;
      ; _display cs:HELP_HINT, 1
      ;
_ui_x:
      mov  ax, cs:sleep

      ret
ui_size dw 0
userprompt endp

; ===========================================================================
user proc far
; ===========================================================================
user_int:
      call userprompt
      or   ax, ax
      jz   user_int
      ret
user endp

eventchk proc far
              mov  ax, cs:event
              cmp  ax, 1
              je   short tske1
              cmp  ax, 2
              je   short tske2
              cmp  ax, 3
              je   short tske3
              cmp  ax, 4
              je   short tske4
              jmp  short tskother
tske1:        ; Time to expire

              jmp  short tskex
tske2:        ; Signal from an ISR

              jmp  short tskex
tske3:        ; Message from another task

              jmp  short tskex
tske4:        ; 

              jmp  short tskex
tskother:

              jmp  short tskex
tskex:
         ret
eventchk endp

; ===========================================================================
task0 proc far
; ===========================================================================
; while (1) {
task0_l:
      ; while (!sleep) {
task0_s:
              call eventchk
              call user
              ;
              ; if sleep mode then sleep = 1
              ;
              mov  ax, cs:sleep
              or   ax, ax
              jz   short task0_s
      ; }
      ; if wakeup then sleep = 0
      jmp short task0_l
; }
      ret
task0 endp

; ===========================================================================
console proc far
; ===========================================================================
     ;mov  al, cs:runlevel
     ;cmp  al, MULTI_USERG
     ;jne  short bootshell
     ; if (vga) {

     ; } else {

IFDEF (FILESYS)
     lea  di, TESTFILE
     call fs_run
ELSE
     stc
ENDIF
     jc   badcommand
IFDEF (FILESYS)
          lea  di, commandcom ; lea  di, commandcom2
          ; inc  di
          call fs_run
ELSE
          stc
ENDIF
          jc  bootshell
          nop
     jmp  short consolex
bootshell:
     call task0
     jmp  short consolex
     ; }
badcommand:
     _print ErrMsg0011, 1
consolex:
     ret
console endp
