10 '        P U B L I C  D O M A I N  CAT SEED P R O G R A M
15 '*****************************************************************
16 '* This program may be freely distributed and exchanged. It may  *  
17 '* be rewritten, modified, changed and/or expanded. Indeed you   *    
18 '* are  encouraged to do so to make it work with your particular * 
19 '* radio. You need not even give this author any credit. While   * 
20 '* this program is originally intended for the YAESU(tm) FT-980  * 
21 '* transceiver, a careful approach and rewrite should make it a  * 
22 '* seed for the development of most other ham radios on the      *  
23 '* market. One request: share your ideas with others. This is an * 
24 '* still an exciting frontier of Ham Radio. On with it!          *
25 '*     (Program prepared at the suggestion of 73 Magazine)       *
26 '*       Art Harding K5YEF, PO Box 1719, Plano, Tx 75074         *
27 '* Full featured FT-980 EXE program available from above address *
28 '*****************************************************************
50 GOSUB 9000 'Set up your computer COM port
60 GOSUB 1000   'INITIALIZATION
70 GOSUB 2000   'Begin CAT action
80 'Release radio and shut down COM port
90 CMD$=ONOFF$:GOSUB 6000
100 PRINT#1,OK$;
110 CLOSE #1
120 PRINT:PRINT:PRINT"Radio released ~ COM 1 NOW CLOSED ~Program complete..."
130 END
1000 '* INITIALIZATION
1010 OPTION BASE 1
1020 DIM ECHO$(5) 'Echo is same length as a command, 5 bytes
1030 DIM STATUS%(148) 'The FT-980 complete status stream, 148 bytes
1040 CMD$="     "   'This could have been a DIM CMD$(5), but this works too..
1060 OK$=CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(&HB)      'OK to execute CMD
1070 ONOFF$=CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)             'ON-OFF CMD
1080 ALLSTATUS$=CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(&H1)  'Status ALL CMD
1085 TIMER1=4000 'Change if trouble with receiving status inputs
1090 TIMER2=1000 'Change for hang time between 10 meter FM freqs
1100 GEN$=CHR$(&H21): HAM$=CHR$(&H22):             'Choose GENeral or HAM vfo
1110 USB$=CHR$(&H11): AMW$=CHR$(&H14): FM$=CHR$(&H17)       'Some modes choices
1120 MR$=CHR$(&H1E): VFO$=CHR$(&H1F)                      'MEMory or VFO choice
1130 RETURN
2000 '* MAIN PROCESSING
2010 '1)Capture radio 2)Choose VFO 3)Choose HAM/VFO 4)Choose USB 5)Choose freq
2020 CMD$=ONOFF$: R=148: GOSUB 5010   'R is the number of status bytes expected
2030 IF STATUS%(27)=1 THEN PRINT "Radio Is Captured!" ELSE 2020
2040 CHOICE$=VFO$: R=22: GOSUB 5000
2050 CHOICE$=HAM$: R=22: GOSUB 5000
2060 CHOICE$=USB$: R=22: GOSUB 5000
2070 'The next line changes the frequency. You can "read" 142500 reading
2080 'from the next to last byte, right to left.
2090 CMD$=CHR$(0)+CHR$(&H50)+CHR$(&H42)+CHR$(1)+CHR$(&H8): R=5: GOSUB 5010
2100 CMD$=ALLSTATUS$:R=148:GOSUB 5010 'Task radio for a complete status
2110 GOSUB 9100
3000 PRINT:PRINT:PRINT "Hit any key to switch to WWV on 10 MHz (F1=quit)"
3010 GOSUB 9999 'Hang around for next key hit
3020 GOSUB 9200
3030 GOSUB 9100:
3040 PRINT"Compare the 2 status displays now on the screen. Notice the changes."
4000 PRINT: PRINT"Hit any key to scan 10 meter FM frequencies...(F1 to quit)"
4010 GOSUB 9999
4020 GOSUB 9500
4030 RETURN
5000 CMD$=CHR$(0)+CHR$(0)+CHR$(0)+CHOICE$+CHR$(&HA)
5010 ' OUTPUT COMMAND - GET ECHO - COMPARE/CONFIRM - GET STATUS
5020 GOSUB 6000         'Output Command, Get ECHO
5030 GOSUB 7000                 'OK
5040 GOSUB 8000                 'Get status
5050 RETURN
6000 '* OUTPUT COMMAND AND GET ECHO
6010 '*
6020 N=0
6030 COM(1) OFF
6040 PRINT#1,CMD$; 'ALL CAT radios will need to do this!
6050 N=N+1: IF (EOF(1) AND N<TIMER1) THEN 6050 'Wait for input but not forever!
6060 REM IF N>=TIMER1 THEN 7100 'Oh oh, no COM action was detected, try again.
6070 WHILE NOT EOF(1): ECHO$=INPUT$(5,#1): IF LOC(1)=0 THEN 6080:WEND
6080 IF ECHO$=CMD$ THEN RETURN: ELSE PRINT"Echo received does NOT match command![trying again]": GOTO 6020
7000 '* send OK to 980
7010 COM(1) ON 'Prepare Event Trap for expected incoming status stream
7020 PRINT#1,OK$; 'The FT-980 OK CMD - ok to execute last command sent
7030 RETURN
8000 '*Get Status
8010 IF EOF(1) THEN 8010
8020 FOR S=1 TO 4000: IF R=1 THEN 8030: NEXT 'Twittle thumbs loop while traping
8030 COM(1) OFF 'No more input expected at this time
8040 RETURN
9000 'Set up Com Ports, event trap and F1 key trap
9005 'If you get port errors then increase CS10 to CS100 if you have a fast
9006 'computer. For slow computers (10 MHz down) eliminate CS parameter -
9007 'i.e., just CS with no value. These changes are made on line 9010.
9010 OPEN "COM1:4800,N,8,2,RS,CS10,DS0,BIN" FOR RANDOM AS #1
9012 '...if no luck, try running fix_com1.exe then try everything again
9015 ' com ports can be tricky - have patients
9020 REM FOR S=1 TO 2000: NEXT 'Allow time for port to settle down????
9030 ON COM(1) GOSUB 10000
9040 COM(1) ON
9050 ON KEY (1) GOSUB 80 'F1 key will release radio, close port and quit
9060 KEY (1) ON
9070 RETURN
9100 'Print all status bytes on screen in Hex...
9110 PRINT:PRINT "STATUS Input in Hex (Compare with your manual):"
9120 FOR S=1 TO 148: PRINT " "HEX$(STATUS%(S));: NEXT S
9130 PRINT:PRINT:PRINT"Bytes 2 thru 5 above yield Frequency: ";
9140 FOR S=2 TO 5: PRINT HEX$(STATUS%(S));:NEXT S
9150 RETURN
9200 'SWITCH TO GENERAL VFO, AM AND WWV ON 10 MHz
9210 CHOICE$=GEN$: R=22: GOSUB 5000
9220 CHOICE$=AMW$: R=22: GOSUB 5000
9230 CMD$=CHR$(0)+CHR$(0)+CHR$(0)+CHR$(&H1)+CHR$(&H8): R=5: GOSUB 5010
9240 RETURN
9500 'SCAN FOR 10 METER FM ACTIVITY
9510 PRINT: PRINT: PRINT"Hit any key to stop and restart scan (F1 to quit)"
9520 CHOICE$=VFO$: R=22: GOSUB 5000
9530 CHOICE$=HAM$: R=22: GOSUB 5000
9540 CHOICE$=FM$: R=22: GOSUB 5000
9550 TEN$=CHR$(&H95): GOSUB 9580: PRINT
9560 TEN$=CHR$(&H96): GOSUB 9580: PRINT: PRINT"* Complete cycle (F1=quit)"
9570 GOTO 9550 'Keep the loop going forever - or until <F1> hit
9580 FOR Q9=1 TO 10
9590 T=1
9600 READ F
9610 BUMP$=CHR$(F)
9620 CMD$=CHR$(0)+BUMP$+TEN$+CHR$(&H2)+CHR$(&H8): R=5: GOSUB 5010
9630 FOR S9=2 TO 5: PRINT HEX$(STATUS%(S9));:NEXT S9
9640 PRINT" ";
9650 T=T+1: IF(INKEY$="" AND T<TIMER2) THEN 9650
9660 IF T<TIMER2 THEN T=1: GOSUB 9999
9670 NEXT
9680 RESTORE 9700
9690 RETURN
9700 DATA &H0,&H10,&H20,&H30,&H40,&H50,&H60,&H70,&H80,&H90
9999 IF INKEY$="" THEN 9999 ELSE RETURN
10000 'THERE IS A CHARACTER RECEIVED!
10010 WHILE NOT EOF(1):STATUS%(R)=ASC(INPUT$(1,#1)):R=R-1:WEND
10020 RETURN
