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.  
  3.    20 REM * File Transfer Program                                     *
  4.  
  5.    30 REM * BBC <-> Risc PC                                           *
  6.  
  7.    40 REM * By Paul Theobald                                          *
  8.  
  9.    50 REM *************************************************************
  10.  
  11.    60 
  12.  
  13.    70 REM Set up error handler
  14.  
  15.    80 ON ERROR PROCreset:REPORT:PRINT " at line ";ERL:END
  16.  
  17.    90 
  18.  
  19.   100 REM Main loop
  20.  
  21.   110 PROCinit
  22.  
  23.   120 REPEAT
  24.  
  25.   130 PRINT "(S)end, (R)eceive, (*) command, (Q)uit?";
  26.  
  27.   140 REPEAT
  28.  
  29.   150 option$ = GET$
  30.  
  31.   160 IF option$ <> "*" THEN option$=CHR$(ASC(option$) AND &DF)
  32.  
  33.   170 UNTIL option$="S" OR option$="R" OR option$="*" OR option$="Q"
  34.  
  35.   180 PRINT option$
  36.  
  37.   190 IF option$ = "S" THEN PROCsend
  38.  
  39.   200 IF option$ = "R" THEN PROCreceive
  40.  
  41.   210 IF option$ = "*" THEN INPUT "*" command$:OSCLI(command$)
  42.  
  43.   220 PROCreset
  44.  
  45.   221 UNTIL option$ = "Q"
  46.  
  47.   240 END
  48.  
  49.   250 
  50.  
  51.   260 REM *************************************************************
  52.  
  53.   270 REM * Initialise variables                                      *
  54.  
  55.   280 REM *************************************************************
  56.  
  57.   290 DEF PROCinit
  58.  
  59.   300 baud_rate%        = 7     : REM 9600 baud transfer rate
  60.  
  61.   310 file_name_length% = 7     : REM Max size of file name for BBC DFS
  62.  
  63.   320 file_size_length% = 4     : REM Max size of file is &FFFFFFFF
  64.  
  65.   330 osbyte%           = &FFF4 : REM OSBYTE call address
  66.  
  67.   340 sync_text$ = "BBC<->RPC"  : REM Text indicating start of transfer 
  68.  
  69.   350 ENDPROC
  70.  
  71.   360 
  72.  
  73.   370 REM *************************************************************
  74.  
  75.   380 REM * Receive a file                                            *
  76.  
  77.   390 REM *************************************************************
  78.  
  79.   400 DEF PROCreceive
  80.  
  81.   410 PRINT "Waiting for remote end..."
  82.  
  83.   420 REM Set receive baud rate
  84.  
  85.   430 A% = 7:X% = baud_rate%:CALL osbyte%
  86.  
  87.   440 REM Open the serial port for input
  88.  
  89.   450 *FX 2,1
  90.  
  91.   460 REM Flush the serial port input buffer
  92.  
  93.   470 *FX 21,1
  94.  
  95.   480 REM Read in the sync text to check we're receiving valid data
  96.  
  97.   490 this_text$ = FNread_string(LEN(sync_text$))
  98.  
  99.   500 IF this_text$ <> sync_text$ THEN PRINT "Invalid data received, please try again.":ENDPROC
  100.  
  101.   510 REM Read in the file name
  102.  
  103.   520 file_name$ = FNread_string(file_name_length%)
  104.  
  105.   530 REM Read in the file length
  106.  
  107.   540 file_size% = FNread_integer(file_size_length%)
  108.  
  109.   550 REM Display file details
  110.  
  111.   560 PRINT "Receiving:"
  112.  
  113.   570 PRINT "File name   = ";file_name$
  114.  
  115.   580 PRINT "File length = ";file_size%
  116.  
  117.   590 REM Create a local file of the same name
  118.  
  119.   600 file_handle% = OPENOUT(file_name$)
  120.  
  121.   610 REM Copy in the file contents
  122.  
  123.   620 PROCread_data(file_handle%, file_size%)
  124.  
  125.   630 REM Close the file
  126.  
  127.   640 CLOSE#file_handle%
  128.  
  129.   650 REM Close the serial port and reselect keyboard input
  130.  
  131.   660 *FX 2,0
  132.  
  133.   670 ENDPROC
  134.  
  135.   680 
  136.  
  137.   690 REM *************************************************************
  138.  
  139.   700 REM * Send a file                                               *
  140.  
  141.   710 REM *************************************************************
  142.  
  143.   720 DEF PROCsend
  144.  
  145.   730 REM Input a file name and truncate/lengthen to standard length
  146.  
  147.   740 INPUT"Filename: " file_name$
  148.  
  149.   750 file_name$ = LEFT$(file_name$, file_name_length%)
  150.  
  151.   760 file_name$ = file_name$+STRING$(file_name_length%-LEN(file_name$)," ")
  152.  
  153.   770 REM Open the file or report an error if we can't
  154.  
  155.   780 file_handle% = OPENIN(file_name$)
  156.  
  157.   790 IF file_handle% = 0 THEN PRINT "Can't open file """;file_name$;""", please try again.":ENDPROC
  158.  
  159.   800 REM Find the file size
  160.  
  161.   810 file_size% = EXT#file_handle%
  162.  
  163.   820 REM Display file details
  164.  
  165.   830 PRINT "Sending:"
  166.  
  167.   840 PRINT "File name   = ";file_name$
  168.  
  169.   850 PRINT "File length = ";file_size%
  170.  
  171.   860 REM Set transmit baud rate
  172.  
  173.   870 A% = 8:X% = baud_rate%:CALL osbyte%
  174.  
  175.   880 REM Select the serial port for output
  176.  
  177.   890 *FX 3,3
  178.  
  179.   900 REM Flush the serial port output buffer
  180.  
  181.   910 *FX 21,2
  182.  
  183.   920 REM Send the sync text to indicate start of transfer
  184.  
  185.   930 PROCwrite_string(sync_text$, LEN(sync_text$))
  186.  
  187.   960 REM Send the file name
  188.  
  189.   970 PROCwrite_string(file_name$, file_name_length%)
  190.  
  191.   980 REM Send the file size
  192.  
  193.   990 PROCwrite_integer(file_size%,file_size_length%)
  194.  
  195.  1000 REM Copy out the file contents
  196.  
  197.  1010 PROCwrite_data(file_handle%, file_size%)
  198.  
  199.  1020 REM Close the file
  200.  
  201.  1030 CLOSE#file_handle%
  202.  
  203.  1040 REM Reselect VDU output
  204.  
  205.  1050 *FX 3,0
  206.  
  207.  1060 ENDPROC
  208.  
  209.  1070 
  210.  
  211.  1080 REM *************************************************************
  212.  
  213.  1090 REM * Reset configuration                                       *
  214.  
  215.  1100 REM *************************************************************
  216.  
  217.  1110 DEF PROCreset
  218.  
  219.  1120 REM Close the serial port and reselect keyboard input
  220.  
  221.  1130 *FX 2,0
  222.  
  223.  1140 REM Reselect VDU output
  224.  
  225.  1150 *FX 3,0
  226.  
  227.  1160 REM Close any remaining open files
  228.  
  229.  1170 CLOSE#0
  230.  
  231.  1180 ENDPROC
  232.  
  233.  1190 
  234.  
  235.  1200 REM *************************************************************
  236.  
  237.  1210 REM * Read in a string of specified length                      *
  238.  
  239.  1220 REM *************************************************************
  240.  
  241.  1230 DEF FNread_string(length%)
  242.  
  243.  1240 LOCAL loop%, string$
  244.  
  245.  1250 string$ = ""
  246.  
  247.  1260 FOR loop% = 1 TO length%
  248.  
  249.  1270 string$ = string$ + GET$
  250.  
  251.  1280 NEXT
  252.  
  253.  1290 = string$
  254.  
  255.  1300 
  256.  
  257.  1310 REM *************************************************************
  258.  
  259.  1320 REM * Read in an integer of specified length                    *
  260.  
  261.  1330 REM *************************************************************
  262.  
  263.  1340 DEF FNread_integer(length%)
  264.  
  265.  1350 LOCAL loop%, integer%
  266.  
  267.  1360 integer% = 0
  268.  
  269.  1370 FOR loop% = 1 TO length%
  270.  
  271.  1380 integer% = integer% * 256 + GET
  272.  
  273.  1390 NEXT
  274.  
  275.  1400 = integer%
  276.  
  277.  1410 
  278.  
  279.  1420 REM *************************************************************
  280.  
  281.  1430 REM * Read in data of specified length to a file                *
  282.  
  283.  1440 REM *************************************************************
  284.  
  285.  1450 DEF PROCread_data(file_handle%,length%)
  286.  
  287.  1460 LOCAL loop%
  288.  
  289.  1470 FOR loop% = 1 TO length%
  290.  
  291.  1480 BPUT#file_handle%,GET
  292.  
  293.  1490 NEXT
  294.  
  295.  1500 ENDPROC
  296.  
  297.  1510 
  298.  
  299.  1520 REM *************************************************************
  300.  
  301.  1530 REM * Write out a string of specified length                    *
  302.  
  303.  1540 REM *************************************************************
  304.  
  305.  1550 DEF PROCwrite_string(string$,length%)
  306.  
  307.  1560 PRINT LEFT$(string$,length%);
  308.  
  309.  1570 ENDPROC
  310.  
  311.  1580 
  312.  
  313.  1590 REM *************************************************************
  314.  
  315.  1600 REM * Write out an integer of specified length                  *
  316.  
  317.  1610 REM *************************************************************
  318.  
  319.  1620 DEF PROCwrite_integer(integer%,length%)
  320.  
  321.  1630 LOCAL loop%
  322.  
  323.  1640 FOR loop% = 1 TO length%
  324.  
  325.  1650 VDU integer% DIV (256 ^ (4-loop%)) MOD 256
  326.  
  327.  1660 NEXT
  328.  
  329.  1670 ENDPROC
  330.  
  331.  1680 
  332.  
  333.  1690 REM *************************************************************
  334.  
  335.  1700 REM * Write out data of specified length from a file            *
  336.  
  337.  1710 REM *************************************************************
  338.  
  339.  1720 DEF PROCwrite_data(file_handle%,length%)
  340.  
  341.  1730 LOCAL loop%
  342.  
  343.  1740 FOR loop% = 1 TO length%
  344.  
  345.  1750 VDU BGET#file_handle%
  346.  
  347.  1760 NEXT
  348.  
  349.  1770 ENDPROC
  350.  
  351.  1780 
  352.  
  353.