10
20
30 :
40 MODE 128
50 DIM M%(32),data% 31:PROCusb_Init:ecs%=0
60 REPEAT
70 VDU30
80 PRINT"USB: DUMP INPUT/OUTPUT"'
90 PRINT"S Sync"'"F Flush"
100 PRINT"Z Short commands"'"X Extended commands"'
110 PRINT"H IPH : Hex"
120 PRINT"A IPA : Ascii"
130 PRINT"1 QP1 : Query Port 1"
140 PRINT"2 QP2 : Query Port 2"
150 PRINT"Cn SCx : Set Current Device"
160 PRINT"Qn QDx : Query Device"
170 PRINT"R DRD : Read: Device Read Data"
180 PRINT"Wx DSD : Write: Device Send Data"
190
200 PRINT"Tx SFx : Set FTDI"
210 PRINT"V QSS : Query Slave Status"
220 PRINT"E E : Echo"
230 REPEATA$=GET$:UNTILINSTR("SFHAZX12CQRWUTVE",A$):PROCdo:PROCusb_Sync
240 UNTIL FALSE
250 END
260 :
270 DEFPROCdo
280 PRINTSPC(60)'SPC(60)'SPC(60)'SPC(60)'CHR$11;CHR$11;CHR$11;CHR$11;
290 IF A$="S":PROCusb_Sync:ENDPROC
300 IF A$="F":PROCusb_Flush:ENDPROC
310 IF A$="Z":PROCusb_Cmd(CHR$&10):ecs%=0:ENDPROC
320 IF A$="X":PROCusb_Cmd(CHR$&11):ecs%=1:ENDPROC
330 IF A$="A":IFecs%:PROCusb_Cmd("IPA") :ENDPROC
340 IF A$="A": PROCusb_Cmd(CHR$&90):ENDPROC
350 IF A$="H":IFecs%:PROCusb_Cmd("IPH") :ENDPROC
360 IF A$="H": PROCusb_Cmd(CHR$&91):ENDPROC
370 IF A$="1":IFecs%:PROCusb_Cmd("QP1") :ENDPROC
380 IF A$="1": PROCusb_Cmd(CHR$&2B):ENDPROC
390 IF A$="2":IFecs%:PROCusb_Cmd("QP2") :ENDPROC
400 IF A$="2": PROCusb_Cmd(CHR$&2C):ENDPROC
410 IF A$="W":PROCdsd:ENDPROC:
420 IF A$="R":IFecs%:PROCusb_Cmd("DRD") :ENDPROC
430 IF A$="R" :PROCusb_Cmd(CHR$&84):ENDPROC
440 IF A$="Q":PRINT"QD";:B$=GET$:PRINT
450 IF A$="Q":IFecs%:PROCusb_Cmd("QD "+B$) :ENDPROC
460 IF A$="Q": PROCusb_Cmd(CHR$&85+" "+CHR$VALB$):ENDPROC
470 IF A$="C":PRINT"SC";:B$=GET$:PRINT
480 IF A$="C":IFecs%:PROCusb_Cmd("SC "+B$) :ENDPROC
490 IF A$="C": PROCusb_Cmd(CHR$&86+" "+CHR$VALB$):ENDPROC
500 IF A$="T":PRINT"SF";:B$=GET$:PRINT
510 IF A$="T":IFecs%:PROCusb_Cmd("SF "+B$) :ENDPROC
520 IF A$="T": PROCusb_Cmd(CHR$&87+" "+CHR$VALB$):ENDPROC
530 IF A$="V":IFecs%:PROCusb_Cmd("QSS"):ENDPROC
540 IF A$="V": PROCusb_Cmd(CHR$&98):ENDPROC
550 IF A$="E":PROCusb_Cmd("E"):ENDPROC
560
570 ENDPROC
580 :
590 :
600 DEFFNh0(A%,N%)=RIGHT$("0000000"+STR$~A%,N%)
610 DEFFNc0(A%):IFA%<32ORA%>126:PRINT"<"FNh0(A%,2)">"; ELSE VDU A%
620 =""
630 :
640
650 :
660
670
680 DEFPROCusb_Sync:REPEATIF(?usb_S AND 128)=0:PRINTFNc0(?usb_D);
690 UNTIL(?usb_S AND 128):ENDPROC
700 DEFPROCusb_Flush:IF(?usb_S AND 128):ENDPROC
710 PRINT'"Flushing USB";:REPEAT:REPEATA%=?usb_D:PRINTFNc0(A%);:UNTIL(?usb_S AND 128)
720 A%=TIME+20:REPEATUNTILTIME>A%:UNTIL(?usb_S AND 128):ENDPROC
730 DEFFNusb_Err:IF?usb_result%=13 OR usb_result%?1=ASC":":=0 ELSE PRINT"USB Error: "$usb_result%:=TRUE
740 DEFPROCusb_Cmd(A$):COLOUR129:COLOUR0:PROCusb_WrStr(A$+CHR$13):COLOUR128:COLOUR1:PROCusb_RdStr:ENDPROC
750 DEFFNusb_Cmd(A$):PROCusb_Cmd(A$):=FNusb_Err
760 DEFPROCusb_WrStr(A$):FOR A%=1 TO LEN A$:REPEATUNTIL(?usb_S AND 64)=0
770 PRINTFNc0(ASCMID$(A$,A%,1));:?usb_D=ASCMID$(A$,A%,1):NEXT:ENDPROC
780 DEFPROCusb_RdStr:A%=usb_result%-1:REPEATA%=A%+1:?A%=FNusb_Rd:UNTIL?A%=13:ENDPROC
790 DEFPROCusb_Wr(A%):REPEATUNTIL(?usb_S AND 64)=0:?usb_D=A%:ENDPROC
800 DEFFNusb_Rd:LOCALA%:REPEATUNTIL(?usb_S AND 128)=0:A%=?usb_D:PRINTFNc0(A%);:=A%
810 DEFPROCusb_Init
820 usb_D=&FCF8:usb_S=&FCF9
830 usb_result%=usb_result%:IF usb_result%:ENDPROC
840 DIM usb_result% 63,mc% 99
850 FOR P=0 TO 1:P%=mc%:[OPT P*2
860 .usb_RdData
870 TAY:LDA #data% AND 255:STA usb_RdLp+4
880 LDA #data% DIV 256:STA usb_RdLp+5:LDX #0
890 .usb_RdLp:JSR usb_Rd:STA data%,X:INX:BNE usb_RdLp
900 INC usb_RdLp+5:DEY:BNE usb_RdLp:RTS
910 .usb_Rd:BIT usb_S:BPL usb_Rd2:BIT &FF:BPL usb_Rd
920 .usb_Rd2:LDA usb_D:RTS
930 .usb_WrData
940 TAY:LDA #data% AND 255:STA usb_WrLp+1
950 LDA #data% DIV 256:STA usb_WrLp+2:LDX #0
960 .usb_WrLp:LDA data%,X:JSR usb_Wr
970 .usb_WrLp2:LDA usb_D:BIT usb_S:BPL usb_WrLp2
980 INX:BNE usb_WrLp
990 INC usb_WrLp+2:DEY:BNE usb_WrLp:RTS
1000 .usb_Wr:BIT usb_S:BVC usb_Wr2:BIT &FF:BPL usb_Wr
1010 .usb_Wr2:STA usb_D:RTS
1020 ]NEXT:ENDPROC
1030 :