home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
RBBS in a Box Volume 1 #3.1
/
RBBSIABOX31.cdr
/
kba1
/
jr_modem.bas
< prev
next >
Wrap
BASIC Source File
|
1990-10-01
|
16KB
|
328 lines
10 ' JR-MODEM.BAS Jody Donaldson 9/7/84
20 ' Communications Program For IBM-PC jr. and Hayes Smartmodem
30 '
40 ' Based on Russ Lane's IBMODEM.BAS
45 '
50 ' You can added your own long distance service (MCI, etc.) prefix
51 ' codes in Line 6520 -- Be sure to include the commas for the pauses
52 ' on the SmartModem.
60 '
62 ' BE SURE TO RUN THIS PROGRAM IN THIS MANNER ONLY:
64 ' A>BASIC JR-MODEM /C:2048
66 ' At 1200 baud the normal buffer of 128 overflows quickly.
70 ' In order for the hang-up command to work,
80 ' you MUST flip switch #1 on the modem UP.
85 ' (You should have it up anyway.)
87 '
90 SCREEN 0,0,0,0 : LOCATE ,,1 : WIDTH 80 : KEY OFF : CLOSE
95 ON ERROR GOTO 1000
100 ' Set Variable Defaults ---------------------------------------
110 DEFINT A-Z ' All Variables Are Integers
120 ONLINE = -1 ' Start On-Line
130 EVEN = -1 ' Even Parity, 7 Bit Word Structure
140 PRINTER= 0 ' Printer Off
150 DISK = 0 ' Disk(s) Off
160 LOCAL = 0 : HOST=0 ' Echoes Off
170 BK$=CHR$(29)+CHR$(32)+CHR$(29)' Clean Backspace For Local PC
180 SOH$=CHR$(1) : EOT$=CHR$(4) : ACK$=CHR$(6)
190 XON$=CHR$(17) : XOFF$=CHR$(19) : NAK$=CHR$(21) : CAN$=CHR$(24)
200 ' Define Funtion Keys -----------------------------------------
210 KEY(1)ON:ON KEY(1)GOSUB 3100
220 KEY(2)ON:ON KEY(2)GOSUB 3200
230 KEY(3)ON:ON KEY(3)GOSUB 3300
240 KEY(4)ON:ON KEY(4)GOSUB 3400
250 KEY(5)ON:ON KEY(5)GOSUB 3500
260 KEY(6)ON:ON KEY(6)GOSUB 3600
270 KEY(7)ON:ON KEY(7)GOSUB 3700
280 KEY(8)ON:ON KEY(8)GOSUB 3800
290 KEY(9)ON:ON KEY(9)GOSUB 3900
295 KEY(10)ON:ON KEY(10)GOSUB 4000
297 DEF SEG:POKE 106,0
299 GOSUB 60000 ' Sign on screen
300 ' Define I/O Channels -----------------------------------------
302 BAUD$="1200": PARITY$="N": LNGTH$="8": STP$="1": SETTING$=",RS,CS,DS"
310 GOSUB 50010
330 PRINT #1,"ATE1QTS11=50" ' Un-REM to init modem for tone dialing
340 FOR X=1 TO 1000 : NEXT : GOSUB 25000 : GOSUB 800
350 GOSUB 6320:GOSUB 3940:EVEN=0 ' Default 300 Baud, No Parity, 8 Data Bits
400 ' Keyboard Driven Terminal Loop -------------------------------
410 WHILE ONLINE
420 X$=INKEY$:IF X$<>"" THEN LOCATE ,,1:PRINT #1,X$;:IF LOCAL THEN GOSUB 470
430 GOSUB 500
440 WEND
450 IF NOT ONLINE THEN 450 ' Off-Line Wait Loop
460 GOTO 410
470 IF POS(0)>1 AND X$=CHR$(8) THEN PRINT BK$; ELSE PRINT X$;
480 RETURN
500 ' Main Communication Loop -------------------------------------
510 WHILE NOT EOF(1)
520 X$=INKEY$ : IF X$<>"" THEN LOCATE ,,1 : PRINT #1,X$;
530 Y$=INPUT$(LOC(1),#1) : IF DISK THEN PRINT #3,Y$;
540 FOR I=1 TO LEN(Y$)
550 J=ASC(MID$(Y$,I,1)) : IF J=10 THEN 590 ELSE IF J=8 THEN 595
560 PRINT CHR$(J); : IF HOST THEN PRINT #1,CHR$(J);
570 NEXT : IF PRINTER THEN PRINT #2,Y$;
580 WEND : RETURN
590 MID$(Y$,I,1)=" " : GOTO 570
595 IF POS(0)>1 THEN PRINT BK$; : IF HOST THEN PRINT #1,CHR$(J);
597 GOTO 570
800 ' Function Key Display Menu -----------------------------------
810 CLS : PRINT TAB(15);"MENU FOR FUNCTION KEYS" : PRINT
820 PRINT TAB(10)"Key 1 . . . . . . To Toggle Modem Online/Offline
830 PRINT TAB(10)"Key 2 . . . . . . To Toggle On/Off LOCAL Echo
840 PRINT TAB(10)"Key 3 . . . . . . To Toggle On/Off HOST Echo
850 PRINT TAB(10)"Key 4 . . . . . . To Dial A Number
860 PRINT TAB(10)"Key 5 . . . . . . To Display This Menu
870 PRINT TAB(10)"Key 6 . . . . . . To Toggle Printer On/Off
880 PRINT TAB(10)"Key 7 . . . . . . To Write To Disk From Modem
890 PRINT TAB(10)"Key 8 . . . . . . To Write To Modem From Disk
900 PRINT TAB(10)"Key 9 . . . . . . To Toggle Between E,7,1 and N,8,1 words
910 PRINT TAB(10)"Key 10. . . . . . To Return To Basic Without Hanging-Up
920 PRINT
930 PRINT TAB(10)"Alt + Key 3 . . . To Change To 300 Baud
940 PRINT TAB(10)"Alt + Key 4 . . . To Continuously Dial A Number
950 PRINT TAB(10)"Alt + Key 5 . . . Long Distance Dialing Service Prefix
960 PRINT TAB(10)"Alt + Key 6 . . . To Change To 1200 Baud
970 PRINT TAB(10)"Alt + Key 7 . . . To Write To Disk With Xmodem Protocol
975 PRINT TAB(10)"Alt + Key 8 . . . To Write To Modem From Disk With Xmodem
980 PRINT TAB(10)"Alt + Key 10. . . To Hang-Up
985 LOCATE 25,1: PRINT "f4=DIAL f5=MENU alt+f5=LONG DISTANCE alt+f7=XMODEM RCV alt+f10=HANG-UP";
990 LOCATE 22,1: RETURN
1000 ' Error Vector Table -----------------------------------------
1010 PRINT
1020 IF ERR=24 THEN PRINT "Device Timeout" : PRINT : RESUME 400
1030 IF ERR=27 THEN PRINT "Printer" : PRINT : RESUME 400
1040 IF ERR=57 THEN PRINT "Device I/O" : PRINT : RESUME 400
1050 IF ERR=52 THEN PRINT "Bad Filename" : GOTO 1150
1060 IF ERR=61 THEN PRINT "Disk Full" : GOTO 1150
1070 IF ERR=67 THEN PRINT "Directory Full" : GOTO 1150
1080 IF ERR=70 THEN PRINT "Disk Write Protected" : GOTO 1150
1090 IF ERR=71 THEN PRINT "Drive Not Ready" : GOTO 1150
1100 IF ERR=72 THEN PRINT "Disk Media Error" : GOTO 1150
1105 IF ERR=53 AND ERL=3770 THEN RESUME 3780
1110 IF ERR=53 THEN PRINT "File Not Found" : PRINT : FILES : GOTO 1150
1120 IF ERR=58 THEN PRINT "File Already Exists" : PRINT : FILES : GOTO 1150
1130 ON ERROR GOTO 0
1150 PRINT : DISK=0 : CLOSE #3 : IF NOT ONLINE THEN GOSUB 3120
1160 LOCATE ,,1 : RESUME 400
3100 ' Service Function Key #1 -------------------------------------
3110 GOSUB 5000 : KEY(1)ON : ON S GOTO 6100,7100,8100
3120 ONLINE=NOT ONLINE : IF NOT ONLINE THEN 3140
3130 PRINT #1, XON$ : PRINT "Status : ON Line" : RETURN
3140 PRINT #1, XOFF$: PRINT "Status : OFF Line" : RETURN
3200 ' Service Function Key #2 -------------------------------------
3210 GOSUB 5000 : KEY(2) ON : ON S GOTO 6200,7200,8200
3220 LOCAL=NOT LOCAL
3230 PRINT "Local Echo "; : IF LOCAL THEN PRINT "ON" ELSE PRINT "OFF"
3240 RETURN
3300 ' Service Function Key #3 -------------------------------------
3310 GOSUB 5000 : KEY(3)ON : ON S GOTO 6300,7300,8300
3320 HOST=NOT HOST
3330 PRINT "Host Echo "; : IF HOST THEN PRINT "ON" ELSE PRINT "OFF"
3340 RETURN
3400 ' Service Function Key #4 -------------------------------------
3410 GOSUB 5000 : KEY(4)ON : ON S GOTO 6400,7400,8400
3420 GOSUB 10000 : PRINT
3430 PRINT #1,"AT M1 D "+X$
3440 RETURN
3500 ' Service Function Key #5 -------------------------------------
3510 GOSUB 5000 : KEY(5)ON : ON S GOTO 6500,7500,8500
3520 GOTO 800
3600 ' Service Function Key #6 ------------------------------------
3610 GOSUB 5000 : KEY(6)ON : ON S GOTO 6600,7600,8600
3620 PRINTER=NOT PRINTER
3630 IF PRINTER THEN PRINT "Printer ON" ELSE PRINT "Printer OFF"
3640 RETURN
3700 ' Service Function Key #7 -------------------------------------
3710 GOSUB 5000 : KEY(7)ON : ON S GOTO 22000,7700,8700
3720 DISK=NOT DISK
3730 IF NOT DISK THEN CLOSE #3 : PRINT "File Closed" : RETURN
3740 GOSUB 3120
3750 PRINT "Modem ====>> Disk" : PRINT
3760 INPUT "ENTER FILENAME : ",X$ : IF X$="" THEN 3790
3770 CLOSE #3 : OPEN "I",#3,X$ : ERROR 58
3780 CLOSE #3 : OPEN "O",#3,X$ : GOSUB 3120 : RETURN
3790 PRINT "Aborted" : PRINT : CLOSE #3 : GOSUB 3120 : DISK=0 : RETURN
3800 ' Service Function Key #8 -------------------------------------
3810 GOSUB 5000 : KEY(8)ON : ON S GOTO 30000,7800,8800
3820 PRINT "Disk ====>> Modem" : PRINT
3830 INPUT "ENTER FILENAME : ",X$ : IF X$="" THEN 3790
3840 OPEN "I",#3,X$
3850 PRINT "Proceed With File ";X$;
3860 INPUT " (Y/N) ";Y$ : Y$=LEFT$(Y$,1)
3870 IF Y$<>"Y" AND Y$<>"y" THEN 3896
3875 IF XX THEN XX=0 : RETURN 30040
3880 WHILE NOT EOF(3)
3885 LINE INPUT #3,X$
3890 PRINT #1,X$
3892 FOR I=1 TO 1500:NEXT
3894 WEND
3896 CLOSE #3 : DISK=0 : PRINT "File Closed" : PRINT : RETURN
3900 ' Service Function Key #9 -------------------------------------
3910 GOSUB 5000 : KEY(9)ON : ON S GOTO 6900,7900,8900
3920 EVEN=NOT EVEN : IF NOT EVEN THEN 3940
3930 PRINT "Changed to Even Parity, With 7 Data Bits" : PARITY$="E": LNGTH$ = "7": GOSUB 50000: RETURN
3940 PRINT "Changed to No Parity With 8 Data Bits." : PARITY$="N": LNGTH$="8": GOSUB 50000: RETURN
4000 ' Service Function Key #10 ------------------------------------
4005 REM Error exits 8000 and 9000 missing from original code. We will replace
4006 REM this code when we get a better orig. from somebody. DCC/Dallas RCP/M
4010 GOSUB 5000 : KEY(10)ON : ON S GOTO 7000,8000,9000
4020 PRINT "Pressing Key #5 will continue without hanging up."
4030 PRINT:STOP : LOCATE ,,1
5000 ' Functin Keys 1-10 Router ----------------------------------
5010 PRINT
5020 DEF SEG=&H40:A=PEEK(&H17)
5030 IF (A AND 8)=8 THEN S=1 : DEF SEG : RETURN 'Alternate
5040 IF (A AND 2)=2 THEN S=2 : DEF SEG : RETURN 'Left Shift
5050 IF (A AND 4)=4 THEN S=3 : DEF SEG : RETURN 'Control
5060 S=0 : DEF SEG : RETURN
6300 '-------------------------------------------------- Alt + F3 -------------
6310 PRINT "Switch to 300 Baud."
6320 ON ERROR GOTO 0
6330 BAUD$="300": GOSUB 50000
6390 ON ERROR GOTO 1000 : RETURN
6400 'Continuous Dialing ------------------------------- Alt + F4 -------------
6405 IF NOT EVEN THEN GOSUB 3940
6410 GOSUB 10000 : PRINT : PRINT "Continuously Dialing ";X$
6420 PRINT "Press ESC twice to abort."
6430 T=0 : PRINT : PRINT "Number of calls attempted so far : ";
6440 T=T+1 : LOCATE ,36 : PRINT T; : PRINT #1,"AT M0 D "+X$
6450 IF CHR$(27)=INKEY$ THEN 6497 ELSE WHILE NOT EOF(1)
6460 INPUT #1,Y$ : FOR X=1 TO 1000 : NEXT
6470 IF INSTR (Y$,"NO CARRIER") THEN 6440
6480 IF INSTR (Y$,"CONNECT") THEN 6490
6485 WEND : GOTO 6450
6490 PRINT : PRINT "Connection Established."
6495 WHILE INKEY$="" : SOUND 1000,10 : SOUND 735,8 : WEND
6497 PRINT : RETURN
6500 '------------------------------------------------- Alt + F5 ------------
6510 LINE INPUT "Long Distance Service Number to Dial? "; X$
6520 X$ = "999-9999,,999999," + X$ ' INSERT YOUR LONG DISTANCE NUMBERS HERE
6530 GOTO 3430
6590 ON ERROR GOTO 1000 : RETURN
6600 '-------------------------------------------------- Alt + F6 -------------
6610 PRINT "Switch to 1200 Baud"
6620 ON ERROR GOTO 0
6630 BAUD$="1200": GOSUB 50000
6690 ON ERROR GOTO 1000 : RETURN
7000 '-------------------------------------------------- Alt + F10 ------------
7010 PRINT "Hanging-Up" : RUN
10000 ' Directory --------------------------------------------------
10010 PRINT "+------------- Directory -------------+"
10020 PRINT "| A> 931-8073 Dallas RCP/M\CBBS |" : D$(1)="931-8073"
10030 PRINT "| B> 239-5842 Eclectic |" : D$(2)="239-5842"
10040 PRINT "| C> 761-9040 Compuserve |" : D$(3)="761-9040"
10050 PRINT "| D> -------- --------- |" : D$(4)="--------"
10060 PRINT "| E> -------- --------- |" : D$(5)="--------"
10070 PRINT "| F> -------- --------- |" : D$(6)="--------"
10080 PRINT "+-------------------------------------+"
10090 PRINT " Enter the corresponding letter"
10100 PRINT " or type in any phone number." : PRINT
10110 LINE INPUT "Number to Dial ? ";X$
10120 IF LEN(X$)=1 AND X$=>"A" AND X$<="F" THEN X$=D$(ASC(X$)-64) : RETURN
10130 IF LEN(X$)=1 AND X$=>"a" AND X$<="f" THEN X$=D$(ASC(X$)-96) : RETURN
10140 IF LEN(X$)<7 THEN LOCATE ,,1 : RETURN 400 ELSE RETURN
20000 ' Get Character -----------------------------------------
20010 Y$=""
20020 FOR A=1 TO 420
20030 IF NOT EOF(1) THEN Y$=INPUT$(LOC(1),#1) : RETURN
20040 NEXT A : Y$="" : RETURN
21000 ' Timeout -----------------------------------------------
21010 FOR B = 1 TO 10
21020 GOSUB 20000
21030 IF MID$(Y$,1,1)=SOH$ THEN RETURN
21040 IF MID$(Y$,1,1)=EOT$ THEN 22350
21050 IF MID$(Y$,1,1)=CAN$ THEN 22360
21060 IF Y$<>"" THEN GOSUB 25000 : GOTO 21000
21070 NEXT B
21080 IF Y$="" THEN PRINT #1,NAK$;
21090 GOTO 21000
22000 ' Receive With Xmodem Protocol ---------------------------
22010 PRINT "Receive File With XMODEM Protocol" : PRINT
22020 IF EVEN THEN GOSUB 3940 ' Set Word Structure To 8-N-1
22030 GOSUB 3740 ' Open File
22040 GOSUB 25000 ' Purge Buffer
22050 X$="" : SEC=1
22060 PRINT #1,NAK$;
22070 GOSUB 21000 ' Timeout
22080 GOSUB 20000 ' Get Char
22090 IF Y$="" THEN PRINT "Timeout" : GOTO 22120
22100 X$=X$+Y$
22110 IF LEN(X$)<=131 THEN 22080
22120 IF LEN(X$)= 132 THEN Z$=MID$(X$,4,128) : N=132 : GOTO 22200
22130 IF LEN(X$)= 131 THEN Z$=MID$(X$,3,128) : N=131 : GOTO 22200
22140 IF LEN(X$)> 132 THEN 22310
22150 IF X$=EOT$ THEN 22350
22160 IF X$=CAN$ THEN 22360
22170 GOTO 22300
22180 IF SEC<> VAL(MID$(X$,2,1) THEN 22330
22190 IF (SEC XOR 255) <> VAL(MID$(X$,3,1) THEN 22340
22200 FOR Q=1 TO 128 : CK=CK+ASC(MID$(Z$,Q,1)) : NEXT
22210 IF (CK AND 255) <> (ASC(MID$(X$,N,1))) THEN 22320
22220 PRINT " Received #";SEC; " ";CHR$(13) CHR$(30);: SEC=SEC+1
22230 PRINT #3,Z$;
22240 PRINT #1,ACK$;
22250 X$="" : CK=0 : GOTO 22080
22300 PRINT "Short Block in #" ;SEC : PRINT #1,NAK$; : GOTO 22250
22310 PRINT "Long Block in #" ;SEC : PRINT #1,NAK$; : GOTO 22250
22320 PRINT "Checksum Error in #";SEC : PRINT #1,NAK$; : GOTO 22250
22330 PRINT "Block # Error in #";SEC : PRINT #1,NAK$; : GOTO 22250
22340 PRINT "Complement Error in #";SEC:PRINT #1,NAK$; : GOTO 22250
22350 PRINT "File Closed." : PRINT #1,ACK$; : CLOSE #3 : RETURN 400
22360 PRINT "Transfer Aborted at Receiver" : CLOSE #3 : RETURN 400
25000 'Purge Buffer ------------------------------------------
25010 WHILE NOT EOF(1) : DUMMY$=INPUT$(LOC(1),#1) : WEND : RETURN
30000 ' Send with Xmodem Protocol -----------------------------------
30010 PRINT "Send File With XMODEM Protocol" : PRINT
30020 IF EVEN THEN GOSUB 3940 'Set To N-8-1 Word Structure
30030 XX=-1 : GOSUB 3820 'Open File
30040 SEC=0 : GOSUB 25000 'Purge Buffer
30050 EOT=0 : Y$="" : X$=""
30100 WHILE NOT EOF(1) 'Wait for NAK
30110 Y$=INPUT$(1,#1)
30120 IF Y$=CAN$ THEN 30510
30130 IF Y$=NAK$ THEN 30310
30140 WEND : GOTO 30100
30150 '
30200 WHILE NOT EOF (1) ' Wait for ACK
30210 Y$=INPUT$(1,#1)
30220 IF Y$=ACK$ THEN CK=0 : Y$="" : GOTO 30360
30230 IF Y$=NAK$ THEN 30460
30240 IF Y$=CAN$ THEN 30510
30250 WEND : GOTO 30200
30260 '
30300 IF EOT THEN 30500 ' Build and Send Block
30310 CK=0 : Y$=""
30320 IF EOF(3) THEN 30490
30330 LINE INPUT #3,Z$
30340 Z$=Z$+CHR$(13)+CHR$(10)
30360 IF EOT THEN 30500
30365 FOR X=1 TO LEN(Z$)
30370 Y$=Y$+MID$(Z$,X,1)
30380 CK=CK+ASC(MID$(Z$,X,1))
30390 IF LEN(Y$)=128 THEN 30410
30400 NEXT : GOTO 30320
30410 Z$=MID$(Z$,X+1)
30420 CK=(CK AND 255)
30430 IF CK>256 THEN CK=CK-256 : GOTO 30430
30440 SEC=255 AND (SEC+1)
30450 A$=SOH$+CHR$(SEC)+CHR$(SEC XOR 255)+Y$+CHR$(CK)
30460 PRINT " Send #";SEC; " "; CHR$(13) CHR$(30)
30470 PRINT #1,A$;
30480 GOTO 30200
30490 CK=CK+ASC(" ")*(128-LEN(Y$)):Y$=Y$+SPACE$(128-LEN(Y$)):EOT=-1: GOTO 30420
30500 PRINT "Transmission Ended." : PRINT #1,EOT$; : CLOSE #3 : RETURN 400
30510 PRINT "Transmission Canceled Before Completion" : CLOSE #3 : RETURN 400
50000 CLOSE #1
50010 FL$ = "COM1:"+BAUD$+","+PARITY$+","+LNGTH$+","+STP$+SETTING$
50020 OPEN FL$ AS #1: RETURN
60000 CLS
60010 PRINT "------------------------------------"
60020 PRINT "JR-MODEM.BAS 9-7-84 JODY DONALDSON"
60030 PRINT "for the IBM(R) PC JR. Version 1.01"
60040 PRINT "Based upon IBMODEM.BAS by Russ Lane"
60045 PRINT "Run only as A>BASIC JR-MODEM /C:2048"
60050 PRINT "------------------------------------"
60060 PRINT: PRINT: PRINT: LINE INPUT "Press <RETURN> to continue ... "; DUMMY$
60070 RETURN