; ===========================================================================
mswrite proc far
; DS:DX = DOS STRING terminated with $
; while ((c = *bp++) != '$') writecharstdout(c)
; ===========================================================================
           mov  si, dx
           mov   bl,7
           mov   ah,0Eh
           cld
msdoswrite:
           lodsb
           cmp   al,24h     
           je    mswritex 
           int   10h
           jmp   short msdoswrite
mswritex:
           ret
mswrite endp

_mswrite macro _mswobj
     mov  dx, _mswobj
     call mswrite
     endm

; ===========================================================================
GET_INDOS_FLAG proc far
; Output: ES:BX = address of flag
;         AL    = flag setting
; ===========================================================================
    mov  ax, offset cs:[INDOS]
    mov  bx, ax
    push cs
    pop  es
    mov  al, cs:[INDOS]
    ret
GET_INDOS_FLAG endp

Set_InDOS macro
    call get_indos_flag
    mov  ax, TRUE
    mov  byte ptr es:[bx], al
          endm

Clr_InDOS macro
    call get_indos_flag
    mov  ax, FALSE
    mov  byte ptr es:[bx], al
          endm

; ===========================================================================
GET_IN_VARS proc far
; ES:BX = List of Lists
; ===========================================================================
;   mov  cx, DOSVars_Size
    mov  bx, offset cs:[prBaseDPB]
    push cs
    pop  es
    ret
GET_IN_VARS endp

; ===========================================================================
GET_EXIT_CODE proc far
; ===========================================================================
      ; Get exit code - Child-program Return Value
      ; AH=0 normal, 1=Ctrl-break,
      ; AH=2 term. via critial error INT24
      ; AH=3 termination via Fn 31h KEEP
      mov  ah, cs:exitmethod
      mov  al, cs:errorlevel
      ret
GET_EXIT_CODE endp

; ===========================================================================
MSDOS_VERSION proc far
; DOS VERSION - AH= 30h
; Input : BX = FCh = Return Real version instead of Cooked Code
; Output: AL = Major version
;         AH = Minor version
;         BX:CX = Build Number
; ===========================================================================
     cmp  bx, 0fch       ; Return Real version instead of Cooked Code
     jne  DOSREAL    
     mov  ax, cs:setver  ; Get (editable) DOS Version
     jmp  MSDOSVERX
DOSREAL:                   ; DOS 2.0+ BX:CX OEM ID, sub versions
     mov  ax, _dosversion ; AL=major, AH=minor
     mov  bx, _build     ;  lr.BX = (OEM_ID << 8) | REVISION_SEQ;
     shl  bx, 8
     or   bl, _revision
     ; Supposely, a buggy 32RTM thrashes the stack if cx is NZ!
     xor  cx, cx
     mov  cl, _maintenance
     mov  dx, _version
MSDOSVERX:
     ret
MSDOS_VERSION endp

; ===========================================================================
MSDOS_DOSVARS proc far
; DosVars - get/set dos variables
; ===========================================================================
_dcs33fn0:
     cmp  al, 0                 ; Get Ctrl-C flag
     jne  _dcs33fn1
          mov  dl, cs:breakflag
     jmp  _MSDOSVOK
_dcs33fn1:
     cmp  al, 1                 ; set Ctrl-C flag
     jne  _dcs33fn2
          mov  cs:breakflag, dl
     jmp  _MSDOSVOK
_dcs33fn2:
     cmp  al, 2                 ; get/set extended control break
     jne  _dcs33fn3
          mov  dl, cs:breakflag
          and  dl, 1
          mov  cs:breakflag, dl
          ; mov  dl, tmp
     jmp  _MSDOSVOK
_dcs33fn3:
     cmp  al, 3                 ; DOS 7 does not set AL
     jne  _dcs33fn4
          xor  al, al              
          ; ...
     jmp  _MSDOSVOK
_dcs33fn4:
     cmp  al, 4
     jne  _dcs33fn5
          xor  al, al              
          ; ...
     jmp  _MSDOSVOK
_dcs33fn5:
     cmp  al, 5                   ; get bootdrive in dl
     jne  _dcs33fn6
          mov  dl, cs:bootdrive
     jmp  _MSDOSVOK
_dcs33fn6:
     cmp  al, 6     ; Get (real) DOS-C version (devel. version)
     jne  _dcs33fn7         
          mov  ax, _version
          mov  bx, _dosversion          ; BHBL = minor.major
          mov  cx, cs:_serialno
          mov  dh, 0
          mov  dl, _revision
          mov  dh, 00000000b  ; bit 3 : runs in ROM,bit 4: runs in HMA
          lea  si, cs:timestamp  ; Get DOS makedate string pointer
          push cs
          pop  es
     jmp  _MSDOSVOK
