6502 to ARM - Application Note ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Name: 0310063 Version: 0.02 History: 0.01: Undated : started. 0.02: 15-Feb-89: updated for release on SID CONTENTS Foreword Introduction Legal issues ARM BASIC 6502 Emulation Evaluation of portability Transfer Running Instructions Available resources FOREWORD The term 6502 is used in this document to refer to the following Acorn products based on the 6502 microprocessor: BBC Model B BBC Model B+ Electron BBC Master 128 Master Compact ARM is short for Acorn RISC Machine. This is the RISC (Reduced Instruction Set Chip) microprocessor at the heart of the Archimedes architecture. Products of Acorn Computers Limited are subject to continuous development and improvement, and so the information contained in this document is subject to change without notice. Moreover, while every effort has been made for accuracy at the time of writing, it is acknowledged that there may be errors or omissions in this note. It is inevitable that much of the content of this document is of a technical nature. INTRODUCTION This document looks at the issues involved in porting software for Acorn's 6502-based microcomputers onto the Archimedes range of microcomputers. It is written to help you identify which items of software may run on the Archimedes microcomputer, and how to transfer them and get them running. It also covers resources available to help in porting software. It is primarily targetted at the broad base of 6502-based educational software used in schools and colleges. Before you attempt to port existing software on to the Archimedes microcomputer, you need to consider the following questions: is it legal? is it likely to run? will it run native, or under 6502 emulation? how can the software be transferred? what running instructions are needed? IS IT LEGAL? You can ignore this question if it is a program that you have written yourself, but commercial software is sold subject to terms and conditions which you must comply with. This is covered in the chapter entitled LEGAL ISSUES. IS IT LIKELY TO RUN? Whether a particular piece of software for a 6502-based machine will run on the Archimedes microcomputer will depend on how the program has been written. If you are dealing with a number of programs, then it would be worth considering the likelihood of success before spending time transferring and attempting to run the software. Further details are given in the chapter entitled EVALUATION OF PORTABILITY. WILL IT RUN NATIVE, OR UNDER 6502 EMULATION? Native The version of BBC BASIC (BASIC 5) developed for the ARM may be referred to in this document and elsewhere as being native to the Archimedes microcomputer. You can attempt to run programs written in BASIC for the 6502-based microcomputers, using ARM BASIC on the Archimedes microcomputer, provided that the programs are written entirely in BASIC and contain no Assembler. Further details are given in the chapter entitled ARM BASIC. 6502 Emulation In addition to programs written entirely in BASIC, you can attempt to run 6502 machine code programs and BASIC programs that assemble or call 6502 machine code routines using the 6502 emulator. Further details are given in the chapter entitled 6502 EMULATION. HOW CAN THE SOFTWARE BE TRANSFERRED? Before you can attempt to run 6502-based software on the Archimedes microcomputer, you need to find a means of transfer from its current medium (e.g. 5.25" disc in DFS format) to a medium accessible to the Archimedes microcomputer (e.g. 3.5" disc in ADFS format). This is covered in the chapter entitled TRANSFER. WHAT RUNNING INSTRUCTIONS ARE NEEDED? You may need to use modified running instructions in order to get the software started on the Archimedes microcomputer. Guidance and suggestions for this are provided in the chapter entitled RUNNING INSTRUCTIONS. LEGAL ISSUES COPYRIGHT Unless you are dealing with software already on 3.5" ADFS format disc, attempting to port software to the Archimedes microcomputer will necessarily entail copying the software. For the purpose of copyright in this country, software is regarded as a work of art. Making an unauthorised copy of an item of software for which you do not hold the copyright is against the law. It is your responsibility to ensure that you comply with the law, and you will need to consider which of the following applies with a particular item of software: Your own programs If you have written the program, you automatically hold the copyright unless you assign the rights to another party. You are free to copy the program. Commercial software It is essential that you consult the terms and conditions of sale of a particular item of commercially available software. The terms may make provision for making a number of copies (e.g. under a licence scheme within an institution), a single back-up copy, or no copies at all. Aside from copying, the conditions of sale may specify hardware or mode of use. For example, that you can not use a disc version on a network. In general, the conditions will not bar you from running the software on a machine other than that for which it was intended (e.g. running a package for the BBC Model B on the Archimedes microcomputer), but consult the section on Support. Public Domain Some software is distributed free of charge, or with a nominal charge to cover costs. However, although you will be free to make a copy, there may be further conditions that you will need to comply with (registering yourself as a user, for example). Some software is available on a similar basis, but within the confines of the LEA where it was developed. SUPPORT In general, there are conditions specifying the guarantee and support that go with the purchase of an item of commercially available software. It is very likely that use of the software on a system other than that specified will void the guarantee and the vendor's obligation to provide support. Thus, if you port a title for the BBC Model B onto the Archimedes microcomputer, and find that it does not work, you should not expect any help from the supplier of the software title. ARM BASIC Any program written in BASIC for the 6502-based microcomputers will probably run without modification on the Archimedes microcomputer, provided that it does not exhibit any of the following: 6502 assembler, or accessing 6502 machine code. assuming the value of PAGE or HIMEM. using the indirection operators ($,! and ?) to access locations in the OS workspace. accessing undocumented OS routines with CALL or USR( ). using *commands that require a particular extension (e.g.*DISC for the DFS). In addition to these general points, loading or saving screen files to and from screen memory and likewise for user-defined graphics characters to and from Page C will not work. The way sound is handled is completely different on the Archimedes, so that programs which use sound may produce strange and unexpected effects. The SOUND and ENVELOPE statements are ignored by ARM BASIC. More information can be obtained in the application note entitled Archimedes 6502 Emulation 0340011. This note considers features of 6502 software which would give problems when run native on the Archimedes microcomputer, and indicates if 6502 emulation could provide the solution. 6502 EMULATION There are two 6502 emulators for the Archimedes microcomputer, called 65Arthur and BBCrun. 65ARTHUR 65Arthur is a program provided on the Archimedes Welcome disc which emulates the 6502 second processor. By using this emulator, you can attempt to run 6502 machine code programs on the Archimedes microcomputer. 65Arthur comes supplied with a 6502 BASIC, so that you can also try programs written entirely in BASIC, including those that contain Assembler source, or a combination of BASIC and machine code. 65Arthur also supports other languages for the 6502-based machines, such as LOGO, COMAL and VIEW, (since, like the BASIC interpreter, they are 6502 machine code programs) so that you can run LOGO or COMAL programs in emulation mode on the Archimedes microcomputer, or edit documents in VIEW. To summarise: Software written in..... On ARM, you can try..... BASIC only. Native BASIC or 65Arthur. 6502 Machine Code only. 65Arthur. BASIC and Machine Code. 65Arthur. Other: LOGO 65Arthur. COMAL VIEW documents etc. Invoking 65Arthur 65Arthur is supplied on your Archimedes Welcome disk in the Modules directory. With the Welcome disk in the disc drive, you can run 65Arthur from the desktop (consult your Welcome Guide), or leave the desktop and type *Modules.65Arthur followed by pressing RETURN. Setting PAGE When 65Arthur is invoked, it starts BASIC with PAGE=&800. You can change this to a requisite value before running an application by using the *PAGE command. For example, to set PAGE=&1900: type *PAGE=&1900, followed by pressing RETURN then *BASIC, followed by pressing RETURN. Software development 65Arthur provides a way forward for software developers who wish to add the Archimedes microcomputer to a range of target machines for their applications. Specifically, it enables the incorporation of 6502 code in the application. In particular, this will be useful for CAL software developers in the short and medium term who want their applications running on Archimedes alongside the BBC Model B and Master in the classroom. BBCRUN BBCrun is a modified version of 65Arthur designed to emulate some features of the BBC Model B. It is primarily targetted at CAL packages developed to run with the DFS (Disk Filing System) on the Model B as the minimum environment. Thus programs that do not work with 65Arthur, the pure 6502 emulator, may work with BBCrun. It is available as part of the suite of programs 'BBC to ARM: Utilities', complete with documentation covering how to use the program etc.. See the section entitled AVAILABLE RESOURCES. RUNNING AN APPLICATION In order to run an application under emulation (whether 65Arthur or BBCrun), you need to invoke the emulator first and then attempt to run the application package. Often, this will amount to running the application's !BOOT file. Alternatively, you can incorporate invoking the emulator in the application's !BOOT file. Please note that the instructions for running the application will probably need modification, and this may involve editing the !BOOT file. More information is given in the section entitled RUNNING INSTRUCTIONS. EVALUATION OF PORTABILITY INTRODUCTION The Archimedes microcomputer has a high degree of commonality with the 6502-based machines, so that there is the comfort of familiarity for end-users and programmers alike. However, it is important to remember that the hardware is completely different and this must temper your expectations as regards portability. Whether a program written for a 6502-based machine will run on the Archimedes depends on how the program has been written and what it is doing at the code level. For this reason, all that can be provided here is a number of generalised statements; we are dealing with 'may' rather than 'can' and for a particular title it is a question of try it and see. RESOURCES (see also the section entitled AVAILABLE RESOURCES) BBCscan You can use the program BBCscan (part of the 'BBC to ARM: Utilities' package) to help identify potential problems in a BASIC program. This has been written to run across the range of Acorn machines, so that you can assess portability before attempting transfer. Application note Archimedes 6502 Emulation 0340011 This classifies features of 6502 programs at the code level that are likely to cause problems on the Archimedes microcomputer, and indicates whether 65Arthur or BBCrun is likely to get round the problem. GENERAL POINTS Software that is 'well behaved' and not tied to a particular filing system has a good chance of running on the Archimedes microcomputer. 'Well behaved' means not making assumptions about the hardware and firmware environment, and using the legal interfaces into the operating system. Thus, programs that have been written to run on a range of 6502 microcomputers are more likely to port onto the Archimedes microcomputer than generic versions. As regards filing systems, software developed for the DFS disc filing system may not port onto the Archimedes, which uses the ADFS (Advanced Disk Filing System). Network versions, on the other hand, are more likely to port. Electron Plus 3 or Master Compact software on disc uses the ADFS, and so is less likely to run into problems owing to the filing system. 65Arthur 65Arthur is a second processor emulator, and so programs which are Tube compatible will probably run with 65Arthur invoked. Arcade-style games will not run under emulation, since they poke the screen for fast animation, but well-written languages will. For example, the Compact VIEW series. Correctly written ROM images will run, providing that they are not protected in any way, or assume that they are located in ROM or sideways RAM. TRANSFER Before you attempt transfer, you must ensure that you are not in breach of copyright (consult the chapter entitled LEGAL ISSUES). A summary of the possible starting points and methods of transfer is given at the end of this section, which is designed to help you quickly identify the method appropriate to your needs. How best to transfer your existing 6502 software, so that it can be tried on the Archimedes microcomputer, will depend on the following factors: the medium the software is on (e.g. 5.25" disc). what 6502 machine(s) you have (e.g. Master 128). the quantity of software involved. The following possibilities, classified according to your starting point, are considered: 3.5" disc. network. 5.25" disc. cassette. ROM. other media - e.g. bar codes. The following hardware routes are considered: keyboard. network. RS423 cable. 5.25" external drive. The information is summarised at the end of this section in the form of a table. STARTING POINT 3.5" disc The Archimedes ADFS supports two formats for floppy disks: D 800k L 640k The L format is the same as that for the Master Compact and Electron Plus 3 (or for a Master 128 with a 3.5" external drive attachment), and so discs in this format can be read by the Archimedes unless they have been copy-protected. In general, no transfer is necessary. Network An Archimedes can be stationed on an Econet network, for which you need to install an Econet module (the same unit as for the Master 128), connect the Archimedes with an Econet lead, and set its station number. This gives you access to the software on the network medium (hard or floppy disc). No transfer is necessary. 5.25" disc You will need to consider one of the possible means of transfer in the next section. Do not attempt to transfer software that is copy-protected. Cassette Since there is no Tape filing system or cassette port on the Archimedes microcomputer, there is no direct means of transferring software from cassette. If you have an Electron Plus 3, use it to copy from cassette to 3.5" disc, which can be read by the Archimedes ADFS. Otherwise, you will need to find another route (e.g. load the program from cassette into memory, and then transfer via the RS423 ports). ROM OTHER MEDIA For software on other media, such as Bar codes, you will need to transfer onto another medium first. MEANS OF TRANSFER Keyboard For a few short BASIC programs, typing them in may be the quickest method of transfer. Network Since you can network a BBC Model B or Master series, by using a local disc drive with it you can copy software onto the network medium, and from there to the Archimedes. This provides a ready means of transferring 5.25" DFS based software to the Archimedes, providing that the discs are not copy-protected. RS423 cable BBC B, B+ or Archimedes Master 128 RS423 >> RS423 5.25" drive 3.5" drive The RS423 port on the Archimedes microcomputer is designed for connecting a modem. As such, any device connected to the port must appear to the computer as a modem in order that the handshaking runs correctly. The pinout of the port runs as follows: Pin 1 DCD Data Carry Detect Pin 1 RXD Receive Data Pin 3 TXD Transmit Data Pin 4 DTR Data Terminal Ready Pin 5 GND Zero Volts Pin 6 DSR Data Set Ready Pin 7 RTS Ready To Send Pin 8 CTS Clear To Send Pin 9 RI Phone Line Ringing The pins are laid out as below, when viewed from the back: 1 2 3 4 5 6 7 8 9 If you want to connect a non-modem device, for example connecting an Archimedes microcomputer back to back with a BBC Model B, the normal arrangement of connecting RTS on one machine to CTS on the other, and RXD on one to TXD on the other, should be used. Further to this however, DCD, DTR and DSR need all to be tied together in order to simulate a modem. At high baud rates, problems will arise if the Archimedes own receive and transmit rates are set differently. This is due to the RS423 controller chip only having one baud rate generator so when different rates are required problems arise. If either transmission or reception at a high rate ( > 4,800 baud) is required, it is important to set both transmit and receive rates the same even if only one direction is being used. Further information is available in application notes; consult the section entitled AVAILABLE RESOURCES. At the time of writing, at least one third party had developed a commercially available RS423 transfer kit for the Archimedes microcomputer. External 5.25" drive You are advised not to attempt to attach a 5.25" drive cable to the current drive unit cable in the Archimedes machine. This may damage a chip, which introduces an undetectable error. Additionally, there can be an excessive load on the Archimedes driver gates from some drives. At the time of writing, at least one independent company was completing work on an external 5.25" drive unit, and you should be able to obtain further information from your dealer. TRANSFER SUMMARY Medium Machine Comment Transfer 3.5" Master Compact may be copy not required ADFS disc Electron Plus 3 protected any any a few short keyboard entry programs Winchester or Econet Net module in not required or floppy disc network Archimedes download onto required 3.5" disc 5.25" Model B, B+ may be copy RS423 cable DFS disc Master 128 protected 5.25" external drive Cassette Electron RS423 cable Model B, B+ Master 128 Electron Plus 3 download onto 3.5" disc ROM any 32 pin Need ROM expansion >= 16K card Other any Transfer to Via available route e.g. bar code other medium first above. RUNNING INSTRUCTIONS The following section is written with a typical eventuality in mind; namely that you have transferred software onto 3.5" disc, probably from 5.25" disc. The software starts from an EXEC !BOOT file, and you may need to note the contents of this file and edit it as appropriate for starting the application on the Archimedes microcomputer. GETTING STARTED BBC Model B etc. The 6502-based microcomputers boot up into BASIC command mode. It is possible to get software on discs to autoboot, i.e. so that the user can place the disk in the drive and press SHIFT + BREAK to start the program. Most commercially available disc-based software is distributed like this. To do this, the start-up option on the disc needs to be set, and a file named !BOOT provided on the disc. Then, in response to SHIFT + BREAK, the computer looks for a !BOOT file and runs it. The !BOOT file will contain a few key instructions needed to get the program running. If !BOOT is a machine code program, the start-up option needs setting to 2. However, you are more likely to encounter !BOOT as an EXEC file, for which the start-up option needs setting to 3. If !BOOT is an EXEC file, you can list the instructions it contains by typing *TYPE !BOOT, followed by pressing RETURN. The Archimedes microcomputer By default, the Archimedes microcomputer boots up into the desktop program (Arthur 0.3 and later). There are three routes available to you to get started. The first circumnavigates the desktop altogether. To get a disk to auto-boot on Archimedes, you need to set the disc option to 2, and you need to provide a !BOOT file which is either ARM machine code or BASIC. An example For example, consider a BASIC program called FRIDA which you have transferred onto a 3.5" disc: place the disc in the disc drive exit from the desktop: move the pointer with the mouse until it is over the EXIT icon, and click the left-hand button. set the start-up option on the disc to 2: type *OPT 4,2, then press RETURN provide a BASIC program as the !BOOT file: type 10 CHAIN "FRIDA", then press RETURN type SAVE "!BOOT", then press RETURN Now, when you press SHIFT + BREAK, the !BOOT file will be run, which in turn runs your program FRIDA. The other two routes require you to work from the desktop, and the existence of a !BOOT file is assumed: exit from the desktop run the !BOOT file by typing in the appropriate commands: e.g. type CH."!BOOT" followed by RETURN in the example above. OR select the disc icon on the icon bar select the !BOOT option from the menu of icons available KEYBOARD Some changes in the running instructions referring to the keyboard may be required. In particular, the red function key f0 on the Model B keyboard is replaced by the PRINT key on the Archimedes keyboard. AVAILABLE RESOURCES APPLICATION NOTES Archimedes 6502 Emulation 0340011 RS423 0310052 These are available on SID (Support Information Database), or write to: Customer Support and Service Dept. Acorn Computers Limited Fulbourn Road Cherry Hinton Cambridge CB1 4JN By surface mail, these are subject to availability and a charge of £2.50 is made per document to cover the costs of reproduction and postage. Please make cheques payable to Acorn Computers Ltd. 65ARTHUR The 6502 second processor emulator provided on the Archimedes Welcome disk. BBC TO ARM: UTILITIES A disc of utility programs, together with examples and supporting documentation, to aid in the conversion of software for the 6502-based microcomputers to the Archimedes range. The programs are: Utilities BBCscan Searches tokenised BBC BASIC programs and flags lines that may cause problems when porting to ARM computers. Runs on the BBC Model B, B+, Master series, Acorn Electron and Archimedes computers. PicConv Converts BBC screen image files and GXR sprites into Archimedes sprites. MODE 7 files are converted for display using *PRINT. Runs on the Archimedes range only. UdgConv Converts files of User Defined Graphics characters, for loading into Page C, back into BASIC VDU statements. MakeDisk Converts an ADFS image of a DFS disk into the form required by BBCrun for DFS emulation. emulators 65Arthur 6502 Second Processor emulator. As supplied on the Archimedes 305/310 Welcome disk. BBCrun A modified version of the emulator, to account for some problematic features of existing BBC 6502 software. These can be obtained from: R.E.S.O.U.R.C.E Exeter Road Off Coventry Grove Doncaster DN2 4PY BBC is an abbreviation of British Broadcasting Corporation. Acorn is a trademark of Acorn Computers Limited. Econet is a registered trademark of Acorn Computers Limited. Archimedes is a trademark of Acorn Computers Limited. C Acorn Computers Limited 1987