home *** CD-ROM | disk | FTP | other *** search
- '┌─────────────────────────────────────────────────────────────────────┐
- '└── beginning of crossbas.inc ────────────────────────────────────────┘
-
- ' Include file for CrossBas.bas
- ' Lester L. Noll
- ' CompuServe Id: 72250,2551
- ' copyright (c) November 13, 1989, 1990
-
- '─── flush keyboard buffer ─────────────────────────────────────────────
- SUB FlushKeyBuf 'Flush any waiting keystrokes.
-
- WHILE INSTAT
- InK$ =INKEY$
- WEND
- END SUB
-
- '─── dimension cmd line array ──────────────────────────────────────────
- SUB DimCmdLine(DimCmd%) 'Find number of elements in command line to dimension
- ' the parameter$ array of ReadCmdLine() procedure.
-
- LOCAL I%, Char$, CmdLine$, DelimitFlag%
- DimCmd% =0
- DelimitFlag% =-1
- CmdLine$=COMMAND$
- FOR I% =1 TO LEN(CmdLine$) 'Increment through the cmd line 1 char at a time.
- Char$=MID$(CmdLine$,I%,1)
- SELECT CASE Char$
- CASE " " : GOTO DimCmdLine.1 'Space char.
- CASE "," : GOTO DimCmdLine.1 'Comma char.
- CASE "/" : GOTO DimCmdLine.1 'Switch char.
- CASE "" : GOTO DimCmdLine.1 'No more chars.
- CASE CHR$(0) TO CHR$(31) : GOTO DimCmdLine.2 'Non-anphanumeric
- CASE >CHR$(125) : GOTO DimCmdLine.2 'Non-alphanumeric
- END SELECT
- DelimitFlag% =0
- GOTO DimCmdLine.2
-
- DimCmdLine.1:
- IF DelimitFlag% THEN DimCmdLine.2
- DelimitFlag% =-1
- INCR DimCmd%
-
- DimCmdLine.2:
- NEXT I%
- INCR DimCmd%
- END SUB
-
-
- '─── read DOS command line ─────────────────────────────────────────────
- SUB ParseCmdLine(Cmd$(1)) 'This subprogram will parse the DOS command line
- ' and return the non-blank characters as members
- ' of the array Cmd$(). The maximum number of
- ' command line characters is 127.
- 'If you expect to see more than 10 command line
- ' parameters, you must include a DIM Cmd$()
- ' statement prior to calling this subprogram.
- 'You should include a $DYNAMIC statement at the
- ' top of the calling program so that after you are
- ' finished with the Cmd$() array you can ERASE it.
-
- LOCAL I%, J%, Char$, Temp$, CmdLine$, DelimitFlag%
- DelimitFlag% =-1
- CmdLine$=COMMAND$
- FOR I% =1 TO LEN(CmdLine$)+1 'Increment through the cmd line 1 char at a time.
- Char$=MID$(CmdLine$,I%,1)
- SELECT CASE Char$
- CASE " " : GOTO ParseCmdLine.6 'Space char.
- CASE "," : GOTO ParseCmdLine.6 'Comma char.
- CASE "" : GOTO ParseCmdLine.4 'No more chars.
- CASE CHR$(0) TO CHR$(31) : GOTO ParseCmdLine.9 'Ignore non alpha-num.
- CASE "/" : GOTO ParseCmdLine.5 'Switch delimiter.
- CASE ELSE : GOTO ParseCmdLine.7
- END SELECT
-
- ParseCmdLine.4: 'No more chars on cmd line.
- I% =128
- GOTO ParseCmdLine.8
-
- ParseCmdLine.5: 'Switch delimiter.
- IF Temp$ ="/" GOTO ParseCmdLine.9
- IF NOT (Temp$ ="") THEN ParseCmdLine.8
- GOTO ParseCmdLine.7
-
- ParseCmdLine.6: 'Space delimiter.
- IF DelimitFlag% THEN ParseCmdLine.9
- DelimitFlag% =-1
- GOTO ParseCmdLine.8
-
- ParseCmdLine.7: 'Normal text.
- DelimitFlag% =0
- Temp$ =Temp$ +Char$
- GOTO ParseCmdLine.9
-
- ParseCmdLine.8: 'Save word and start next.
- INCR J%
- Cmd$(J%) =Temp$
- IF Char$ ="/" THEN Temp$ =Char$ ELSE Temp$ =""
-
- ParseCmdLine.9: 'Get next character.
- NEXT I%
-
- END SUB
-
-
- '─── calculate the drive portion of a file path ────────────────────────
- SUB CalcDr(FilePath$,Dr$)
-
- LOCAL C%
- Dr$ =""
- IF NOT (FilePath$ ="") THEN
- C% =INSTR(FilePath$,":")
- IF C% =2 THEN
- SELECT CASE UCASE$(LEFT$(FilePath$,1))
- CASE "A" TO "J" : Dr$ =LEFT$(FilePath$,2)
- END SELECT
- END IF
- END IF
- END SUB
-
-
- '─── calculate the directory portion of a file path ────────────────────
- SUB CalcDir(FilePath$,Dir$)
-
- LOCAL I%, I1%, I2%
- Dir$ =""
- IF NOT FilePath$ ="" THEN
- I% =INSTR(FilePath$,"\")
- IF I% >0 THEN
- I1% =I%
- WHILE I% >0
- I2% =I%
- I% =INSTR(I2%+1,FilePath$,"\")
- WEND
- Dir$ =MID$(FilePath$,I1%,I2%-I1%+1)
- END IF
- IF NOT Dir$ ="" THEN
- IF NOT LEFT$(Dir$,1) ="\" THEN Dir$ ="\" +Dir$
- IF NOT RIGHT$(Dir$,1) ="\" THEN Dir$ =Dir$ +"\"
- END IF
- END IF
- END SUB
-
-
- '─── calculate the filename portion of a file path ─────────────────────
- SUB CalcName(FilePath$,FileName$)
-
- LOCAL C%, I%, I1%
- FileName$ =""
- IF NOT (FilePath$ ="") THEN
- C% =INSTR(FilePath$,":")
- IF NOT (C% =2) THEN C% =0
- I% =INSTR(FilePath$,"\")
- WHILE I% >0
- I1% =I%
- I% =INSTR(I%+1,FilePath$,"\")
- WEND
- IF I1% >0 THEN
- FileName$ =MID$(FilePath$,I1%+1)
- ELSEIF C% =2 THEN
- FileName$ =MID$(FilePath$,3)
- ELSE
- FileName$ =FilePath$
- END IF
- END IF
- END SUB
-
- '─── catch runtime error ────────────────────────────────────────────────
- SUB CatchRuntime
-
- BEEP: DELAY 1: BEEP: DELAY 1: BEEP
- PRINT
- PRINT "Fatal Error Encountered!!"
- PRINT
- PRINT "Error #";STR$(ERR);" at PC counter ";
- PRINT ERADR
- PRINT fnErrorMsg$
- IF ERDEV >0 THEN
- PRINT "Device #";ERDEV$; ", "; STR$(ERDEV)
- END IF
- PRINT "End Memory =";
- PRINT ENDMEM
- PRINT "String Segment=";
- Temp& =(VARSEG(S$))
- Temp& =Temp&*16
- PRINT Temp&,
- PRINT "Hex: "; HEX$(VARSEG(S$));":";HEX$(VARPTR(S$))
- PRINT "String Space =";
- PRINT FRE(S$)
- PRINT "Array Space =";
- PRINT FRE(-1)
- PRINT "Stack Space =";
- PRINT FRE(-2)
- END SUB
-
-
- '─── get error description ─────────────────────────────────────────────
- DEF fnErrorMsg$
-
- LOCAL ErrNum%, Temp$
- ErrNum% =ERR
- SELECT CASE ErrNum%
- CASE 0 : Temp$ =""
- CASE 2 : Temp$ ="Syntax error"
- CASE 3 : Temp$ ="RETURN without GOSUB"
- CASE 4 : Temp$ ="Out of data"
- CASE 5 : Temp$ ="Illegal functin call"
- CASE 6 : Temp$ ="Overflow"
- CASE 7 : Temp$ ="Out of memory"
- CASE 9 : Temp$ ="Subscript out of range"
- CASE 10 : Temp$ ="Duplicate definition"
- CASE 11 : Temp$ ="Division by zero"
- CASE 13 : Temp$ ="Type mismatch"
- CASE 14 : Temp$ ="Out of string space"
- CASE 15 : Temp$ ="String too long"
- CASE 19 : Temp$ ="No RESUME"
- CASE 20 : Temp$ ="RESUME without error"
- CASE 24 : Temp$ ="Device Timeout"
- CASE 25 : Temp$ ="Device hardware error"
- CASE 27 : Temp$ ="Printer out of paper"
- CASE 50 : Temp$ ="Field overflow"
- CASE 51 : Temp$ ="Internal error"
- CASE 52 : Temp$ ="Bad file number"
- CASE 53 : Temp$ ="File not found"
- CASE 54 : Temp$ ="Bad file mode"
- CASE 55 : Temp$ ="File already open"
- CASE 57 : Temp$ ="Device I/O error"
- CASE 58 : Temp$ ="File already exists"
- CASE 61 : Temp$ ="Disk is full"
- CASE 62 : Temp$ ="Input past end"
- CASE 63 : Temp$ ="Bad record number"
- CASE 64 : Temp$ ="Bad file name"
- CASE 67 : Temp$ ="Too many files in directory or bad file spec"
- CASE 68 : Temp$ ="Device not available"
- CASE 69 : Temp$ ="Communications buffer overflow"
- CASE 70 : Temp$ ="Disk is write protected"
- CASE 71 : Temp$ ="Disk not ready"
- CASE 72 : Temp$ ="Disk media error"
- CASE 74 : Temp$ ="Rename across disks"
- CASE 75 : Temp$ ="Path / file access error"
- CASE 76 : Temp$ ="Path not found"
- CASE 201 : Temp$ ="Out of stack space"
- CASE 202 : Temp$ ="Out of string temp space"
- CASE 203 : Temp$ ="Mismatched common variables"
- CASE 204 : Temp$ ="Midmatched program options"
- CASE 205 : Temp$ ="Mismatched program revisions"
- CASE 206 : Temp$ ="Invalid program file"
- CASE 242 : Temp$ ="String / array memory corrupt"
- CASE 243 : Temp$ ="CHAIN/RUN from .EXE file only"
- CASE 258 : Temp$ ="Program too big to fit in memory"
- CASE 900 : Temp$ ="Pop/Push Cursor stack value out of range"
- CASE 901 : Temp$ ="HexFill$ conversion value too large"
- CASE ELSE : Temp$ ="Unknown error #" +STR$(ERR) +_
- " at PC counter " +STR$(ERADR)
- END SELECT
- fnErrorMsg$ =Temp$
- END DEF
-
-
- '─── save cursor position ──────────────────────────────────────────────
- SUB PushCursor
-
- SHARED SaveRow%(), SaveCol%(), PushCNum%
- INCR PushCNum%
- IF PushCNum% >10 THEN ERROR 900
- SaveRow%(PushCNum%) =CSRLIN: SaveCol%(PushCNum%) =POS
- END SUB
-
-
- '─── restore cursor position ───────────────────────────────────────────
- SUB PopCursor
-
- SHARED SaveRow%(), SaveCol%(), PushCNum%
- LOCATE SaveRow%(PushCNum%),SaveCol%(PushCNum%)
- DECR PushCNum%
- IF PushCNum% <0 THEN ERROR 900
- END SUB
-
-
- '─── blank one line ────────────────────────────────────────────────────
- SUB Blankline(Row%,FG%,BG%) 'Print 80 blank spaces with the color passed
- ' to the subroutine. Color must be restored
- ' by the calling program.
- COLOR FG%,BG%
- LOCATE Row%,1,0
- PRINT SPACE$(80);
- END SUB
-
-
- '─── right justify text ────────────────────────────────────────────────
- DEF fnRightJust$(Text$,FieldWidth%)
-
- fnRightJust$ =SPACE$(FieldWidth% -LEN(Text$)) +Text$
- END DEF
-
- '─── center justify text ───────────────────────────────────────────────
- DEF fnCenterJust$(Text$,FieldWidth%)
-
- LOCAL CenterSpc%
- IF LEN(Text$) >=FieldWidth% THEN
- CenterSpc% =0
- ELSE
- CenterSpc% =(FieldWidth% -LEN(Text$)) \2
- END IF
- fnCenterJust$ =SPACE$(CenterSpc%) +Text$ +SPACE$(CenterSpc%)
- END DEF
-
- '─── center justify/fill text ──────────────────────────────────────────
- DEF fnCenterJustFill$(Text$,FieldWidth%,FillChar$)
-
- LOCAL CenterSpc%
- CenterSpc% =(FieldWidth% -LEN(Text$)) \2
- fnCenterJustFill$ =STRING$(CenterSpc%,FillChar$) +Text$ +_
- STRING$(CenterSpc%,FillChar$)
- END DEF
-
-
- '─── convert seconds to time string ────────────────────────────────────
- DEF fnSecondsToTime$(Seconds&)
-
- LOCAL Sec%, Mins%, Hour%, Sec$, Mins$, Hour$
- Seconds& =FIX(Seconds&)
- Hour% =FIX(Seconds& /3600)
- Mins% =FIX(((Seconds& /3600 -Hour%) *3600) /60)
- Sec% =FIX((((Seconds& /3600 -Hour%) *3600) /60 -Mins%) *60)
- IF Hour% >9 THEN
- Hour$ =RIGHT$(STR$(Hour%),2)
- ELSE
- Hour$ ="0" +RIGHT$(STR$(Hour%),1)
- END IF
- IF Mins% >9 THEN
- Mins$ =RIGHT$(STR$(Mins%),2)
- ELSE
- Mins$ ="0" +RIGHT$(STR$(Mins%),1)
- END IF
- IF Sec% >9 THEN
- Sec$ =RIGHT$(STR$(Sec%),2)
- ELSE
- Sec$ ="0" +RIGHT$(STR$(Sec%),1)
- END IF
- fnSecondsToTime$ = Hour$ +":" +Mins$ +":" +Sec$
- END DEF
-
-
- '─── subtract end time from start time ─────────────────────────────────
- DEF fnElapsedSeconds&(BegTime$,EndTime$)
-
- LOCAL BegSec&, EndSec&
- BegSec& =fnTimeToSeconds&(BegTime$)
- EndSec& =fnTimeToSeconds&(EndTime$)
- fnElapsedSeconds& =EndSec& -BegSec&
- END DEF
-
-
- '─── convert time string to seconds ────────────────────────────────────
- DEF fnTimeToSeconds&(TimeX$)
-
- LOCAL Sec%, Mins%, Hour&, Temp&
- Hour& =VAL(LEFT$(TimeX$,2))
- Mins% =VAL(MID$(TimeX$,4,2))
- Sec% =VAL(RIGHT$(TimeX$,2))
- fnTimeToSeconds& =(Hour& *3600) +(Mins% *60) +Sec%
- END DEF
-
- '─── fill hex word with zeros ──────────────────────────────────────────
- DEF fnHexFill$(Value&,Count%) 'Convert a value to hex and left-fill with
- ' zeros a field width of count%.
-
- LOCAL Remainder%, I%, Temp$, Temp&
- IF Value& >1048575 THEN ERROR 901 'Value bigger than can convert to hex.
- IF Value& >65535 THEN 'HEX$() will not convert a value
- Temp& =FIX(Value& /16) ' larger than 64k.
- Remainder% =(Value& -(Temp& *16)) MOD 16
- Temp$ =HEX$(Temp&)
- Temp$ =Temp$ +HEX$(Remainder%)
- ELSE
- Temp$ =HEX$(Value&)
- END IF
- DO UNTIL LEN(Temp$) =Count%
- Temp$ ="0" +Temp$
- LOOP
- fnHexFill$ =Temp$
- END DEF
-
-
- '─── limit upper value ────────────────────────────────────────────────
- DEF fnMax&(Value&,UpperValue&)
-
- IF Value& >UpperValue& THEN Value& =UpperValue&
- fnMax& =Value&
- END DEF
-
-
- '─── limit lower value ────────────────────────────────────────────────
- DEF fnMins&(Value&,LowerValue&)
-
- IF Value& <LowerValue& THEN Value& =LowerValue&
- fnMins& =Value&
- END DEF
-
-
- '─── get rom machine id ────────────────────────────────────────────────
- DEF fnROMId$ 'ROM machine id is an integer.
-
- LOCAL Temp&, Temp$
- DEF SEG =&hF000
- Temp& =PEEK(&hFFFE)
- DEF SEG
- SELECT CASE Temp&
- CASE 255 : Temp$ ="IBM PC"
- CASE 254 : Temp$ ="IBM XT"
- CASE 253 : Temp$ ="IBM PCjr"
- CASE 252 : Temp$ ="IBM AT"
- CASE 45 : Temp$ ="Compacq (PC)"
- CASE 154 : Temp$ ="Compaq-Plus (XT)"
- CASE ELSE : Temp$ ="Unknown #" +STR$(Temp&)
- END SELECT
- fnROMId$ =Temp$
- END DEF
-
-
- '┌── end of crossbas.inc ──────────────────────────────────────────────┐
- '└─────────────────────────────────────────────────────────────────────┘