Difference between revisions of "Multiplatform programming"

From BeebWiki
Jump to: navigation, search
m (1 revision)
m (Added to See Also.)
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Programming]]
 
[[Category:Programming]]
 
[[Category:BASIC]]
 
[[Category:BASIC]]
On almost every platform that BBC BASIC has been ported to you can call [[OSBYTE_&00|OSBYTE 0]] to find out what the host hardware is, and from that what capabilities the host hardware has.
+
[[Category:Programming tips]]
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 <code>'''ADVAL(7)'''</code>, <code>'''ADVAL(8)'''</code> and see happens).
+
==Filing system structure==
By coincience or design, over the years the value returned forms a bitmap that makes for convenient testing.
+
On almost every platform that BBC BASIC has been ported to you can call
 +
[[OSBYTE_&00|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 <code>'''ADVAL(7)'''</code>,
 +
<code>'''ADVAL(8)'''</code> 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
 
     A%=0:X%=1:os%=((USR&FFF4)AND&FF00)DIV256
 
      
 
      
     IF(os%AND32)=0 THEN Filing system calls to &FFxx are allowed
+
     IF (os% AND -24)=0 THEN paths are :drive.directory.file/ext
 +
    IF (os% AND -24)=8 THEN paths are directory/file.ext
 +
    IF (os% AND -32)  THEN paths are d:directory\file.ext
 
      
 
      
     IF(os%AND40)=0 THEN Directory seperators are '.'
+
     IF (os% AND -24)=0 THEN Directory seperators are '.'
     IF(os%AND40)=8 THEN Directory seperators are '/'
+
     IF (os% AND -24)=8 THEN Directory seperators are '/'
     IF(os%AND32)  THEN Directory seperators are '\'
+
     IF (os% AND -32)  THEN Directory seperators are '\'
 
      
 
      
     IF(os%AND40)=0 THEN Extension seperators are '/'
+
     IF (os% AND -24)=0 THEN Extension seperators are '/'
     IF(os%AND40)  THEN Extension seperators are '.'
+
     IF (os% AND -24)  THEN Extension seperators are '.'
 
      
 
      
     IF(os%AND40)=0 THEN Drive specifiers are :d
+
     IF (os% AND -24)=0 THEN Drive specifiers are :d
     IF(os%AND40)  THEN Drive specifiers are d:
+
     IF (os% AND -24)  THEN Drive specifiers are d:
  
You can then use these tests in platform-independant code, such as in the following examples:
+
You can then use these tests in platform-independant code, such as in the
 +
following example:
  
     d$=".":s$="/":IF(os%AND40):d$="/":s$=".":IF(os%AND32):d$="\"
+
     d$=".":s$="/":IF(os%AND-24):d$="/":s$=".":IF(os%AND-32):d$="\"
 
     filename$=dir$+d$+name$+s$+ext$
 
     filename$=dir$+d$+name$+s$+ext$
   
+
 
    DEFPROCf_gbpb(A%,chn%,adr%,num%,ptr%)
+
==BBC API entries==
    ?X%=chn%:X%!1=adr%:X%!5=num%:X%!9=ptr%
+
On most implementations of BBC BASIC, CALL and USR can be used to access the
    IF(os%AND32)=0:CALL&FFD1:ENDPROC
+
BBC API at &FFxx. Testing for PAGE<&FFFF will tell you if the API is
    IF(A%AND1):PTR#chn%=ptr%
+
available, so you can use code such as:
    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))
+
  REM Read object information:
    X%!1=adr%:X%!5=num%:X%!9=PTR#chn%
+
  IF PAGE<&FFFF THEN $name%=A$:?X%=name%:X%?1=name%DIV256:A%=5:ftype%=(USR&FFDD)AND&FF
    ENDPROC
+
 
 +
  REM Write bytes to file:
 +
  ?X%=channel:X%!1=address,X%!5=count:A%=gbpb_wr
 +
  IF PAGE<&FFFF THEN CALL &FFD1 ELSE REPEAT:BPUT#?X%,?(X%!1):X%!1=X%!1+1:X%!5=X%!5:UNTIL X%!5=0
  
 
==See also==
 
==See also==
 +
* [[Filename translation]]
 +
* [[Pathname translation]]
 +
* [[Filename character mapping]]
 
* The [http://mdfs.net/blib generic FileIO] library uses these techniques.
 
* The [http://mdfs.net/blib generic FileIO] library uses these techniques.
 +
* The [http://mdfs.net/blib#fname FName] BASIC library translates simple filenames.
 +
* The [http://mdfs.net/blib#filename Filename] BASIC library translates full pathnames.
 
* The [http://mdfs.net/blib ProgEnv] library sets <code>'''os%'''</code> and also returns other platform environment parameters such as the command line and the run filename.
 
* The [http://mdfs.net/blib ProgEnv] library sets <code>'''os%'''</code> and also returns other platform environment parameters such as the command line and the run filename.
  
 +
''JGH, 25 April 2011''
 +
[[User:Jgharston|Jgharston]] ([[User talk:Jgharston|talk]]) 06:24, 3 April 2018 (CEST)
 
[[User:Jgharston|Jgharston]] 18:51, 29 November 2010 (UTC)
 
[[User:Jgharston|Jgharston]] 18:51, 29 November 2010 (UTC)
 +
[[User:Jgharston|Jgharston]] ([[User talk:Jgharston|talk]]) 20:54, 3 July 2016 (UTC)
 +
[[User:Jgharston|Jgharston]] ([[User talk:Jgharston|talk]]) 06:27, 3 April 2018 (CEST)

Revision as of 05:27, 3 April 2018

Filing system structure

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% AND -24)=0 THEN paths are :drive.directory.file/ext
   IF (os% AND -24)=8 THEN paths are directory/file.ext
   IF (os% AND -32)   THEN paths are d:directory\file.ext
   
   IF (os% AND -24)=0 THEN Directory seperators are '.'
   IF (os% AND -24)=8 THEN Directory seperators are '/'
   IF (os% AND -32)   THEN Directory seperators are '\'
   
   IF (os% AND -24)=0 THEN Extension seperators are '/'
   IF (os% AND -24)   THEN Extension seperators are '.'
   
   IF (os% AND -24)=0 THEN Drive specifiers are :d
   IF (os% AND -24)   THEN Drive specifiers are d:

You can then use these tests in platform-independant code, such as in the following example:

   d$=".":s$="/":IF(os%AND-24):d$="/":s$=".":IF(os%AND-32):d$="\"
   filename$=dir$+d$+name$+s$+ext$

BBC API entries

On most implementations of BBC BASIC, CALL and USR can be used to access the BBC API at &FFxx. Testing for PAGE<&FFFF will tell you if the API is available, so you can use code such as:

 REM Read object information:
 IF PAGE<&FFFF THEN $name%=A$:?X%=name%:X%?1=name%DIV256:A%=5:ftype%=(USR&FFDD)AND&FF
 
 REM Write bytes to file:  
 ?X%=channel:X%!1=address,X%!5=count:A%=gbpb_wr
 IF PAGE<&FFFF THEN CALL &FFD1 ELSE REPEAT:BPUT#?X%,?(X%!1):X%!1=X%!1+1:X%!5=X%!5:UNTIL X%!5=0

See also

JGH, 25 April 2011 Jgharston (talk) 06:24, 3 April 2018 (CEST) Jgharston 18:51, 29 November 2010 (UTC) Jgharston (talk) 20:54, 3 July 2016 (UTC) Jgharston (talk) 06:27, 3 April 2018 (CEST)