'------------------------------------------------------------------------------
' PortDLL.inc
' Created by Branko Spoljaric - Barney
' Version: 0.1
'------------------------------------------------------------------------------
' Port.dll is a DLL containing a very useful libary of comm functions
' It has been part of Elektor magazine project and can be found at many web
' sites. This include file is made in hope that it will make the usage of
' Port.dll easier for the users of Emergence Basic. A great free BASIC like
' language created by Paul Turley and available at www.ionicwind.com
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
' First let's tell the EBasic we are using "Port.lib" import library
' This library is created by EBasic by examining "Port.dll" file
' Create it by selecting "Tools->Create Import Library" option on the main menu
'------------------------------------------------------------------------------
$USE "Port.lib"

'------------------------------------------------------------------------------
' Now we are declaring some of the functions we are going to use
' Those functions are stored inside "Port.dll" and declares are necessary
' in order for the compiler to know how to use them. Declares and import
' library are also necessary to inform the linker how to link in the final EXE
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
' COM ports specific stuff
'------------------------------------------------------------------------------
' In order to do anything with the COM port we need to open it and after we are
' done with it, we have to close it properly. This is exactly what OPENCOM and
' CLOSECOM functions are doing.
' OPENCOM requires a string parameter which can be simple "com1" or complex.
' Most basic command will be OPENCOM("com1") and will open COM1 port with
' standard values for speed, parity and stop bits. More complex command allows
' us to set the comm speed, parity control and number of data and stop bits
' used. For example, "com1:9600,n,8,1" command will try to open a COM1 port and
' set the speed to 9600 bits/sec, no parity, 8-bits of data and one stop bit.
' For parity you can use N (no parity), O (odd parity) or E (even parity)
' Number of data bits is either 7 or 8
' Number of stop bits is the number of bits between two data bytes
' The return value of 0 indicates failure to open COM port
'------------------------------------------------------------------------------
DECLARE IMPORT, OPENCOM(STRING A),INT
DECLARE IMPORT, CLOSECOM()
'------------------------------------------------------------------------------
' COM ports specific stuff
'------------------------------------------------------------------------------
' There are four input lines at each COM port
'
' DCD - Data Carrier Detect
' DSR - Data Send Request
' CTS - Clear to Send
' RI  - Ring Indicator
'
' Functions are named exactly the same as the lines and they don't need any
' inpit parameters. The returning value is either 0 or 1 indicating line
' low (0) or high (1)
'------------------------------------------------------------------------------
DECLARE IMPORT, DCD(),INT
DECLARE IMPORT, DSR(),INT
DECLARE IMPORT, CTS(),INT
DECLARE IMPORT, RI(),INT
'------------------------------------------------------------------------------
' COM ports specific stuff
'------------------------------------------------------------------------------
' There are three output lines at each COM port
'
' TXD - Transmit Data
' DTR - Data Terminal Ready
' RTS - Request To Send
'
' Functions are named exactly the same as the lines and they all need one input
' parameter, which can be either 0 or 1. For example, if we want to tell the
' listener we want to send data we will use RTS(1) function and then wait for
' the answer via CTS() function
'------------------------------------------------------------------------------
DECLARE IMPORT, TXD(INT b)
DECLARE IMPORT, DTR(INT b)
DECLARE IMPORT, RTS(INT b)
'------------------------------------------------------------------------------
' LPT port specific stuff
'------------------------------------------------------------------------------
' We have two functions here. SENDBYTE is sending a byte of data to LPT port,
' while READBYTE is reading a byte of data from LPT port. Even though input
' and ooutput values are INT (32-bit) only the lowest 8-bits will be valid, so
' make sure you are only sending values between 0 and 255. Values received will
' also be inside 0-255 range
'------------------------------------------------------------------------------
DECLARE IMPORT, SENDBYTE(INT b)
DECLARE IMPORT, READBYTE(),INT
'------------------------------------------------------------------------------
' PRIORITY
'------------------------------------------------------------------------------
' Here we have just one function, which will give the program highest possible
' priority (parameter set to TRUE), or return it to normal priority processing
' (parameter set to FALSE)
'------------------------------------------------------------------------------
DECLARE IMPORT, REALTIME(INT i)
'------------------------------------------------------------------------------
' DELAY times
'------------------------------------------------------------------------------
' Following two functionw define the time a program will wait before continuing
' execution.
' DELAY will wait for a given number of milliseconds and
' DELAYUS will wait for a given number of microseconds, which gives us more
' precision, but we have to use 64-bit value instead of the usual 32-bit
'------------------------------------------------------------------------------
DECLARE IMPORT, DELAY(INT b)
DECLARE IMPORT, DELAYUS(INT64 l)
'------------------------------------------------------------------------------
' TIME functiona
'------------------------------------------------------------------------------
' This set of functions is important for various time measurements. Just as
' with DELAY functions, TIME functions also operate on millisecond or
' microsecond basis.
' TIMEINIT and TIMEINITUS will reset the timers to zero and start them again
' with ms or us precision
' TIMEREAD and TIMEREADUS functions will read the amount of time (in ms or us)
' since the last TIMEINIT or TIMEINITUS function was executed. Both functions
' return a 64-bit integer
'------------------------------------------------------------------------------
DECLARE IMPORT, TIMEINIT()
DECLARE IMPORT, TIMEINITUS()
DECLARE IMPORT, TIMEREAD(),INT64
DECLARE IMPORT, TIMEREADUS(),INT64
'------------------------------------------------------------------------------
' COM and LPT ports common stuff
'------------------------------------------------------------------------------
' These two functions are not tied up to Win API. They try to get to the
' hardware directly and are faster than the rest of the comm functions.
' The parameters passed to the OUTPORT function are the address of the COM or
' LPT port we want to send the data to, and an 8-bit (byte) data value.
' INPORT function accepts the address of the COM or LPT port only and returns
' an 8-bit data value. Due to their nature (direct hardware access) these
' functions should be used with care and are not guaranteed to always work
'------------------------------------------------------------------------------
DECLARE IMPORT, OUTPORT(INT a, INT b)
DECLARE IMPORT, INPORT(INT p),INT
'------------------------------------------------------------------------------
' Regardng JOYSTICK and AUDIO functions. I did not research much into them,
' so I am not 100% sure if the declarations are correct and I definitely
' cannot guarantee the functions will work. Try them at your own risk.
'------------------------------------------------------------------------------
' JOYSTICK functions - not guaranteed to be correct or working
'------------------------------------------------------------------------------
DECLARE IMPORT, PD_JOYX ALIAS JOYX(),INT64
DECLARE IMPORT, PD_JOYY ALIAS JOYY(),INT64
DECLARE IMPORT, PD_JOYZ ALIAS JOYZ(),INT64
DECLARE IMPORT, JOYW(),INT64
DECLARE IMPORT, JOYBUTTON(),INT
'------------------------------------------------------------------------------
' AUDIO functions - not guaranteed to be correct or working
'------------------------------------------------------------------------------
DECLARE IMPORT, SOUNDSETRATE(INT iRate),INT
DECLARE IMPORT, SOUNDGETRATE(),INT
DECLARE IMPORT, SOUNDBUSY(),INT
DECLARE IMPORT, SOUNDIS(),INT
DECLARE IMPORT, SOUNDIN(STRING sBuffer, INT iSize)
DECLARE IMPORT, SOUNDOUT(STRING sBuffer, INT iSize)
DECLARE IMPORT, SOUNDGETBYTES(),INT
DECLARE IMPORT, SOUNDSETBYTES(INT b),INT
DECLARE IMPORT, SOUNDCAPIN()
DECLARE IMPORT, SOUNDCAPDOUT()

