Difference between revisions of "Multiplatform programming"
m |
m (1 revision) |
(No difference)
|
Revision as of 23:58, 28 August 2013
On almost every platform that BBC BASIC has been ported to you can call OSBYTE 0 to find out what the host hardware is, and from that what capabilities the host hardware has.
This can be useful to set various program defaults that cannot be done by making other calls (for instance, any system might have a mouse - just use ADVAL(7)
, ADVAL(8)
and see happens).
By coincience or design, over the years the value returned forms a bitmap that makes for convenient testing.
A%=0:X%=1:os%=((USR&FFF4)AND&FF00)DIV256 IF(os%AND32)=0 THEN Filing system calls to &FFxx are allowed IF(os%AND40)=0 THEN Directory seperators are '.' IF(os%AND40)=8 THEN Directory seperators are '/' IF(os%AND32) THEN Directory seperators are '\' IF(os%AND40)=0 THEN Extension seperators are '/' IF(os%AND40) THEN Extension seperators are '.' IF(os%AND40)=0 THEN Drive specifiers are :d IF(os%AND40) THEN Drive specifiers are d:
You can then use these tests in platform-independant code, such as in the following examples:
d$=".":s$="/":IF(os%AND40):d$="/":s$=".":IF(os%AND32):d$="\" filename$=dir$+d$+name$+s$+ext$ DEFPROCf_gbpb(A%,chn%,adr%,num%,ptr%) ?X%=chn%:X%!1=adr%:X%!5=num%:X%!9=ptr% IF(os%AND32)=0:CALL&FFD1:ENDPROC IF(A%AND1):PTR#chn%=ptr% REPEAT:IF((A%-1)AND2):?adr%=BGET#chn% ELSE BPUT#chn%,?adr% adr%=adr%+1:num%=num%-1:UN.num%=0 OR (EOF#chn% AND ((A%-1)AND2)) X%!1=adr%:X%!5=num%:X%!9=PTR#chn% ENDPROC
See also
- The generic FileIO library uses these techniques.
- The ProgEnv library sets
os%
and also returns other platform environment parameters such as the command line and the run filename.
Jgharston 18:51, 29 November 2010 (UTC)