By Deano

File Selector Source

This is the File Selector Routine that I programmed for my Grafix Art Art package. Feel free to use it in your own programs.

2240 rem FILE SELECTOR
2250 wipe S5 : unpack S2+33020,S5 : get palette (5) : wait vbl : A=0 : PRE_Y=0 : PR$=”” 2260 fastcopy S5,back : fastcopy S5,logic : K=1
2270 if LO=1 then T$=”LOAD A PICTURE” : pen 15 : locate 14,23 : print T$
2280 if SA=1 then T$=”SAVE A PICTURE” : pen 15 : locate 14,23 : print T$
2290 T$=right$(PATH$,4) : locate 24,7 : pen 15 : print T$ : fastcopy logic,back
2300 rem
2310 blit S5,96,52,160,64,back,96,52 : blit S5,96,52,160,64,logic,96,52 : wash back,112,72,224,152
2320 if drive=0 then logic=S3 : ink 15 : bar 2,2 to 30,30 : paper 15 : pen 0 : locate 1,1 : print “A” : logic=physic : ppsc S3,logic,3,7,20,15,107,55,4 : paper 0 2330 if drive=1 then logic=S3 : ink 15 : bar 2,2 to 30,30 : paper 15 : pen 0 : locate 1,1 : print “B” : logic=physic : ppsc S3,logic,3,7,20,15,132,55,4 : paper 0 2340 fastcopy logic,back
2350 dir$=”\” : DD$=””
2360 blit S5,16,32,208,41,back,16,32 : blit S5,16,32,208,41,logic,16,32
2370 for X=0 to 500 : FILE$(X)=”” : IDEN(X)=0 : F_NAME$(X)=”” : E$(X)=”” : POS(X)=0 : next X 2380 FILE=0 : FI=8 : POS=0 : S=0 : wash back,112,72,224,152 : wash logic,112,72,224,152 2390 rem GET FOLDERS
2400 P$=”*.*” : N$=dir first$(P$,-1)
2410 if mid$(N$,43,1)=”8” then N$=dir next$
2420 if left$(N$,1)=”.” then N$=dir next$ 2430 if left$(N$,2)=”..” then N$=dir next$
2440 D$=mid$(N$,43,2) : if D$=”16” then inc FILE : F_NAME$(FILE)=left$(N$,12) : gosub 2740 : FILE$(FILE)=left$(N$,12) : IDEN(FILE)=1 2450 repeat
2460 N$=dir next$
2470 D$=mid$(N$,43,2) : if D$=”16” then inc FILE : F_NAME$(FILE)=left$(N$,12) : gosub 2740 : FILE$(FILE)=left$(N$,12) : IDEN(FILE)=1 2480 until N$=””
2490 rem GET FILES
2500 P$=PATH$ : N$=dir first$(P$,-1)
2510 D$=mid$(N$,43,2) : if D$<>”16” then inc FILE : F_NAME$(FILE)=left$(N$,12) : gosub 2740 : FILE$(FILE)=left$(N$,12) : IDEN(FILE)=2 2520 repeat
2530 N$=dir next$
2540 D$=mid$(N$,43,2) : if D$<>”16” then inc FILE : F_NAME$(FILE)=left$(N$,12) : gosub 2740 : FILE$(FILE)=left$(N$,12) : IDEN(FILE)=2 2550 until N$=””
2560 rem NOW LIST THEM IN THE FILE SELECTOR
2570 for Y=1 to FILE
2580 T$=FILE$(Y+S)+chr$(0) : text back,0,varptr(T$),15,Y+FI
2590 if IDEN(Y+S)=1 then T$=”*”+chr$(0) : text back,0,varptr(T$),14,Y+FI
2600 if POS<10 then inc POS : POS(POS)=POS
2610 if Y=10 then goto 2630
2620 next Y
2630 blit back,112,72,224,152,logic,112,72 : paper 0
2640 rem SET ZONES
2650 set zone 1,233,68 to 255,84
2660 set zone 2,233,140 to 255,154
2670 set zone 3,112,70 to 224,152
2680 set zone 4,167,156 to 228,170
2690 set zone 5,155,49 to 176,61
2700 set zone 6,106,157 to 163,168
2705 set zone 7,105,53 to 120,64
2710 set zone 8,131,47 to 150,60
2720 set zone 9,103,32 to 200,46 : show on 2725 if LO=1 then reset zone 9
2726 goto 2860
2740 rem SPACE FILE NAMES FOR FILE SELECTOR 2750 D=instr(N$,”.”) : if D=0 then return
2760 A$=left$(N$,D-1) : E$(FILE)=mid$(N$,D+1,3) : E$=mid$(N$,D+1,3) 2770 if len(A$)=1 then SP=8
2780 if len(A$)=2 then SP=7
2790 if len(A$)=3 then SP=6
2800 if len(A$)=4 then SP=5
2810 if len(A$)=5 then SP=4
2820 if len(A$)=6 then SP=3
2830 if len(A$)=7 then SP=2
2840 if len(A$)=8 then SP=1
2850 N$=”” : N$=A$+space$(SP-1)+”.”+E$ : return 2860 rem GET NAME AND POSITION OF LAST FILE SELECTED 2870 if A>7 then PRE_Y=A : PR$=FILE$(A-8+S)
2880 rem WAIT FOR CHOICE
2890 repeat : M=mouse key : CH=zone(0) : wait vbl : until M and CH<>0 2900 rem CHOICE SELECTED
2910 if M=1 and CH=1 and S>0 then dec S : dec POS
2920 if M=1 and CH=2 and S<FILE-11 then inc S : inc POS : POS(POS)=POS 2930 if M=1 and CH=3 then A=ytext(y mouse) : H=POS(A-8+S) : goto 3090 2940 if M=1 and CH=4 and FF$<>”” then goto 3140
2950 if M=1 and inkey$=chr$(13) and FF$<>”” then goto 3140
2960 if M=1 and CH=4 and FF$=”” then goto 2880
2970 if M=1 and inkey$=chr$(13) and FF$=”” then goto 2850
2980 if M=1 and CH=5 and FOLD=1 then hide on : goto 3350 2990 if M=1 and CH=5 and FOLD=0 then hide on : goto 2300 3000 if M=1 and CH=5 and FOLD=0 then goto 2890
3010 if M=1 and CH=6 then hide on : cls : wipe S5 : wipe S3 : unpack S2,S5 : floodpal 0 : wait vbl : fastcopy S7,S3 : goto 220 3020 if M=1 and CH=8 and drvmap<3 then goto 2560
3030 if M=1 and CH=7 then hide on : drive$=”A:” : goto 2310
3040 if M=1 and CH=8 then hide on : drive$=”B:” : goto 2310
3050 if M=1 and CH=9 then goto 3400
3060 rem UPDATE SCREEN
3070 wash back,112,72,224,152
3080 goto 2560
3090 rem HIGHLIGHT THE OPTION
3100 paper 0 : pen 15 : locate 15,PRE_Y : print PR$
3110 inverse on : locate 15,A : F$=FILE$(A-8+S) : FF$=F_NAME$(A-8+S) : pen 15 : print F$ : inverse off
3120 pen 15 : locate 13,4 : A$=left$(F$,8) : print A$ : locate 21,4 : A$=” “+right$(F$,3) : print A$ : wait 10 3130 goto 2870
3140 rem IF FILE IS A FOLDER THEN OPEN IT AND LIST FILES
3150 for X=1 to FILE
3160 K$=F_NAME$(X) : if K$=FF$ and IDEN(X)=1 then FOLD=1 : P$=”” : goto 3300
3170 next X : FOLD=0
3180 if SA=1 then goto 3550
3190 if LO=1 and PATH$=”*.PI1” then hide on : wait 10 : load FF$ : SCR$(SC)=”” : SCR$(SC)=screen$(logic,0,0 to 330,200) : gosub 3220 : wait 100 : cls : wipe S3 : wipe S5 : unpack S2,S5 : floodpal 0 : wait vbl : fastcopy S7,S3 : goto 220 3200 if LO=1 and PATH$=”*.NEO” then hide on : wait 10 : load FF$ : SCR$(SC)=”” : SCR$(SC)=screen$(logic,0,0 to 330,200) : gosub 3220 : wait 100 : cls : wipe S3 : wipe S5 : unpack S2,S5 : floodpal 0 : wait vbl : fastcopy S7,S3 : goto 220 3210 if LO=1 and PATH$=”*.GRX” then hide on : goto 3260
3220 for COCO=0 to 15 : C0L$(SC,COCO)=”” : next COCO
3230 for COCO=0 to 15 : C0L$(SC,COCO)=hex$(colour(COCO)) : next COCO 3240 return
3260 rem
3270 reserve as work 10,20000 : fill start(10) to start(10)+length(10),0
3280 bload FF$,10 : crack unpac start(10),logic,0 : wait 100 : SCR$(SC)=”” : SCR$(SC)=screen$(logic,0,0 to 330,200) : erase 10 : gosub 3220 3290 cls : unpack S2,S5 : floodpal 0 : wait vbl : fastcopy S7,S3 : goto 220
3300 rem OPEN THE FOLDER
3310 gosub 3390
3320 dir$=”\”+DD$
3330 wash back,112,72,224,152
3340 P$=”*.*” : goto 2360
3350 rem MOVE BACK TO PREVIOUS PATH
3360 dir$=”\” : DD$=””
3370 wash back,112,72,224,152
3380 FOLD=0 : goto 2360
3390 DD$=DD$+FF$+”\”-“ “ : return
3400 rem ENTER A SAVE FILE NAME
3410 reset zone : set zone 1,167,160 to 228,174
3415 locate 13,4 : print space$(12)
3420 clear key : XC=13 : XSP=104 : locate XC,4 : FF$=”” : T$=”ENTER NAME OF PICTURE” : pen 15 : locate 10,23 : print T$ : sprite 1,XSP,32,2 : caps lock on 3430 K$=inkey$
3440 rem CHECK FOR RETURN KEY
3450 if K$=chr$(13) then goto 3545
3460 if mouse key=1 and zone(0)=1 then goto 3545
3470 rem CHECK FOR BACKSPACE KEY
3480 if K$=chr$(8) and XC>12 and XSP>104 then locate XC,4 : print “ “; : dec XC : locate XC,4 : XSP=XSP-8 : sprite 1,XSP,32,2
3490 if XC=12 then XC=13
3500 rem CHECK FOR NORMAL CHARACTERS
3510 if K$=”.” then XC=22 : XSP=176 : sprite 1,XSP,32,2 : locate XC,4 : goto 3540
3520 if asc(K$)>31 and XC=21 then XSP=XSP+8 : sprite 1,XSP,32,2 : inc XC : locate XC,4 : print K$; : goto 3540
3530 if asc(K$)>31 and XC<25 then XSP=XSP+8 : sprite 1,XSP,32,2 : print K$; : inc XC
3540 K$=”” : locate XC,4 : goto 3430
3545 for X=13 to XC : FF$=FF$+chr$(scrn(X,4)) : next X
3550 if len(FF$)=0 or len(FF$)=1 then sprite off : paper 0 : locate 10,23 : print space$(23) : wait 10 : goto 2640 3560 F=instr(FF$,”.”) : if F then FF$=left$(FF$,F-1) : hide on : wait 10
3565 if not(F) then FF$=left$(FF$,8)-“ “ : hide on : wait 10
3570 if PATH$=”*.PI1” then cls : goto 3680
3580 if PATH$=”*.NEO” then cls : goto 3700
3590 if PATH$=”*.GRX” then FF$=left$(FF$,8)-" "
3600 rem SAVE A PACKED SCREEN
3610 cls : reserve as work 10,20000 : fill start(10) to start(10)+length(10),0 3620 for X=0 to 15 : colour X,val(C0L$(SC,X)) : next X
3630 opaque screen logic,0,0,SCR$(SC) : fastcopy logic,back
3640 D=crack pac(logic,start(10))
3650 bsave FF$+”.GRX”,start(10) to start(10)+length(10) : erase 10 : gosub 3220 3660 cls : unpack S2,S5 : floodpal 0 : wait vbl : fastcopy S7,S3 : goto 220 3670 rem
3680 for X=0 to 15 : colour X,val(C0L$(SC,X)) : next X
3690 opaque screen back,0,0,SCR$(SC) : fastcopy back,logic : save FF$+".PI1" : cls : wipe S3 : wipe S5 : unpack S2,S5 : floodpal 0 : wait vbl : fastcopy S7,S3 : goto 220 3700 for X=0 to 15 : colour X,val(C0L$(SC,X)) : next X
3710 opaque screen back,0,0,SCR$(SC) : fastcopy back,logic : save FF$+".NEO" : cls : wipe S3 : wipe S5 : unpack S2,S5 : floodpal 0 : wait vbl : fastcopy S7,S3 : goto 220