'This program is built from RLseries.BAS. 10-23-10 'This program is modified to read text files and plot the the data. 'It plots sampled voltage vs time. The text file is unformatted raw text. Initial default text file is "out.txt", but can be changed in the program. 'The name of the coil can be held in the text file. It is in the first line after "NAME". 'The file name convention is: 2Char for make. 2Char for resistance in ohms. '1Char H or C for hot or cold. 1CHar M or U for mounted or unmounted. '2Char for sequence number for when there is more than one type of the same coil. 'The start of a sampling cycle is designated with an "$". The end with an "&". Notes can be written before $ or after & for any sample cycle. 'Each time-current pair is listed as "t" followed by time in usec, then "," then "v" followed by current data as a sample value (0 to 1023), 'followed by a ",". There may be spaces interspersed along with carriage returns. Those need to be ignored. 'There can be multiple sets of data in one file. The program will display each one at a time and will prompt before each. 'After the last one is drawn, there will be a blank graph before starting over with the first set. 'Lou Dudzik Updated 10/15/16 DECLARE SUB Intro () DECLARE SUB SetTscale () DECLARE SUB DrawScreen () DECLARE SUB DrawScreen () DECLARE SUB DrawGrid () DECLARE SUB PrintVar () DECLARE SUB Plot () 'Plots charging function DECLARE SUB GetCoilFile () DECLARE SUB GetCoilName () DECLARE SUB FindData () DECLARE FUNCTION ValidFilename (FileName$) DECLARE FUNCTION subtract# (aaa#, bbb#) DECLARE FUNCTION FileExists (FileName$) DECLARE SUB ZZLou24bIT (FileName$, invertBW$) DIM SHARED GrphSize 'holds whether the graph should be big or small DIM SHARED Fault AS INTEGER 'This holds a fault code DIM SHARED StyleHex 'This holds the alternating style pattern to create the dotted plot. DIM SHARED tscale AS DOUBLE 'tScale is the range of the x axis in seconds. DIM SHARED vMax AS DOUBLE 'vMax is the max of the y axis in volts and amps. DIM SHARED vMin AS DOUBLE 'vMin is the min of the y axis in volts and amps. DIM SHARED iLimit AS DOUBLE 'this is the maximum current to graph. This is used to stop plotting points on a graph after a certain value is reached. DIM SHARED GrphColor AS INTEGER 'Holds the color to be used for each plot. The color value increments for each successive plot. DIM SHARED CoilName AS STRING 'Holds the name of the coil to be plotted. DIM SHARED NewCoilN AS STRING 'This is the new coil name as found in the data file to be selected. DIM SHARED CoilFile AS STRING 'Holds the name of the file to be used to create the plot. DIM SHARED NewCoilF AS STRING 'This holds the name of the data files that are scrolled through when selecting CoilFile. DIM SHARED SkipSel AS INTEGER 'This holds whether to select the DatFileN or skip it. DIM SHARED Continue AS INTEGER 'This justs holds a dummy input. It's used to continue the program after an error message is given to user. DIM SHARED PntOrLin AS INTEGER 'holds whether to plot points or connect them into lines. 0 for points. 1 for lines. DIM SHARED FilNmeErr AS INTEGER 'Holds the error code for filename validity check. SCREEN 12 CLS 0 'Clears everything Intro CLS 0 'Clears everything '----------This initializes the variables.------------ GrphSize = 1 '1 = Big size. 0 = small size PntOrLin = 1 '1 = draw as lines. 0 = draw points iLimit = 7.5 'After a graph reaches this limit in amps, stop plotting that graph. tscale = .005 CoilName = "Coil 1" CoilFile = "out.txt" IF FileExists(CoilFile) = 1 THEN OPEN CoilFile FOR INPUT AS #1 ELSE VIEW PRINT 27 TO 30 PRINT CoilFile; INPUT " does not exist or was empty and now deleted. Press enter.", Continue END IF GrphColor = 9 'This initializes the color for the plot. Each successive plot changes color. Color choice is based what they will be after converting to 24bit, then gif, then inverted. '---------------------------------------------------- DrawScreen 'Setup the graphics port and print the graph scales. DrawGrid REM command section------------------------------------------------------------------------------- DO COLOR 7 VIEW PRINT 27 TO 30 CLS 2 PrintVar COLOR 15 PRINT "1 clear. 2 exit. 3 time scale. 4 vertical. 47 bitmap. 57 invertBitmap." PRINT "5 points. 6 lines. n coil name. f select file." INPUT " Or enter to plot. ", Comand$ CLS 2 IF Comand$ = "2" THEN SYSTEM ELSEIF Comand$ = "1" THEN CLS 0 DrawScreen DrawGrid ELSEIF Comand$ = "47" OR Comand$ = "57" THEN Color$ = Comand$ 'Color$ holds whether the colors should be as on the screen, or inverted. 57 is inverted. 47 is normal. DO 'The default name of the bmp will be the last file data name selected. Options in case it already exists. BMPname$ = LEFT$(CoilFile, LEN(CoilFile) - 4) 'BMPname$ will take the filename of the COilFile minus the period and filetype. BMPname$ = BMPname$ + ".BMP" 'add the filetype to the file name. BMPname$ = UCASE$(BMPname$) 'convert to upper case PRINT "Enter a new filename, or press enter to use "; BMPname$; " "; INPUT Comand$ IF Comand$ <> "" THEN 'If Comand$ is other than "", then... BMPname$ = UCASE$(Comand$) 'Convert comand$ to upper case and make it the BMPname$. IF RIGHT$(BMPname$, 4) = ".BMP" THEN 'if the filetype was already entered, then keep it. BMPname$ = BMPname$ ELSE BMPname$ = BMPname$ + ".BMP" 'Else add ".BMP" to the filename. END IF END IF FilNmeErr = ValidFilename(BMPname$) 'Check filename validity and print error warning. IF FilNmeErr > 0 THEN PRINT "Filename invalid. "; IF FilNmeErr = 1 THEN PRINT "Too long."; IF FilNmeErr = 2 THEN PRINT "Too short."; IF FilNmeErr = 3 THEN PRINT "Bad format."; IF FilNmeErr = 4 THEN PRINT "Bad character."; PRINT " Format => xxxxxxxx.xxx " ELSE IF FileExists(BMPname$) = 1 THEN 'Check if file already exists. FilNmeErr = 5 'set error code if exists INPUT "File already exists. Press enter to try another name, or o to overwrite it."; Comand$ END IF END IF LOOP WHILE FilNmeErr > 0 AND Comand$ <> "o" CLS 2 PRINT "A bitmap of this screen called "; BMPname$; " is being generated. Please wait. " 'the previously set VIEW and WINDOW commands have to be cleared for the sub to work. VIEW WINDOW CLOSE #1 'close the open text file ZZLou24bIT BMPname$, Color$ 'must now reinstate the VIEW and WINDOW DrawScreen VIEW PRINT 28 TO 30 CLS 2 LOCATE 29, 1 PRINT "Image file "; BMPname$; " is saved in the folder in which this program resides." INPUT "Enter to continue. ", Continue IF FileExists(CoilFile) = 1 THEN OPEN CoilFile FOR INPUT AS #1 'Re open text file for graphing ELSEIF Comand$ = "3" THEN VIEW PRINT 1 TO 30 'needed to expand the text port CLS 2 SetTscale CLS 0 DrawScreen DrawGrid ELSEIF Comand$ = "4" THEN IF GrphSize = 1 THEN 'this flips the graph size from big to small or vice versa. GrphSize = 0 ELSE GrphSize = 1 END IF CLS 0 DrawScreen DrawGrid ELSEIF Comand$ = "5" THEN PntOrLin = 0 'print as points. ELSEIF Comand$ = "6" THEN PntOrLin = 1 'print as lines. ELSEIF Comand$ = "n" THEN 'This overrides the coil name that was found on the CoilFile (assuming there was one). CLS 2 INPUT "Enter the name of the coil. ", CoilName ELSEIF Comand$ = "f" THEN SkipSel = 0 SHELL "dir > PXT4938.TXT" 'This is the temporary text file which contains the filenames within the current directory. OPEN "PXT4938.TXT" FOR INPUT AS #10 DO GetCoilFile 'Will set NewCoilF = "" if no data files found, or no more data files found. CLS 2 IF NewCoilF <> "" THEN 'If NewCoilF is valid... OPEN NewCoilF FOR INPUT AS #20 GetCoilName 'Try to get a coil name from the file NewCoilF. CLOSE #20 PRINT "Enter 0 to skip. Enter 1 to select." PRINT "Enter 2 to select without changing coil name." PRINT NewCoilF, NewCoilN; INPUT " ", SkipSel ELSE INPUT "No more data files. Press enter. ", Continue END IF LOOP WHILE SkipSel <> 1 AND SkipSel <> 2 AND NewCoilF <> "" 'Keep looping through txt files until 1 or 2 is selected, or if NewCoilF is blank. IF SkipSel = 1 THEN CoilFile = NewCoilF CoilName = NewCoilN ELSEIF SkipSel = 2 THEN CoilFile = NewCoilF END IF CLOSE #10 KILL "pxt4938.txt" CLOSE #1 'close the old file IF FileExists(CoilFile) = 1 THEN OPEN CoilFile FOR INPUT AS #1 'ELSE 'This section is redundant with not selecting a new file. ' CLS 2 ' Print CoilFile; ' INPUT " did not exist or was empty and now deleted. Hit enter.", Continue END IF ELSEIF Comand$ = "" THEN IF FileExists(CoilFile) = 1 THEN 'GrphColor = GrphColor + 1 'plot color increment now happens in plot function IF GrphColor = 15 THEN GrphColor = 9 COLOR GrphColor IF GrphSize = 1 THEN VIEW PRINT 21 TO 27 IF GrphSize = 0 THEN VIEW PRINT 12 TO 27 LOCATE 26 PRINT "" 'This allows the maintaining of text and scroll up. Otherwise every view/locate command will overwrite. 'PRINT CoilName, CoilFile 'Printing of the coil file name is now being done in the plot function. Plot ELSE VIEW PRINT 27 TO 30 PRINT CoilFile; INPUT " does not exist or was empty and now deleted. Hit enter. ", Continue END IF END IF LOOP REM command section--------------------------------------------------------------------- SUB DrawGrid '-------------DrawGrid------------------------------------------------------ COLOR 8 IF GrphSize = 1 THEN 'draw 1/4 amp lines on the big screen FOR y = 9 TO 0 STEP -.25 LINE (0, y)-(tscale, y) 'draws horizontal gray lines NEXT y END IF FOR y = 9 TO 0 STEP -.5 'draws 1/2 amp lines LINE (0, y)-(tscale, y) 'draws horizontal gray lines NEXT y IF tscale = .005 THEN FOR x = 0 TO tscale + tscale / 100 STEP tscale / 50 'draws 1/100 time lines LINE (x, 0)-(x, 9) 'draws vertical gray lines NEXT x ELSE FOR x = 0 TO tscale + tscale / 100 STEP tscale / 100 'draws 1/100 time lines LINE (x, 0)-(x, 9) 'draws vertical gray lines NEXT x END IF COLOR 7 FOR y = 9 TO 0 STEP -1 'draws 1 amp lines LINE (0, y)-(tscale, y) 'draws horizontal gray lines NEXT y IF tscale = .02 THEN FOR x = 0 TO tscale + tscale / 10 STEP tscale / 20 'draws 1/20 time lines LINE (x, 0)-(x, 9) 'draws vertical gray lines NEXT x ELSE FOR x = 0 TO tscale + tscale / 10 STEP tscale / 10 'draws 1/10 time lines LINE (x, 0)-(x, 9) 'draws vertical gray lines NEXT x END IF COLOR 15 LINE (0, 0)-(tscale, 0) 'adds horizontal zero line in white LINE (0, 0)-(0, 9) 'vertical zero line in white END SUB'-------------------DrawGrid-------------------------------------------------------- SUB DrawScreen '---------------------------DrawScreen----------------------------------- 'The graphics port is set to leave room to the left and bottom for scale indicators. 'Vertically, 0-368 gives 23 spaces, but 1/2 is wasted on top and 1/2 is wasted on bottom to leave room for the scale numbers so the center of the number lines up with the graph lines. 'The graph is broken into 22 useable spaces vertically with a 1/2 unused on top, and 1/2 unused on bottom for a total of 23, and the scale gets 22 numbers. 'It has to be that way in order for the vertical scale numbers to line up. 'Vertically, one line of text takes 16 vertical pixels. 368/23 = 16 . 'If more vertical space is needed at the bottom for text, the graph loses 16 pixels per line. IF GrphSize = 1 THEN VIEW (39, 0)-(639, 304) 'must be 601 by 305 (The View and Window commands are also reinstated after bitmap generator call.) WINDOW (0, 9.25)-(tscale, -.25) VIEW PRINT 1 TO 21 END IF IF GrphSize = 0 THEN VIEW (39, 0)-(639, 160) 'must be 601 by 161 WINDOW (0, 9.5)-(tscale, -.5) VIEW PRINT 1 TO 12 END IF 'Show the scale numbers of the y axis. 'note: using "PRINT USING" command to force the formatting. Without it, extra spaces get printed. LOCATE 1, 1 FOR y = 9 TO 0 STEP -1 PRINT USING "##"; y; PRINT " A" IF GrphSize = 1 THEN PRINT "" 'prints a blank line if drawing the big size screen NEXT y IF GrphSize = 1 THEN LOCATE 20, 1 IF GrphSize = 0 THEN LOCATE 11, 1 IF tscale = .0001 THEN PRINT " 0msec .01ms .02ms .03ms .04ms .05ms .06ms .07ms .08ms .09ms .1ms" IF tscale = .001 THEN PRINT " 0sec .0001 .0002 .0003 .0004 .0005 .0006 .0007 .0008 .0009 .001" IF tscale = .005 THEN PRINT " 0sec .0005 .0010 .0015 .0020 .0025 .0030 .0035 .0040 .0045 .005" IF tscale = .01 THEN PRINT " 0sec .001 .002 .003 .004 .005 .006 .007 .008 .009 .01" IF tscale = .02 THEN PRINT " 0sec .002 .004 .006 .008 .010 .012 .014 .016 .018 .02" IF tscale = .1 THEN PRINT " 0sec .01 .02 .03 .04 .05 .06 .07 .08 .09 .1" IF tscale = 1 THEN PRINT " 0sec .1 .2 .3 .4 .5 .6 .7 .8 .9 1" IF tscale = 10 THEN PRINT " 0sec 1 2 3 4 5 6 7 8 9 10" IF tscale = 100 THEN PRINT " 0sec 10 20 30 40 50 60 70 80 90 100" IF tscale = 1000 THEN PRINT " 0sec 100 200 300 400 500 600 700 800 900 1000" IF tscale = 10000 THEN PRINT " 0sec 1k 2k 3k 4k 5k 6k 7k 8k 9k 10k" END SUB'--------------------------------------DrawScreen---------------------------------------- FUNCTION FileExists (FileName$) '-----------------FileExists-------------------- 'Checks to see if the file exists. Returns 1 if exists. 0 if not. (Note, if the file existed, but was empty, this reports it did not exist and then deletes it.) FileExists = 0 OPEN FileName$ FOR BINARY AS #99 'open or create it, to measure it FileLen& = LOF(99) 'measure it IF FileLen& > 0 THEN 'if it's not empty, report it exists FileExists = 1 CLOSE #99 ELSE CLOSE #99 'if empty, close it. KILL FileName$ 'delete it. END IF END FUNCTION '------------------FileExists---------- SUB GetCoilFile '-------------GetCoilFile--------------------------- 'This reads the temporary text file (pxt4938.txt) containing directory information, as #10. 'It sets NewCoilF to the next txt file in the directory. 'If the end is reached before a txt file is found, then NewCoilF = "" NewCoilF = "" 'Clear NewCoilF DO LINE INPUT #10, DirLine$ 'Read a line IF MID$(DirLine$, 10, 3) = "TXT" THEN 'If the line contains the name of a text file (chars 10, 11, 12 are "TXT")... NewCoilF = MID$(DirLine$, 1, 8) NewCoilF = RTRIM$(NewCoilF) NewCoilF = NewCoilF + ".TXT" 'first 8 chars of line is possible new coil file. END IF IF NewCoilF = "PXT4938.TXT" THEN NewCoilF = "" 'The temporary directory file should be ignored. LOOP WHILE EOF(10) = 0 AND NewCoilF = "" 'Loop until reach end of file, or NewCoilF is a valid file. END SUB '--------------------GetCoilFile---------------- SUB GetCoilName '-------------GetCoilName--------------------------- 'this extracts the NewCoilN (possible new coil name) from the NewCoilF (possible new coil file). NewCoilN = "" 'Clear NewCoilN LINE INPUT #20, FileLine$ 'Read a line IF MID$(FileLine$, 1, 4) = "NAME" THEN 'If the first 4 chars of the first line contains the word "NAME"... NewCoilN = MID$(FileLine$, 5, 60) 'first 200 chars of line (after the first 4) is possible new coil name. NewCoilN = RTRIM$(NewCoilN) NewCoilN = LTRIM$(NewCoilN) END IF END SUB '--------------------GetCoilName---------- SUB Intro '----------------------Intro-------------------------------- PRINT "This program plots current versus time for ignition coils. The input values" PRINT "come from a text file produced by a coil test circuit sampled by an Arduino" PRINT "microcontroller. The sampler measures voltage on a resistor to get current" PRINT "data. The data is actually voltage, but this program will convert it to" PRINT "current. Each data point has a voltage value and time value. The time value" PRINT "is the number of microseconds since the voltage was applied to the coil." PRINT "Timescale can be changed, and the current scale can be changed to produce" PRINT "two different size graphs. The graph itself can be sampled points only," PRINT "or made up of lines connecting the points. The program plots one sample" PRINT "cycle at a time, but the text file can contain multiple cycles. It will plot" PRINT "them in the order they exist in the file. When it reaches the end of the file," PRINT "it will plot a blank plot, then repeat the cycles after that. If there is an" PRINT "incomplete set of data before the end of the file, it will simply stop plotting." PRINT "After any plot, a new name for the next plot can be given, and/or a new" PRINT "file can be chosen to take data from." PRINT "The X axis is time in seconds." PRINT "The Y axis is current in amps." PRINT "Printing: This progam can generate a bitmap file of the screen. The files" PRINT "will be saved in the folder in which this program resides. If it will be " PRINT "printed out, there is also an option to invert the colors, which will show up" PRINT "better on paper. The files will be in 24bit format BMP. This should be " PRINT "opened in MSpaint, then saved as a 256 color BMP, then saved as a gif." INPUT "Enter to continue. ", Continue END SUB'----------------------Intro---------------------------------- SUB Plot '--------------------- Plot --------------------------- 'This sub reads the file and converts it to point to plot. DIM t AS DOUBLE 'time in seconds DIM v AS SINGLE 'sample value (0 to 1023) then converted to voltage in volts DIM i AS SINGLE 'current in amps DIM Char AS STRING 'holds the character being read. DO UNTIL (EOF(1)) OR Char = "&" 'loop until the end of file #1 is reached, or end of cycle is reached. Char = INPUT$(1, #1) 'this line reads the next character in the file. IF Char = "$" THEN '$ means start of sample cycle. PSET (0, 0) 'plot a point at the origin. DO UNTIL Char = "&" 'loop until the end of sample cycle is reached Char = INPUT$(1, #1) 'this line reads the next character in the file. IF Char = "t" THEN 'if character is a t, then next number is time (in usec) INPUT #1, t 'read the number as time, and the "," Char = INPUT$(1, #1) 'this line reads the next character in the file. IF Char = "v" THEN 'verify that "v" is next char INPUT #1, v 'read the number as raw sample data for current, and the "," t = t / 1000000 'put t into seconds from usec IF t > (2# * tscale) THEN t = 2# * tscale 'prevents plots from wrapping around due to being too far off scale (like checkrange for t) v = v * 1.1 / 1023 'the correction for v will be complicated i = v * 10 'current is just 10 times the voltage IF i <= iLimit OR t < .00008 THEN 'if the current is less than the limit set by iLimit, or time is less than 80usec... then plot. The time factor allows for plotting graphs that have a glitch at the beginning of max current. IF PntOrLin = 0 THEN 'if PntOrLin is 0, plot points PSET (t, i) 'plot point ELSEIF PntOrLin = 1 THEN 'if PntOrLin is 1, plot lines LINE STEP(0, 0)-(t, i) 'Step (0,0) means draw line from current cursor position END IF ELSE DO UNTIL (EOF(1)) OR Char = "&" 'If the current goes above iLimit, then end the set by reading all characters until "&" or EOF. Char = INPUT$(1, #1) 'read next character in file LOOP END IF ELSE VIEW PRINT 28 TO 30 CLS 2 INPUT "Data error. Not v. Hit enter. ", Continue 'if it was not "v" then it is an error. Char = "&" 'setting Char to e will exit graphing loop END IF ELSEIF Char = "&" OR Char = " " OR Char = CHR$(13) OR Char = CHR$(10) THEN 'do nothing. skip "&", spaces, Carriage return (CR), and Line feeds (LF) ELSE VIEW PRINT 28 TO 30 CLS 2 INPUT "Data error. Not t. Hit enter. ", Continue 'if it was not "t" then it is an error. Char = "&" 'setting Char to & will exit graphing loop END IF LOOP PRINT CoilName, CoilFile GrphColor = GrphColor + 1 END IF LOOP IF (EOF(1)) THEN 'if the end of the file was reached CLOSE #1 'close the file OPEN CoilFile FOR INPUT AS #1 're-open the file END IF END SUB '---------------------------Plot---------------------------------------- SUB PrintVar '---------------------------PrintVar--------------- 'Just prints whether it will be line or point plot, then coil's name, and data file's name. IF PntOrLin = 0 THEN PRINT "Point plot. "; IF PntOrLin = 1 THEN PRINT "Line plot. "; 'PRINT CoilFile, CoilName 'Not enough room to print CoilFile and everything else. PRINT CoilName END SUB '--------------------------------PrintVar---------------- SUB SetTscale '----------------------------SetTscale------------------------------- PRINT " Eleven different time scales can be chosen from." PRINT "0 to .0001 sec." PRINT "0 to .001 sec." PRINT "0 to .005 sec." PRINT "0 to .01 sec." PRINT "0 to .02 sec." PRINT "0 to .1 sec." PRINT "0 to 1 sec." PRINT "0 to 10 sec." PRINT "0 to 100 sec." PRINT "0 to 1000 sec." PRINT "0 to 10,000 sec." DO INPUT "Enter the number of seconds for the x axis (default is .005). ", tscale LOOP WHILE tscale < 0 IF tscale = 0 THEN tscale = .005 'default case ELSEIF tscale < .00011 THEN tscale = .0001 ELSEIF tscale < .0011 THEN tscale = .001 ELSEIF tscale < .0051 THEN tscale = .005 ELSEIF tscale < .011 THEN tscale = .01 ELSEIF tscale < .021 THEN tscale = .02 ELSEIF tscale < .11 THEN tscale = .1 ELSEIF tscale < 1.1 THEN tscale = 1 ELSEIF tscale < 11 THEN tscale = 10 ELSEIF tscale < 110 THEN tscale = 100 ELSEIF tscale < 1100 THEN tscale = 1000 ELSE tscale = 10000 END IF END SUB'----------------------------SetTscale------------------------------- FUNCTION subtract# (aaa#, bbb#) '---------------Subtraction function-------------- ' The purpose of this function is to avoid loss-of-significance errors. ' subtract# = aaa# - bbb# ' But, if both aaa and bbb are positive or both negative, then loss-of-sig is possible. ' In that case, check the ratio of aaa to bbb, and bbb to aaa. (Use different ratio for Double and Single precision math.) ' If too close, then loss of sig is going to happen. ' In that case, subtract# = 0. subtract# = aaa# - bbb# IF (aaa# > 0# AND bbb# > 0#) OR (aaa# < 0# AND bbb# < 0#) THEN IF ((aaa# / bbb#) < 1.0000000000001# AND (aaa# / bbb#) > 1#) OR ((bbb# / aaa#) < 1.0000000000001# AND (bbb# / aaa#) > 1#) THEN subtract# = 0 END IF END IF END FUNCTION'----------------------------------Subtraction function-------------- FUNCTION ValidFilename (FileName$) '------- Function ValidFilename --------------- 'This sub checks to make sure a file name is valid. 'It returns an error code based on what's wrong. 'It assumes the 8.3 (8 chars plus 3 char filetype) convention for file names. '0 = valid file name '1 = too long '2 = too short '3 = period not in 4th place from right '4 = invalid character used ValidFilename = 0 IF LEN(FileName$) > 12 THEN ValidFilename = 1 '1=Filename too long. ELSEIF LEN(FileName$) < 5 THEN ValidFilename = 2 '2=Filename too short. ELSEIF MID$(RIGHT$(FileName$, 4), 1, 1) <> "." THEN ValidFilename = 3 '3=No period to separate filetype. ELSE 'If there is no length error or period error, check each character FOR Char = 1 TO LEN(FileName$) - 4 'this loop checks the characters in the name CharAsc = ASC(MID$(FileName$, Char, 1)) 'this gets the acsii value for each character IF CharAsc < 48 OR CharAsc > 122 THEN 'if outside the ascii range for alpha-numeric ValidFilename = 4 '4=invalid character ELSEIF CharAsc > 57 AND CharAsc < 65 THEN 'if greater than numerals, and less than upper case ValidFilename = 4 '4=invalid character ELSEIF CharAsc > 90 AND CharAsc < 95 THEN 'if greater than upper case, and less than underscore ValidFilename = 4 '4=invalid character ELSEIF CharAsc > 95 AND CharAsc < 97 THEN 'if greater than underscore, and less than lower case ValidFilename = 4 '4=invalid character END IF NEXT Char FOR Char = LEN(FileName$) - 2 TO LEN(FileName$) 'This loop checks the filetype characters CharAsc = ASC(MID$(FileName$, Char, 1)) 'this gets the acsii value for each character IF CharAsc < 48 OR CharAsc > 122 THEN 'if outside the ascii range for alpha-numeric ValidFilename = 4 '4=invalid character ELSEIF CharAsc > 57 AND CharAsc < 65 THEN 'if greater than numerals, and less than upper case ValidFilename = 4 '4=invalid character ELSEIF CharAsc > 90 AND CharAsc < 95 THEN 'if greater than upper case, and less than underscore ValidFilename = 4 '4=invalid character ELSEIF CharAsc > 95 AND CharAsc < 97 THEN 'if greater than underscore, and less than lower case ValidFilename = 4 '4=invalid character END IF NEXT Char END IF END FUNCTION'----------------------ValidFilename------------------------- SUB ZZLou24bIT (FileName$, invertBW$) '------------------ Sub zzLou24Bit bmp generator ------------------- 'This SUB is designed to hold the colors true to the original ' qbasic colors, or close to them. But will not convert nicely ' to .gif in MSpaint, so first covert to 8-bit (256 colors) BMP in ' MS paint, then convert to gif in MSpaint. 'Make sure the filename is 8char or less and ".BMP" 'This section sets the header data FileTYPE$ = "BM" 'in hex it's &H42 &H4D, but will use ascii representation instead FileSIZE& = &HE1036 'file size is 921654 bytes. In hex it's E1036. Reserved1% = &H0 'always 0 Reserved2% = &H0 'always 0 OffsetBITS& = &H36 'offset tells where the pixel data begins. With a 24 bit bitmap, it starts at &H36 InfoHEADER& = &H28 'always &H28 PictureWIDTH& = &H280 '640 wide PictureHeight& = &H1E0 '480 height NumPLANES% = &H1 BPP% = &H18 '24 bits. In hex, 24 is &H18 Compression& = 0 ImageSIZE& = &HE1000 'image size is 921600 bytes. in hex it's E1000 WidthPELS& = 0 ' always 0. Bob had 3780 DepthPELS& = 0 ' always 0. Bob had 3780 NumCOLORS& = 0 ' 0 when in 24 bits. 16 if in 4 bits. SigCOLORS& = 0 ' 0 means all colors significant. OPEN FileName$ FOR BINARY AS #1 'this section prints header data in binary PUT #1, , FileTYPE$ PUT #1, , FileSIZE& PUT #1, , Reserved1% 'should be zero PUT #1, , Reserved2% 'should be zero PUT #1, , OffsetBITS& PUT #1, , InfoHEADER& PUT #1, , PictureWIDTH& PUT #1, , PictureHeight& PUT #1, , NumPLANES% PUT #1, , BPP% PUT #1, , Compression& PUT #1, , ImageSIZE& PUT #1, , WidthPELS& PUT #1, , DepthPELS& PUT #1, , NumCOLORS& PUT #1, , SigCOLORS& IF invertBW$ = "57" THEN 'invert some colors FOR y = 479 TO 0 STEP -1 'bitmaps code from bottom to top FOR x = 0 TO 639 STEP 1 'bitmaps code from left to right Colr% = POINT(x, y) 'POINT returns the color at the given pixel coordinates IF Colr% = 0 THEN 'black to white red$ = CHR$(&HFF): grn$ = CHR$(&HFF): blu$ = CHR$(&HFF) ELSEIF Colr% = 1 THEN 'dark blue to blue red$ = CHR$(&H0): grn$ = CHR$(&H0): blu$ = CHR$(&HFF) ELSEIF Colr% = 2 THEN 'dark green to green red$ = CHR$(&H0): grn$ = CHR$(&HFF): blu$ = CHR$(&H0) ELSEIF Colr% = 3 THEN 'dark cyan to cyan red$ = CHR$(&H0): grn$ = CHR$(&HFF): blu$ = CHR$(&HFF) ELSEIF Colr% = 4 THEN 'dark red to red red$ = CHR$(&HFF): grn$ = CHR$(&H0): blu$ = CHR$(&H0) ELSEIF Colr% = 5 THEN 'dark magenta to magenta red$ = CHR$(&HFF): grn$ = CHR$(&H0): blu$ = CHR$(&HFF) ELSEIF Colr% = 6 THEN 'dark yellow to yellow red$ = CHR$(&HFF): grn$ = CHR$(&HFF): blu$ = CHR$(&H0) ELSEIF Colr% = 7 THEN 'light grey to dark grey red$ = CHR$(&H80): grn$ = CHR$(&H80): blu$ = CHR$(&H80) ELSEIF Colr% = 8 THEN 'dark grey to light grey red$ = CHR$(&HC0): grn$ = CHR$(&HC0): blu$ = CHR$(&HC0) ELSEIF Colr% = 9 THEN 'blue to dark blue red$ = CHR$(&H0): grn$ = CHR$(&H0): blu$ = CHR$(&H80) ELSEIF Colr% = 10 THEN 'green to dark green red$ = CHR$(&H0): grn$ = CHR$(&H80): blu$ = CHR$(&H0) ELSEIF Colr% = 11 THEN 'cyan to dark cyan red$ = CHR$(&H0): grn$ = CHR$(&H80): blu$ = CHR$(&H80) ELSEIF Colr% = 12 THEN 'red to dark red red$ = CHR$(&H80): grn$ = CHR$(&H0): blu$ = CHR$(&H0) ELSEIF Colr% = 13 THEN 'magenta to dark magenta red$ = CHR$(&H80): grn$ = CHR$(&H0): blu$ = CHR$(&H80) ELSEIF Colr% = 14 THEN 'yellow to dark yellow red$ = CHR$(&H80): grn$ = CHR$(&H80): blu$ = CHR$(&H0) ELSE 'Colr% = 15 then 'white to black red$ = CHR$(&H0): grn$ = CHR$(&H0): blu$ = CHR$(&H0) END IF PUT #1, , blu$ PUT #1, , grn$ PUT #1, , red$ 'no byte padding needed. (640 x 3 bytes = 1920 bytes. Bytes must be stacked in groups of four. Luckily 1920 divides by 4 evenly.) NEXT x NEXT y ELSE 'use original colors FOR y = 479 TO 0 STEP -1 'bitmaps code from bottom to top FOR x = 0 TO 639 STEP 1 'bitmaps code from left to right Colr% = POINT(x, y) 'POINT returns the color at the given pixel coordinates IF Colr% = 0 THEN 'black red$ = CHR$(&H0): grn$ = CHR$(&H0): blu$ = CHR$(&H0) ELSEIF Colr% = 1 THEN 'dark blue red$ = CHR$(&H0): grn$ = CHR$(&H0): blu$ = CHR$(&H80) ELSEIF Colr% = 2 THEN 'dark green red$ = CHR$(&H0): grn$ = CHR$(&H80): blu$ = CHR$(&H0) ELSEIF Colr% = 3 THEN 'dark cyan red$ = CHR$(&H0): grn$ = CHR$(&H80): blu$ = CHR$(&H80) ELSEIF Colr% = 4 THEN 'dark red red$ = CHR$(&H80): grn$ = CHR$(&H0): blu$ = CHR$(&H0) ELSEIF Colr% = 5 THEN 'dark magenta red$ = CHR$(&H80): grn$ = CHR$(&H0): blu$ = CHR$(&H80) ELSEIF Colr% = 6 THEN 'dark yellow red$ = CHR$(&H80): grn$ = CHR$(&H80): blu$ = CHR$(&H0) ELSEIF Colr% = 7 THEN 'light grey red$ = CHR$(&HC0): grn$ = CHR$(&HC0): blu$ = CHR$(&HC0) ELSEIF Colr% = 8 THEN 'dark grey red$ = CHR$(&H80): grn$ = CHR$(&H80): blu$ = CHR$(&H80) ELSEIF Colr% = 9 THEN 'blue red$ = CHR$(&H0): grn$ = CHR$(&H0): blu$ = CHR$(&HFF) ELSEIF Colr% = 10 THEN 'green red$ = CHR$(&H0): grn$ = CHR$(&HFF): blu$ = CHR$(&H0) ELSEIF Colr% = 11 THEN 'cyan red$ = CHR$(&H0): grn$ = CHR$(&HFF): blu$ = CHR$(&HFF) ELSEIF Colr% = 12 THEN 'red red$ = CHR$(&HFF): grn$ = CHR$(&H0): blu$ = CHR$(&H0) ELSEIF Colr% = 13 THEN 'magenta red$ = CHR$(&HFF): grn$ = CHR$(&H0): blu$ = CHR$(&HFF) ELSEIF Colr% = 14 THEN 'yellow red$ = CHR$(&HFF): grn$ = CHR$(&HFF): blu$ = CHR$(&H0) ELSE 'Colr% = 15 then 'white red$ = CHR$(&HFF): grn$ = CHR$(&HFF): blu$ = CHR$(&HFF) END IF PUT #1, , blu$ PUT #1, , grn$ PUT #1, , red$ 'no byte padding needed. (640 x 3 bytes = 1920 bytes. Bytes must be stacked in groups of four. Luckily 1920 divides by 4 evenly.) NEXT x NEXT y END IF CLOSE #1 END SUB '------------------ End Sub zzLou24Bit bmp generator ------------------