Trying to go from a typed in file name as a string like "TEST.BAS" into "TEST BAS" to find the file in the directory. The string functions didn't work as expected.
DIM A$(11) - Allocates string space for the output string
Inserting characters didn't work. Code to test:
6000 REM STRING STUFF 6010 DIM A$(8) 6020 PRINT A$ 6030 PRINT LEN(A$) 6040 A$(1)="X" 6050 PRINT A$ 6060 PRINT LEN(A$)
Produces no string. This should be relatively easy to solve in assembly so the problem can be ignored for the moment by just typing in the file name with spaces to pad the file name to 8 characters and 3 character extension.
Working on the BASIC code to find a file offset from a file name. Let's look through the directory for "STARS BAS" which is on the disk. String matching does work.
7000 A$="TEST BAS" 7010 B$="TEST BAS" 7020 IF A$=B$ THEN PRINT "OK-MATCH" 7030 IF A$<>B$ THEN PRINT "MATCH ERROR" 7040 B$="TEST2 BAS" 7050 IF A$<>B$ THEN PRINT "OK-DOES NOT MATCH" 7060 IF A$=B$ THEN PRINT "DOES NOT MATCH ERROR"
Produces OK messages. But how can the file name be extracted into a string without the first method? This simple function does not work as expected.
7000 A$="TEST BAS" 7010 PRINT A$(1)
Can the individual characters be converted to numbers and compared?
MID$ does seem to work. This function pulls out characters and turns them into their numeric equivalent.
7000 A$="TEST BAS" 7010 C$=MID$(A$,1,1) 7020 PRINT ASC(C$) 7030 C$=MID$(A$,2,1) 7040 PRINT ASC(C$)
This produces 84,69 as expected. The reverse function works so it could be used one character at a time.
7000 A$="TEST BAS" 7010 C$=MID$(A$,1,1) 7020 PRINT ASC(C$) 7030 C$=MID$(A$,2,1) 7040 N=ASC(C$) 7050 PRINT N 7060 PRINT CHR$(N)
This turns the second character back into the string value which can be used to compare to the value in the buffer. This code matches like it should.
6000 A$="TEST BAS" 6010 DIM B(20) 6020 V$="T" 6030 B(5)=ASC(V$) 6040 C$=MID$(A$,1,1) 6050 X=ASC(C$) 6060 IF X=B(5) THEN PRINT "OK-MATCHES"
So the method is to pull the character out of the buffer, convert the character to ASCII number then compare it to the value of the string. This is painful but works. Here's the code.
265 Q$="STARS BAS" 6010 CM=1 6020 FOR I=1 TO 10 6030 SE=ASC(MID$(Q$,I,1)) 6040 IF MA(DF+I-1)<>SE THEN CM=0 6050 NEXT I 6060 IF CM=1 THEN PRINT "FILE FOUND" 6190 RETURN
This returns:
SPLAT.BAS 4942 CLUSTER OFFSET 150 FILE FOUND STARS.BAS 1590 CLUSTER OFFSET 151 STARTR~1.BAS 8481 CLUSTER OFFSET 152
For some unknown reason typing in 151 does not work. Smaller numbers are OK. Looking for WAR returned 112 which did get the correct file. Added code to prompt fpor a file name and if that file name was found in the directory then print the first block of the file. Name still has to be entered with spaces but this same method could work for comparisons.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.