_dcs33fn7:
     cmp  al, 7          ; Display version screen
     jmp  _MSDOSVX
          call cs:about
     jmp  _MSDOSVOK
_MSDOSVOK:

_MSDOSVX:
       ret
MSDOS_DOSVARS endp

DOS_SERIAL proc far
; Get/Set Serial Number
; AL = 0 get serial number
;      1 set serial number
; BL = drive (0 = defualt, 1=A:, 2 = B:, ...)
; DS:DX = Buffer for extended BIOS Parameter Block 
      cmp  bl, 0
      jne  dcs69_userdrv
      dec  bl
dcs69_userdrv:
      cmp  al, 2
      jb   dcs_69x          ; invalid drive
      ; getdpb         ; !nul
      mov  cx, 846h
      cmp  al, 0
      jne  dcs69ne
      mov  cx, 866h
dcs69ne:
      mov  al, 0dh
      ; rc = DosDevIOctl(&lr);
dcs_69x:
      ret
DOS_SERIAL endp

; ===========================================================================
MSDOS70 proc far                          ; DOS 7.0+ FAT32 extended functions
; ===========================================================================

_MSDOS7OK:   clc
             jmp  short _MSDOS7X
_MSDOS7ERR:  stc
_MSDOS7X:
        ret
MSDOS70 endp

Country_Info proc far
; Get/Set Country Info
      ; UWORD ccode = lr.AL != 0xFF ? lr.AL : lr.BX;
      cmp  dx, 0ffffh
      jne  _dos_getcc
      mov  ccode, bx         ; rc = DosSetCountry(ccode);
_dos_getcc:
      ; Get Country Information
      ; rc = DosGetCountryInformation(ccode ? ccode : NLS_DEFAULT, FP_DS_DX);
      ; if (rc >= SUCCESS)
      mov bx, ccode
      ret
Country_Info endp

GET_DOS_EXTERR proc far
      ; mov  ax, nxdosbio
      ; mov  es, ax
      push cs
      pop  es
      lea  di, cs:CritErrDev
      mov  ax, cs:CritErrCode
      mov  bh, cs:CritErrClass  ; error class 
      mov  bl, cs:CritErrAction ; suggested action
      mov  cl, cs:CritErrLocus  ; location (where error occured)
      ret
GET_DOS_EXTERR endp

EXT_COUNTRY_INF proc far
; Extended country info
      cmp  al, 20h
      jne  _dos_65_ucm
      ; 01100001 = a
      ; 01000001 = A
      or   dl, 20h
      jmp  _dos_65_x        
_dos_65_ucm:
      cmp  al, 21h         ; upcase memory area
      jne  _dos_65_uas
      mov  si, dx
      mov  di, dx
_dos65_uml:
      mov  al, byte ptr [si]
      or   al, 20h
      mov  byte ptr [di], al
      inc  si
      inc  di
      loop _dos65_uml
      jmp  _dos_65_x
_dos_65_uas:
      cmp  al, 22h         ; upcase ASCIZ
      jne  _dos_65_scf
      mov  si, dx
      mov  di, dx
_dos_65_ual:
      mov  al, byte ptr [si]
      push ax
      or   al, 20h
      mov  byte ptr [di], al
      pop  ax
      inc  si
      inc  di
      or   al, al
      jnz  _dos_65_ual
      jmp  _dos_65_x
_dos_65_scf:
      cmp  al, 0a0h         ; upcase single character of filenames
      jne  _dos_65_umf
      ; lr.DL = DosUpFChar(lr.DL);
      jmp  _dos_65_x
_dos_65_umf:
      cmp  al, 0a1h         ; upcase memory area of filenames
      jne  _dos_65_uaf
      ; DosUpFMem(FP_DS_DX, lr.CX); 
      jmp  _dos_65_x
_dos_65_uaf:
      cmp  al, 0a2h         ; upcase ASCIZ of filenames
      jne  _dos_65_cyn
      ; DosUpFString(FP_DS_DX);
      jmp  _dos_65_x
_dos_65_cyn:
      cmp  al, 023h         ; check Yes/No response
      jne  _dos_65_def
      mov  ax, 0
      cmp  dx, 'Y'
      jne  _dos_65_x
      inc  ax
      jmp  _dos_65_x
_dos_65_def:
      ; if NLS_DEBUG
      ; dosgetdata al, bx, dx, cx, ES:DI
_dos_65_x:
      ret
EXT_COUNTRY_INF endp
