'===========================================================================
' Subject: NOVELL NETWARE ROUTINES            Date: 04-06-96 (00:00)       
'  Author: Greg Shultz/Dave Navarro, Jr.      Code: PB32                   
'  Origin: comp.lang.basic.misc             Packet: NETWORK.ABC
'===========================================================================
'Novell Netware programming seeems to be a more and more important issue these 
'days with many programmers.  Users are demanding direct network support in 
'many applications.

'As a result, Greg Schultz and I are working on a public domain Novell Netware 
'library for PowerBASIC.  Most of the work is being done on CompuServe in the 
'PowerBASIC forum.  However, I'll try to post updates here whenever possible.

'Greg has Netware set up and running at his office and home and I am in the 
'process of setting up Netware at home (we use LANtastic at work).

'If you have any code you would like to contribute, please email it to me and 
'I'll make sure to review it.

'I hope you find the following code useful:

'We've tested this code on Netware 3.11, 3.12 and 4.01.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   Novell Netware routines for PowerBASIC 3.2 or later
'   Donated to the Public Domain
'   Last Revision:  April 6, 1996
'
'   Contributions by:  Greg Shultz          71223.431@compuserve.com
'                      Dave Navarro, Jr.    dave@powerbasic.com
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
$CPU 8086          'make compatible with XT systems
$LIB ALL OFF       'turn off all PowerBASIC libraries
$ERROR ALL OFF     'turn off all PowerBASIC error checking
$OPTIMIZE SIZE     'optimize for smaller code
$COMPILE UNIT      'compile to a UNIT (.PBU)
$DIM ALL           'force all variables and arrays to be declared


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' PROC:    NovellAPI
' AUTHOR:  Dave Navarro, Jr.
' DECLARE: FUNCTION NovellAPI(BYVAL integer, ANY, ANY) AS INTEGER
' DESC:    Make a call to the Novell API.  Return's true (-1) if call was
'          successful.
' EXAMP:   Success = NovellAPI(Service%, RequestType, ReplyType)
'
FUNCTION NovellAPI(BYVAL service AS INTEGER, ANY, ANY) AS INTEGER

  !     push    DS                      ;

  !     lds     SI, [BP+8]              ; point DS:SI to request packet
  !     les     DI, [BP+12]             ; point ES:DI to reply packet
  !     mov     AH, Byte Ptr Service    ; put service in AH
  !     xor     AL, AL                  ; clear AL
  !     int     &H21                    ; call API through DOS

  !     xor     BX, BX                  ; clear BX
  !     mov     AH, BH                  ; clear AH
  !     or      AL, AL                  ; we're we successful?
  !     jnz     Done                    ; yes, exit
  !     dec     BX                      ; make it -1
Done:
  !     mov     AX, BX                  ; put return code in AX

  !     pop     DS                      ;

END FUNCTION


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' PROC:    NovCVI
' AUTHOR:  Dave Navarro, Jr.
' DECLARE: FUNCTION NovCVI(BYVAL string) AS INTEGER
' DESC:    Converts a Novell style integer into an IEEE integer.
' EXAMP:   User = NovCVI( User.Object )
'
FUNCTION NovCVI(BYVAL x AS STRING) AS INTEGER

  DIM y AS LOCAL INTEGER

  y = CVI(x)

  ! mov  AX, y
  ! xchg AL, AH
  ! mov  y, AX

  FUNCTION = y

END FUNCTION


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' PROC:    NovCVL
' AUTHOR:  Dave Navarro, Jr.
' DECLARE: FUNCTION NovCVL(BYVAL string) AS LONG
' DESC:    Converts a Novell style long into an IEEE long.
' EXAMP:   User = NovCVL( User.Object )
'
FUNCTION NovCVL(BYVAL x AS STRING) AS LONG

  DIM y AS LOCAL LONG

  y = CVL(x)

  ! mov  AX, y[0]
  ! mov  BX, y[2]
  ! mov  y[0], BX
  ! mov  y[2], AX

  FUNCTION = y

