; ===========================================================================
exit proc far
; Input : AL = ERRORLEVEL
; ===========================================================================
         push cs
         pop  ds
         push cs
         pop  es
         call debugregisters
         _newline
         _print systemhalted, 1
         _newline
         _readkey
         call reset
         call reboot
         call dosexit
         ret
exit endp

; ===========================================================================
detecthardware proc far
; ===========================================================================

         int  11
         mov  cl, 6
         shr  al, cl
         inc  al
         mov  byte ptr [floppynum], al
         xor  ax, ax
         xor  cx, cx

         call checkcpu
         mov  cputype, al

         mov  bx, MEMSTRATEGY
         call MINIT

         call is_pcibios
         mov  pcibus, al

         xor ax, ax
         ;  call detect_adlib
         mov  adlib, al

         mov  ah, 1
         call videomode                 ; call cs:detectvideohardware

         call Init_NE2000
         jc   no_ne2000
         mov  al, 1
         mov  ne2000card, al
no_ne2000:
         mov  ax, 300h
         xor  bx, bx
         mov  bl, 3
         call detect_3c501
         jnc  no_3com
         ; ... indicated by port/irq variables in 3c50x.asm
no_3com:

         ; call cs:enumerate_pcidevices

         ret
detecthardware endp

; ===========================================================================
show_hardware proc far
; ===========================================================================
           xor  ax, ax
           mov  al, cputype
           call putnum
           _echo '8'
           _echo '6'
           _Echo ' '
           mov  ax, memorypool
           call putnum
           _echo 'K'
           _echo 'B'
           _echo ' '
           mov  al, pcibus
           or   al, al
           jnz  _sh_pci
           _print ISA, 1
           jmp  _sh_x
_sh_pci:   _print PCi, 1
           _spaces 1
           mov ax, PCIVERSION
           call wrdec
_sh_x:     _spaces 1
           mov  al, adlib
           or   al, al
           jz   _sh_nadlib
           _print adlibfound, 1
_sh_nadlib:
           _echo ' '
           mov  al, ne2000card
           or   al, al
           jz   _sh_nne2000
           _print ne2000found, 1
           _echo ' '
           _echo '@'
           _echo ' '
           mov  ax, cs:NE2000BASE
           call put_hex
           _echo 'H'
_sh_nne2000:
           mov  ax, _3cBASE
           cmp  ax, 0 
           je   _sh_n3c50x  
           _print _3comfound, 1
_sh_n3c50x:
           _echo ' '
           ret
show_hardware endp

projver    db 'Project version ',0

; ===========================================================================
showversion proc far
; ===========================================================================
          _newline
          _print logo, 1
          _print copyright, 1
          _echo ' '
          mov  ax, projectversion
          call wrdec
          _spaces 1
          mov ax, dosversion
          call wrdec
          _echo '.'
          mov    ah, 0
          mov    al, revision
          call   cs:putnum
          _spaces 1
          mov   ax, setver
          call wrdec
          _spaces 1
          _print timestamp, 1
          _newline
          _print copyright2, 1
          _newline
          _print GPL, 1
          _print GPL2, 1
          _newline
          call cs:show_hardware
          call cs:show_videohardware
          _newline
            ret
showversion endp

_DaysSinceEpoche   dw 0                           ; uptime

; ===========================================================================
read_rtc proc far
; ===========================================================================
         mov     ah,0
         int     1ah
         ; _DaysSinceEpoch   ; update days if necessary
         ; (ah is still 0, al contains midnight flag)
         ;   *some* BIOS's accumulate several days
         add     word [_DaysSinceEpoche],ax
         adc     word [_DaysSinceEpoche+2],0     ;
         ; set return value dx:ax
         xchg    ax,cx                   ; ax=_cx, cx=_ax
         xchg    ax,dx                   ; dx=_cx, ax=_dx (cx=_ax)
         ret
read_rtc endp

; ===========================================================================
WriteATClock proc far
;       BYTE *bcdDays;
;       BYTE bcdHours;
;       BYTE bcdMinutes;
;       BYTE bcdSeconds;
; ===========================================================================
                push    bp
                mov     bp,sp
;               bcdSeconds = 4
;               bcdMinutes = 6
;               bcdHours = 8
;               bcdDays = 10
                mov     ch,byte [bp+8]      ;bcdHours
                mov     cl,byte [bp+6]      ;bcdMinutes
                mov     dh,byte [bp+4]      ;bcdSeconds
                mov     dl,0
                mov     ah,3
                int     1ah
                mov     bx,word [bp+10]     ;bcdDays
                mov     dx,word [bx]
                mov     cx,word [bx+2]
                mov     ah,5
                int     1ah
                pop     bp
                ret     8
         ret
WriteATClock endp

; ===========================================================================
WritePCClock proc far
;       ULONG Ticks;
;               Ticks = 4
; ===========================================================================
		pop	ax			; return address
		pop	dx
		pop	cx			; Ticks
		push	ax			; restore stack
                mov     ah,1
                int     1ah
                ret
WritePCClock endp

cputype         db 0
adlib           db 0
PCi             db 'PCI',0
ISA             db 'ISA',0
adlibfound      db 'ADLIB',0
SYSTEMHALTED    db 'SYSTEM HALTED',0
;

startmsg        db 0ffh,'Starting...',0ffh,0

logo            db 'ÚÄÄÄ  ÚÄÄ ÚÄÄ   ÚÄÄ ÚÄÄÄÄÄÄÄ   ÚÄÄÄÄÄÄ   ÚÄÄÄÄÄÄ NeXt-DOS.System/3 ',0ffh
                db 'ÚÄÄÚÄ ÚÄÄ  ÚÄÄ ÚÄÄ  ÚÄÄ   ÚÄÄ ÚÄÄ   ÚÄÄ ÚÄÄ       .______|_.|||| | ',0ffh                    
                db 'ÚÄÄ ÚÄÚÄÄ   ÚÄÄÄÄ   ÚÄÄ   ÚÄÄ ÚÄÄ   ÚÄÄ  ÚÄÄÄÄÄÄ  |  ||||  |  O  | ',0ffh      
                db 'ÚÄÄ  ÚÄÄÄ  ÚÄÄ ÚÄÄ  ÚÄÄ   ÚÄÄ ÚÄÄ   ÚÄÄ       ÚÄÄ |    O   |_____. ',0ffh   
                db 'ÚÄÄ   ÚÄÄ ÚÄÄ   ÚÄÄ ÚÄÄÄÄÄÄÄ   ÚÄÄÄÄÄÄ   ÚÄÄÄÄÄÄ  .________.       ',0ffh,0   
;
copyright       db 'Embedded Real-Time Operating System Project',0
;
copyright2      db '       (C)Copyright 2004-2006 Christopher Robert Evans, Ltd.',0ffh,0
;
GPL             db 'This program is distributed in the hope that it will be useful,',0ffh
                db 'but WITHOUT ANY WARRANTY; without even the implied warranty of',0ffh
                db 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the',0ffh
                db 'Public License for more details.',0ffh,0ffh,0

GPL2            db 'You should have received a copy of the General Public License',0ffh
                db 'along with this program; if not, write to the',0ffh
                db 'tekno1911@yahoo.com, or call 1-916-501-1423.',0ffh,0ffh
                db 'NX-DOS is distributed under terms of GPL and is free except for',0ffh
                db 'inclusion in commercial embedded systems. If you are a commercial',0ffh
                db 'user then please contact me to buy a license.',0ffh,0
