BNAMEb BBCBasic on different host machines BDESCRIPTIONb BBCBasic has been implemented on many machines, and it is often useful to find out exactly what hardware a program is running on. On all Acorn hardware, this is simple enough, as INKEY-256 and OSBYTE 0,1 give unique values for the machine you are using. However, some machines do not implement negative INKEYs, and so would just wait about 12 minutes for you to press a key, and some do not let you do an OSBYTE call. There are ways around this though. In this discussion, the following Basics will be refered to: BBCBasic(2/4) 6502 Basic, as supplied in the B and Master BBCBasic(32) 32000 Basic, as supplied with the 32016 co-pro BBCBasic(V) ARM Basic, as supplied in the Archimedes BBCBasic(Z80) Z80 Basic, for Acorn CPM, Torch CPN, Tatung Einstein, Cambridge Z88, Amstrad Notepad, or modified for Tube with BBC I/O BBCBasic(86) 80x86 Basic, for PC machines BBCBasic(X) C-coded Basic, for UNIX platforms BBCBasic(2/4) and BBCBasic(V) could also be called BBCBasic(65) and BBCBasic(ARM). Some of the above can also be run on the Archimedes under emulation. Basic(65), Basic(32) and Basic(ARM) store the program in memory starting from PAGE with a CR, and ending with xx, CR, &FF where xx is the last character of the final line. Basic(Z80) and Basic(86) store the program ending with CR, 00, &FF, &FF. Basic(65), Basic(32) and Basic(ARM) always have access to the MOS and FILE calls and allow INKEY-256. This allows us to use ?(TOP-3)=0 to indicate Z80/86 or 65/32000/ARM, and to indicate whether we can make a call to &FFxx or do INKEY-256. OSBYTE 0,1 will return 6 indicating an Archimedes when running on an emulator. BBCBasic(ARM) running native always has PAGE>&8000. This can be used to indicate native. Basic(86) starts with HIMEM>&FFFF, and BBCBasic(Z80) always has HIMEM<&FFFF, so this check can be used to distinguish between Z80 and 80x86. BBCBasic(86) allows only three MOS calls, OSBYTE 0,1 which returns 32, OSBYTE 135 to read the character at the cursor position and OSWORD 10 to read character definitions Basic(Z80) may run under CPM or not under CPM. All CPM calls go through a jump vector at address &0005. In some Basic(Z80) environments, the &0005 call returns zero to indicate non-CPM mode. In other environments, there isn't a jump vector there at all. If we first test to see if there is a jump vector there and if there is call it with C% set to 12 to ask for the CPM version number, we can find out if we are running under CPM. If the call returns zero, then we are running in a non-CPM environment that allows MOS and FILE calls. If we are running in a non-CPM environment we are probably running on a Cambridge Z88 or an NC100. The Z88 has its reset routine at location 0 starting with a &F3 byte. This distinguishes between Z88 and NC100, neither of which have any MOS or FILE calls. B REM Works on I/O,T6502,Arc,TZ80bbc,PC,CPM,Unix,NC,Z88,Einstein DEFFNOS_GetEnv:LOCAL A%,X%,Y%,A$ cpm%=0:dos%=0:bbc%=0:os%=-1:arc%=0:unix%=0:z88%=0:nc%=0 bbc%=?(TOP-3)<>0:IFNOTbbc%:dos%=HIMEM>&FFFF: IFNOTdos%:cpm%=?5=&C3:IFcpm%:C%=12:IFUSR5=0:bbc%=TRUE:cpm%=0 IFbbc%ORdos%:A%=0:X%=1:os%=(USR&FFF4 AND&FF)DIV256 IFNOTbbc%ANDNOTdos%ANDNOTcpm%:z88%=?0=&F3:nc%=NOTz88%:A$=$&A000 arc%=(os%=6 AND PAGE>&8000):unix%=os%=8:IFos%=32:A$=$&100 IFarc%:LOADATN"OS_GetEnv"TOA$:A$=MID$(A$,1+INSTR(A$," ")) IFLENA$=0:IFbbc%:A$=$&600 ELSE IFLENA$=0:A$=$&3800 A%=INSTR(A$+" "," "):run$=LEFT$(A$,A%-1):IFrun$<>"":=MID$(A$,A%+1) X%=ctrl%:Y%=X%DIV256:A%=9:?X%=0:X%!1=data%:!data%=0:CALL&FFD1: IF!data%AND?data%+data%?2<>8:data%?(1+?data%)=13:=$(data%+1) =""b The above routine returns any command line parameters and sets the following global variables: run$ is set to the command used to start the program, os% contains the host operating system value (see below); cpm%, dos%, bbc%, unix%, arc%, z88% and nc100% are flags indicating what hardware is running. These can be used to indicate the following: os% Host os value (see below) run$ Pathname used to start the program bbc% Calls to &FFxx and INKEY-256 ok, names are :d.$.dirname.leafname cpm% Calls to &0005 allowed, filenames are d:filename.xtn dos% filenames are d:\dirname\filename.xtn unix% filenames are /dirname/filename arc% extended Basic functions allowed nc% running on an Amstrad NC100/150/200 z88% running on a Sinclair Z88 Host OS values returned in os% include the following: -1 : Unknown 6 : Archimedes/Acorn 0 : Electron 7 : Springboard 1 : BBC 8 : Unix 2 : BBC B+ 3 : Master 128 30 : Amstrad CPC 4 : Master ET 31 : Spectrum 5 : Master Compact 32 : IBM-type PC