home *** CD-ROM | disk | FTP | other *** search
- '************************************************************************
- function GetHandle%(FileName$, Method$) public
- local FileHandle%
-
- ' The function GetHandle% returns for the lowest available Turbo file
- ' handle with the requested file open in the specified mode. If no
- ' handles are available, the function returns 55.
- ' If the handle returned is < 1, then an error occured and file is not
- ' open. The value returned is the negative of the PB error code.
- ' For com ports FileName$ is "COM#" and Method$ is option block (CR, etc.).
- ' The LEN= option of basic is not supported and will always be 128 which
- ' is PB's default.
-
- FileHandle% = freefile
- on error goto FileOpenError
- if left$(ucase$(FileName$),3) = "COM"_ ' CHECK IF COM PORT
- and len(FileName$) = 4 then
- open FileName$ +Method$ as FileHandle% ' IF IT IS OPEN AS COM PORT
- else ' OTHERWISE
- open Method$, FileHandle%, FileName$ ' TRY TO OPEN AS FILE
- end if
- on error goto 0 ' TURN OFF ERROR CHECKING
- GetHandle% = FileHandle% ' RETURN VALID HANDLE OR 0
- exit function
-
- FileOpenError:
- GetHandle% = -err ' Return error code as negative
-
- end function
-
- '************************************************************************
- function Exists% (FileSpec$) public
-
- ' The function Exists% returns a %True value if the file specified by
- ' FileName$ is on the current/specified disk drive.
-
- FileSpec$ = FileSpec$ +chr$(0) ' Make filespec an ASCIIZ
- reg %AX, &h3D00 ' DOS function 3D: Open File, read access
- reg %DS, strseg(FileSpec$) ' Point DS:DX to FileSpec
- reg %DX, strptr(FileSpec$)
- call interrupt %DOS ' call DOS
-
- if (reg(%Flags) and 1) = 0 then ' If carry flag clear then sucessful
- reg %BX, reg(%AX) ' Move DOS handle from AX to BX
- reg %AX, &h3E00 ' DOS function 3E: Close File
- call interrupt %DOS ' call DOS
- Exists% = %True ' Return TRUE
- else ' Otherwise
- Exists% = %False ' Return FALSE
- end if
-
- end function
-
- '************************************************************************
- function FileNameProper$ (FileName$) public
- local NameProper$
-
- NameProper$ = FileName$
- while instr(NameProper$, "\") > 0
- NameProper$ = mid$(NameProper$, instr(NameProper$, "\") +1)
- wend
- if instr(NameProper$, ".") > 0 then
- NameProper$ = left$(NameProper$, instr(NameProper$, ".") -1)
- end if
- if instr(NameProper$, ":") > 0 then
- NameProper$ = mid$(NameProper$, instr(NameProper$, ":") +1)
- end if
- FileNameProper$ = NameProper$
-
- end function
-
- '************************************************************************
- function FileNamePath$ (FileName$) public
- local NamePath$
-
- NamePath$ = FileName$
- if instr(NamePath$, "\") > 0 or instr(NamePath$, ":") > 0 then
- while right$(NamePath$, 1) <> "\" and right$(NamePath$, 1) <> ":"
- NamePath$ = left$ (NamePath$, len(NamePath$) -1)
- wend
- else
- NamePath$ = ""
- end if
- FileNamePath$ = NamePath$
-
- end function
-
- '************************************************************************
- function DefaultExt$ (FileName$, Ext$) public
-
- if instr(FileName$, ".") > 0 then
- DefaultExt$ = FileName$
- else
- DefaultExt$ = ChangeExt$ (FileName$, Ext$)
- end if
-
- end function
-
- '************************************************************************
- function ChangeExt$ (FileName$, Ext$) public
-
- if instr(Ext$, ".") > 0 then
- Ext$ = mid$(Ext$, instr(Ext$, ".") +1)
- end if
- Ext$ = left$(Ext$, 3)
- ChangeExt$ = FileNamePath$ (FileName$) _
- +FileNameProper$ (FileName$) + "." +Ext$
-
- end function
-
- '************************************************************************
- function GetBytes$ (Handle%, FileOffset&, BytesToGet%) public
- ' Purpose ......| Read specified number of bytes from a binary file
- ' Author/Date ..| Michael E. Flenniken 1-18-90
- ' Notes ........| File must be opened in binary mode before this function is
- ' | called. There is no error checking, so the program will
- ' | crash if the file isn't opened in binary mode.
- local BytesRead$
-
- seek Handle%, FileOffset&
- get$ Handle%, BytesToGet%, BytesRead$
- GetBytes$ = BytesRead$
-
- end function
-
- '************************************************************************
- function GetKeyPress$ (PromptStmt$, Valid$, Echo%) public
- ' Purpose ......| Prompt user to press a key and validate, with or w/o echo
- ' Author/Date ..| Michael E. Flenniken 1-18-90
- ' Notes ........| PromptStmt$ is the text to prompt user with. GetKeyPress$
- ' | normally moves the cursor to the next line upon
- ' | completion, but if PromptStmt$ is null and Echo% = 0 then
- ' | cursor position will be unchanged.
- ' | Valid$ is a list of valid keys presses to accept. If Valid$
- ' | is null then all keys are valid.
- ' | If Echo% is 0 the validated key press will not be sent to
- ' | the screen.
- local KeyPress$
-
- if PromptStmt$ <> "" then
- ? PromptStmt$; " ";
- end if
- while len(KeyPress$) = 0
- KeyPress$ = inkey$
- if instr(Valid$, KeyPress$) = 0 and len(Valid$) > 0 then
- KeyPress$ = ""
- end if
- wend
- if Echo% then
- ? KeyPress$;
- elseif len(PromptStmt$) > 0 then
- ' ?
- end if
- GetKeyPress$ = KeyPress$
-
- end function
-
- '************************************************************************
- sub StdOut (OutLine$, Term%) public
- ' Purpose ......| Send output to DOS stdout
- ' Author/Date ..| Michael E. Flenniken 6-6-90
- ' Notes ........| OutLine$ is the text to send to DOS stdout
- ' | Term% is the terminating character(s) to send. If Term% is
- ' | 13, a CR and LF is sent, otherwise it is ignored.
-
- if Term% = 13 then
- OutLine$ = OutLine$ +chr$(13, 10)
- end if
- OutLine$ = OutLine$ +"$"
- reg (%AX), &h0900
- reg (%DX), strptr (OutLine$)
- reg (%DS), strseg (OutLine$)
- call interrupt &h21
-
- end sub