(C) Dominic Beesley 2005 see http://www.brahms.demon.co.uk Connecting a BBC Serial port to Linux ===================================== Here's some notes on connecting a BBC Micro/Master to a Linux box. They are in no particular order, not definitive, no liability for loss or damage blah blah. I merely publish in the hope that they may save you some time in the future. Also this all assumes a reasonable level of competance in Linux and a fair knowledge of how to use a BBC. If you're not sure about using the BBC then there are loads of sources, one of the best being BBC Lives. http://www.nvg.ntnu.no/bbc/index.php3 Cheers Dom Makeing the cable ================= This was done using a BBC Master 128 and a custom made cable. There are various usenet and website articles discussing how to make up a BBC to PC/Linux cable, with a lot of semi-religous ranting about the "correct" way. The way presented here may not be "correct" but it works for me! Pinout RS423 ============ (As viewed into back of computer) B D > C < A E Pinout RS232 9-pin D ==================== 1 2 3 4 5 6 7 8 9 NULL Modem cable ================ BBC Linux === ===== A <- (RX) -----\ +--- 1 <- (CD) B -> (TX) ------\---|--- 2 <- (RX) C -- (GND)---\ \--|--- 3 -> (TX) D <- (CTS)--\ \ +--- 4 -> (DTR) E -> (RTS)-\ \ \-------- 5 -- (GND) \ \ 6 <- (DSR) \ \-------- 7 -> (RTS) \--------- 8 <- (CTS) 9 <- (RI) BBC RX (A) -- LIN TX (3) BBC TX (B) -- LIN RX (2) BBC GND (C) -- LIN GND (5) BBC CTS (D) -- LIN RTS (7) BBC RTS (E) -- LIN CTS (8) LIN CD (1) -- LIN DTR (4) Linux Serial Ports ================== The following assumes you are going to be using /dev/ttyS0 which is COM1 on a PC based Linux box. If not you should substitute the relevant device name. Also note that you may find that the various options mentioned below for handshaking may or may not work. If you have any supplemental information please get in touch and I'll add it in below. On some Linux machines you may find that the serial ports are already set up to accept connections from terminals in which case you may be able to skip some of the initial sections. Terminal software for the BBC ============================= I recommend getting hold of a package called Tequila I got it from: http://www.nvg.ntnu.no/bbc/software.php3 This needs to be transferred to the BBC by some means though! More on that later! Testing your link! ================== First to try and send a file from the Linux box to the BBC... On the BBC type in the following program (a basic terminal emulator): 5 MODE 0 10 *FX 203,50 20 *FX 7,8 30 *FX 8,8 40 *FX 156,20,227 50 *FX 2,2 70 *FX 229,1 85 OSBYTE=&FFF4 90 REPEAT 100 IF ADVAL(-1)>0 AND ADVAL(-3)>0 THEN PROCout 110 IF ADVAL(-2)>0 THEN PROCin 120 UNTIL INKEY(-33) 125 *FX 2 130 END 1000 DEFPROCout 1010 *FX 2,2 1020 A%=138:X%=2 1030 REPEAT 1035 Y%=GET:CALL OSBYTE 1040 UNTIL ADVAL(-1)=0 OR ADVAL(-3)=0 1050 ENDPROC 1100 DEFPROCin 1110 *FX 2,1 1120 REPEAT 1130 C%=GET 1140 IF C%=10 THEN PRINT ELSE VDU C% 1150 UNTIL ADVAL(-2)=0 1155 *FX 2,2 1160 ENDPROC A quick explanation of the code... line 10: sets the receiver to tell Linux to stop sending if there are less than 50 characters left in the RS423 input buffer. This is a bit conservative but its best to be on the safe side at this point. line 20: sets the receive speed to 19200 line 30: sets the transmit speed to 19200 line 40: sets the protocol to 8N1 (8bits, no parity, 1 stop) line 50: enables RS423, selects keyboard as input stream line 70: disables normal ESCape action, instead ESCape key acts as a normal key (producing CHR$27) line 100: if a there are characters in the keyboard input buffer and there is space left in the RS423 transmit buffer then call PROCout line 110: if there are characters in the RS423 receive buffer call PROCin line 120: exit if f0 pressed line 125: disable RS423 make sure keyboard enabled line 130: STOP! lines 1000-1050:while there are still keys in the input buffer and room in the RS423 TX buffer get keys from keyboard (*FX 2,2 selects keyboard as input stream) and send to serial output buffer OSBYTE 138,2,character lines 1100-1160:while there are still characters in the RS423 input buffer read them in (*FX 2,1 selects RS423 for input) and output to screen (convert char 10 to BBC newline/CR) SAVE the program and set it of running If you've got a load of scribble on screen you may already have an agetty program running on Linux (but its not set to the right speed/parity/stop bits). You will need to read up on init/agetty/mgetty/mingetty etc to fix things. If you get a login prompt then you've got agetty already running on Linux that is set to the right parameters - woo yay! Though you may also want to read up on init/getty/agetty/mingetty. If nothing happens then thats ok! Try sending a file to the BBC: First we'll set the serial port up using stty (you may need to be root to do this!). Here the options -clocal says use hardware handshaking - not lo cal (take note of the RTS/CTS lines), crtscts (use RTS/CTS rather than DTR/DSR for handshaking - to use them you'll need a different lead!?!?) stty -F /dev/ttyS0 -clocal crtscts -ispeed 19200 -ospeed 19200 copy to the serial port cat >/dev/ttyS0 if you get garbage double check that the stty settings worked stty -F /dev/ttyS0 -a if that still looks ok there is another problem - dunno what!? try sending some long files and make sure there is no corruption at the BBC end (especially if you want to transfer files using the simple method shown below!) to try sending from BBC to Linux do cat /dev/ttyS0 and scribble nonsense on the BBC then press RETURN Logging into linux as a dumb terminal ===================================== - Get to a terminal prompt and log in as root $ su - - Start agetty or getty on your linux box - this kills the terminal # su - -c "agetty -h /dev/ttyS0 19200" (If you don't have agetty on your system try mgetty, mingetty or uugetty, but they will probably need other parameters) with any luck you should get a login prompt on the BBC, from there you can log in to linux and execute commands, though the formatting codes on linux will come out as lots of square brackets and numbers. (Linux uses ANSI codes which the BBC doesn't natively understand). Type exit to stop the agetty process. If you forget to do this it will stay running on Linux - re run the BBC terminal program to get at it and do an exit! Transferring a file from Linux to BBC ===================================== If you managed to get this far you will probably now want to get a decent terminal program for the BBC so you can use linux properly. I use tequila and find it very good! This consists of two files that need to be transferred to the BEEB. I did this by writing a disc on a RiscPC but if you don't have one here's another way which should work... Download and unzip the tequila files on linux (http://www.nvg.ntnu.no/bbc/software.php3), there should be three: ExecMe - this is an unzip utility (when unpacked) README.txt - read it TequZip - a zip of the Tequila program. We need to ge the ExecMe and TequZip files across the serial link to the BBC and save them on disc. Type the following program in on the BBC: 5 ON ERROR REPORT:PRINT " at ";ERL:OSCLI("FX2"):END 10 INPUT "FILENAME: "A$ 20 out%=OPENOUT A$ 30 *FX 203,50 40 *FX 7,8 50 *FX 8,8 60 *FX 156,20,227 70 *FX 2,2 80 OSBYTE=&FFF4 90 REPEAT 100 IF ADVAL(-2)>0 THEN PROCin 110 UNTIL INKEY(-33) 120 *FX 2 130 CLOSE#out% 140 END 150 DEFPROCin 160 *FX 2,1 170 REPEAT 180 C%=GET 190 BPUT#out%,C% 200 UNTIL ADVAL(-2)=0 210 *FX 2,2 220 ENDPROC And save it. RUN it and when prompted for a filename enter EXECME On the Linux machine: Set the port to 19200 baud with hardware control stty -F /dev/ttyS0 -clocal crtscts -ispeed 19200 -ospeed 19200 Disable all translation of carriage returns to newlines and vice versa stty -F /dev/ttyS0 -ocrnl -onlcr -icrnl -inlcr And send the ExecMe file to the BBC cat ExecMe >/dev/ttyS0 After the disc activity has all stopped wait 30 seconds then press f0 *INFO EXECME should give EXECME WR (01) 00000000 FFFFFFFF 0001726 000????? ======= If the (underlined) length is wrong (especially if it is too short) try again and check you typed everything in right. You should now be able to run execme *EXEC EXECME This will produce two files ZipText and Unzip on the disc (if it works - if not then try re-transferring the file) Now transfer the TequZip file LOAD and RUN the transfer program above on the BBC giving TEQUZIP for the filename On Linux cat TequZip >/dev/ttyS0 Again wait for all disc activity to cease and then 30secs after the transfer and then press f0. (This file will take a few minutes to transfer as the transfer program is inefficient - in an effort to make it short to type!) Now on the BBC type: *UNZIP TEQUZIP This should unzip the TEQUZIP, if you get messages about BAD CRC then try retransferring TEQUZIP You should now have a disc with all the Tequila files on it.... Using Tequila as a Linux Terminal ================================= Using the Tequila program you just transferred you can now connect to Linux as a fully fledged terminal! On the BBC type: *TEQUILA This should load the Tequila terminal program, (note the title screen has a 10 second delay in it for the unregistered version). I suggest reading the Tequila help files at this point! But I was impatient and started in anyway. Before connecting to Linux we need to set some parameters in Tequila. Using the menus (navigate using cursor keys and RETURN) if you get stuck try pressing ESCape to leave a menu, or if you end up in the terminal itself press SHIFT-f0 to get back to the main menu. Use return to change configuration values too. Using the menus you'll need to set the following: (use cursors/RETURN) Display Mode (80 col) Lines (32) Cursor (Block) Auto Linefeed (Off) Local/Remote Echo (Remote) Show control Chars (No) BBC Graphics mode (Off) Filter (Off) Terminal Emulation (vt102) Screen erase type (ansi) PC characters (off) Protocol Baud Rate (19200/19200) (use submenu to set Send/Receive speeds) Parity (8N1) Xon/Xoff (Off) Send Xon/Xoff (No) Send linefeeds (No) Echo to remote (No) Map Delete to CTRL-H (yes) Local options Cursor Editing (No) Cursor Output (ansi) Press ESCape until you come to a blank screen with a flashing cursor then on Linux do: su - -c "agetty -h /dev/ttyS0 19200 vt102" On the BBC you should now get a login prompt! You are now connected! You can execute most Linux commands as normal, no colours though! :p To finish type exit on the BBC Automatically starting a terminal ================================= You can add the line: s0:2345:respawn:/sbin/agetty -h /dev/ttyS0 19200 vt102 to your /etc/inittab file then run telinit q This should make the serial line always run agetty. WARNING: DO NOT do the above if you are not sure that you know how to fix it if it goes horribly wrong! Conclusions =========== I hope the above has been of help in getting you started or may even have been of use in troubleshooting for other users. Whatever enjoy! If you have any comments or questions get in touch with me by visiting http://www.brahms.demon.co.uk Cheers dom