home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / b / bbc2rpc / BBC2RPC_TX next >
Encoding:
Text File  |  1997-01-25  |  7.1 KB  |  177 lines

  1.    10 REM *************************************************************
  2.    20 REM * File Transfer Program                                     *
  3.    30 REM * BBC <-> Risc PC                                           *
  4.    40 REM * By Paul Theobald                                          *
  5.    50 REM *************************************************************
  6.    60 
  7.    70 REM Set up error handler
  8.    80 ON ERROR PROCreset:REPORT:PRINT " at line ";ERL:END
  9.    90 
  10.   100 REM Main loop
  11.   110 PROCinit
  12.   120 REPEAT
  13.   130 PRINT "(S)end, (R)eceive, (*) command, (Q)uit?";
  14.   140 REPEAT
  15.   150 option$ = GET$
  16.   160 IF option$ <> "*" THEN option$=CHR$(ASC(option$) AND &DF)
  17.   170 UNTIL option$="S" OR option$="R" OR option$="*" OR option$="Q"
  18.   180 PRINT option$
  19.   190 IF option$ = "S" THEN PROCsend
  20.   200 IF option$ = "R" THEN PROCreceive
  21.   210 IF option$ = "*" THEN INPUT "*" command$:OSCLI(command$)
  22.   220 PROCreset
  23.   221 UNTIL option$ = "Q"
  24.   240 END
  25.   250 
  26.   260 REM *************************************************************
  27.   270 REM * Initialise variables                                      *
  28.   280 REM *************************************************************
  29.   290 DEF PROCinit
  30.   300 baud_rate%        = 7     : REM 9600 baud transfer rate
  31.   310 file_name_length% = 7     : REM Max size of file name for BBC DFS
  32.   320 file_size_length% = 4     : REM Max size of file is &FFFFFFFF
  33.   330 osbyte%           = &FFF4 : REM OSBYTE call address
  34.   340 sync_text$ = "BBC<->RPC"  : REM Text indicating start of transfer 
  35.   350 ENDPROC
  36.   360 
  37.   370 REM *************************************************************
  38.   380 REM * Receive a file                                            *
  39.   390 REM *************************************************************
  40.   400 DEF PROCreceive
  41.   410 PRINT "Waiting for remote end..."
  42.   420 REM Set receive baud rate
  43.   430 A% = 7:X% = baud_rate%:CALL osbyte%
  44.   440 REM Open the serial port for input
  45.   450 *FX 2,1
  46.   460 REM Flush the serial port input buffer
  47.   470 *FX 21,1
  48.   480 REM Read in the sync text to check we're receiving valid data
  49.   490 this_text$ = FNread_string(LEN(sync_text$))
  50.   500 IF this_text$ <> sync_text$ THEN PRINT "Invalid data received, please try again.":ENDPROC
  51.   510 REM Read in the file name
  52.   520 file_name$ = FNread_string(file_name_length%)
  53.   530 REM Read in the file length
  54.   540 file_size% = FNread_integer(file_size_length%)
  55.   550 REM Display file details
  56.   560 PRINT "Receiving:"
  57.   570 PRINT "File name   = ";file_name$
  58.   580 PRINT "File length = ";file_size%
  59.   590 REM Create a local file of the same name
  60.   600 file_handle% = OPENOUT(file_name$)
  61.   610 REM Copy in the file contents
  62.   620 PROCread_data(file_handle%, file_size%)
  63.   630 REM Close the file
  64.   640 CLOSE#file_handle%
  65.   650 REM Close the serial port and reselect keyboard input
  66.   660 *FX 2,0
  67.   670 ENDPROC
  68.   680 
  69.   690 REM *************************************************************
  70.   700 REM * Send a file                                               *
  71.   710 REM *************************************************************
  72.   720 DEF PROCsend
  73.   730 REM Input a file name and truncate/lengthen to standard length
  74.   740 INPUT"Filename: " file_name$
  75.   750 file_name$ = LEFT$(file_name$, file_name_length%)
  76.   760 file_name$ = file_name$+STRING$(file_name_length%-LEN(file_name$)," ")
  77.   770 REM Open the file or report an error if we can't
  78.   780 file_handle% = OPENIN(file_name$)
  79.   790 IF file_handle% = 0 THEN PRINT "Can't open file """;file_name$;""", please try again.":ENDPROC
  80.   800 REM Find the file size
  81.   810 file_size% = EXT#file_handle%
  82.   820 REM Display file details
  83.   830 PRINT "Sending:"
  84.   840 PRINT "File name   = ";file_name$
  85.   850 PRINT "File length = ";file_size%
  86.   860 REM Set transmit baud rate
  87.   870 A% = 8:X% = baud_rate%:CALL osbyte%
  88.   880 REM Select the serial port for output
  89.   890 *FX 3,3
  90.   900 REM Flush the serial port output buffer
  91.   910 *FX 21,2
  92.   920 REM Send the sync text to indicate start of transfer
  93.   930 PROCwrite_string(sync_text$, LEN(sync_text$))
  94.   960 REM Send the file name
  95.   970 PROCwrite_string(file_name$, file_name_length%)
  96.   980 REM Send the file size
  97.   990 PROCwrite_integer(file_size%,file_size_length%)
  98.  1000 REM Copy out the file contents
  99.  1010 PROCwrite_data(file_handle%, file_size%)
  100.  1020 REM Close the file
  101.  1030 CLOSE#file_handle%
  102.  1040 REM Reselect VDU output
  103.  1050 *FX 3,0
  104.  1060 ENDPROC
  105.  1070 
  106.  1080 REM *************************************************************
  107.  1090 REM * Reset configuration                                       *
  108.  1100 REM *************************************************************
  109.  1110 DEF PROCreset
  110.  1120 REM Close the serial port and reselect keyboard input
  111.  1130 *FX 2,0
  112.  1140 REM Reselect VDU output
  113.  1150 *FX 3,0
  114.  1160 REM Close any remaining open files
  115.  1170 CLOSE#0
  116.  1180 ENDPROC
  117.  1190 
  118.  1200 REM *************************************************************
  119.  1210 REM * Read in a string of specified length                      *
  120.  1220 REM *************************************************************
  121.  1230 DEF FNread_string(length%)
  122.  1240 LOCAL loop%, string$
  123.  1250 string$ = ""
  124.  1260 FOR loop% = 1 TO length%
  125.  1270 string$ = string$ + GET$
  126.  1280 NEXT
  127.  1290 = string$
  128.  1300 
  129.  1310 REM *************************************************************
  130.  1320 REM * Read in an integer of specified length                    *
  131.  1330 REM *************************************************************
  132.  1340 DEF FNread_integer(length%)
  133.  1350 LOCAL loop%, integer%
  134.  1360 integer% = 0
  135.  1370 FOR loop% = 1 TO length%
  136.  1380 integer% = integer% * 256 + GET
  137.  1390 NEXT
  138.  1400 = integer%
  139.  1410 
  140.  1420 REM *************************************************************
  141.  1430 REM * Read in data of specified length to a file                *
  142.  1440 REM *************************************************************
  143.  1450 DEF PROCread_data(file_handle%,length%)
  144.  1460 LOCAL loop%
  145.  1470 FOR loop% = 1 TO length%
  146.  1480 BPUT#file_handle%,GET
  147.  1490 NEXT
  148.  1500 ENDPROC
  149.  1510 
  150.  1520 REM *************************************************************
  151.  1530 REM * Write out a string of specified length                    *
  152.  1540 REM *************************************************************
  153.  1550 DEF PROCwrite_string(string$,length%)
  154.  1560 PRINT LEFT$(string$,length%);
  155.  1570 ENDPROC
  156.  1580 
  157.  1590 REM *************************************************************
  158.  1600 REM * Write out an integer of specified length                  *
  159.  1610 REM *************************************************************
  160.  1620 DEF PROCwrite_integer(integer%,length%)
  161.  1630 LOCAL loop%
  162.  1640 FOR loop% = 1 TO length%
  163.  1650 VDU integer% DIV (256 ^ (4-loop%)) MOD 256
  164.  1660 NEXT
  165.  1670 ENDPROC
  166.  1680 
  167.  1690 REM *************************************************************
  168.  1700 REM * Write out data of specified length from a file            *
  169.  1710 REM *************************************************************
  170.  1720 DEF PROCwrite_data(file_handle%,length%)
  171.  1730 LOCAL loop%
  172.  1740 FOR loop% = 1 TO length%
  173.  1750 VDU BGET#file_handle%
  174.  1760 NEXT
  175.  1770 ENDPROC
  176.  1780 
  177.