END FUNCTION


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' PROC:    NovMKI
' AUTHOR:  Dave Navarro, Jr.
' DECLARE: FUNCTION NovMKI(BYVAL integer) AS STRING
' DESC:    Converts an IEEE style integer into a Novell integer.
' EXAMP:   User.Object = NovMKI(255)
'
FUNCTION NovMKI(BYVAL x AS INTEGER) AS STRING

  ! mov  AX, x
  ! xchg AL, AH
  ! mov  x, AX

  FUNCTION = MKI$(x)

END FUNCTION


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' PROC:    NovMKL
' AUTHOR:  Dave Navarro, Jr.
' DECLARE: FUNCTION NovMKL(BYVAL long) AS STRING
' DESC:    Converts an IEEE style long into a Novell long.
' EXAMP:   User.Object = NovMKL(255)
'
FUNCTION NovMKL(BYVAL x AS LONG) AS STRING

  ! mov  AX, x[0]
  ! mov  BX, x[2]
  ! mov  x[0], BX
  ! mov  x[2], AX

  FUNCTION = MKL$(x)

END FUNCTION


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' PROC:    NovConnection
' AUTHOR:  Greg Shultz
' DECLARE: FUNCTION NovConnection() AS INTEGER
' DESC:    Return the connection number for the current workstation.  If
'          zero is returned, the workstation is not logged into a server.
' EXAMP:   PRINT "Current connection number:"; NovConnection
'
FUNCTION NovConnection () AS INTEGER

  ! mov  AX, &HDC00              ; get connection id
  ! int  &H21                    ; through DOS
  ! xor  AH, AH                  ; clear AH
  ! mov  FUNCTION, AX            ; return result

END FUNCTION


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' PROC:    NovOpenBindery
' AUTHOR:  Greg Shultz
' DECLARE: FUNCTION NovOpenBinery() AS INTEGER
' DESC:    Returns true (-1) if the bindery was successfully opened.
'
TYPE OpenBinderyRequest
  Length  AS WORD   '0001
  Service AS BYTE   'subfunc 45h
END TYPE

TYPE OpenBinderyReply
  Empty   AS WORD   'nothing is returned
END TYPE

FUNCTION NovOpenBindery () AS INTEGER

  DIM Request AS OpenBinderyRequest
  DIM Reply   AS OpenBinderyReply

  Request.Length  = 1
  Request.Service = &H45
  Reply.Empty     = 0

  FUNCTION = NovellAPI(&HE3, Request, Reply)

END FUNCTION


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' PROC:    NovCloseBindery
' AUTHOR:  Greg Shultz
' DECLARE: FUNCTION NovCloseBinery() AS INTEGER
' DESC:    Returns true (-1) if the bindery was successfully closed.
'
TYPE CloseBinderyRequest
  Length  AS WORD   '0001
  Service AS BYTE   'subfunc 44h
END TYPE

TYPE CloseBinderyReply
  Empty   AS WORD   'nothing is returned
END TYPE

FUNCTION NovCloseBindery () AS INTEGER

  DIM Request AS CloseBinderyRequest
  DIM Reply   AS CloseBinderyReply

  Request.Length  = 1
  Request.Service = &H44
  Reply.Empty     = 0

  FUNCTION = NovellAPI(&H3E, Request, Reply)

END FUNCTION


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' PROC:    NovLogOutAll
' AUTHOR:  Dave Navarro, Jr.
' DECLARE: FUNCTION NovLogOutAll() AS INTEGER
' DESC:    Logs the current workstation out of all attached servers.  Returns
'          true (-1) if successful.
' EXAMP:   CALL NovLogOutAll
'
FUNCTION NovLogOutAll () AS INTEGER

  ! mov  AX, &HD700
  ! int  &H21
  ! xor  AH, AH
  ! mov  FUNCTION, AX

END FUNCTION
