Difference between revisions of "Reading screen mode"

From BeebWiki
Jump to: navigation, search
(Initial page.)
 
(Corrected BASIC code.)
Line 1: Line 1:
 
[[Category:Programming]]
 
[[Category:Programming]]
 
[[Category:6502]]
 
[[Category:6502]]
[[OSBYTE &87]] returns the current screen mode, and the VDU status byte
+
[[OSBYTE &87]] returns the current screen mode. The VDU status byte returned
returned by [[OSBYTE &75]] has a bit which is set if the current display is
+
by [[OSBYTE &75]] has a bit which is set if the current display is a shadow
a shadow screen mode. However, OSBYTE &87 only returns the base screen mode
+
screen mode. However, OSBYTE &87 only returns the base screen mode 0 to 7,
0 to 7, it does not add &80 if a shadow screen mode is selected. Also, the
+
it does not add &80 if a shadow screen mode is selected. Also, the VDU status
VDU status byte shadow bit is only set by Master series computers. Shadow
+
byte shadow bit is only set on systems where a shadow mode can be selected
screen systems on the BBC use a different memory location. So, neither the
+
by using MODE &80+n (for example, the Master, BBC B+ and BBC Integrex).
current screen mode or the VDU status byte can consistantly tell you if you
 
are using a shadow screen mode.
 
  
==Running on I/O processor==
+
==Reading MODE number==
If a shadow screen is selected the top of user memory, read with
+
The following code will return the current screen mode number in a form that
[[OSBYTE &84]] and returned to BASIC to set HIMEM, will be &8000 or higher.
+
can be then used with the '''[[MODE]]''' command to re-select the same mode:
There are some systems that overlay RAM over the BASIC ROM so HIMEM could
 
even be at &C000 even on the I/O processor. So, the address should be
 
checked to be &8000 or higher, not just exactly &8000. This can be done
 
easily by testing bit 15 of the address.
 
  
  \ Test for shadow screen selected:
+
    mode%=(FNfx(&87,0)DIV256) OR ((FNfx(&75,0)AND&10)*8)
  LDA #&84:JSR OSBYTE  :\ Read top of user memory/bottom of screen
+
    ...
  TYA                  :\ Set flags from address
+
    DEFFNfx(A%,X%):LOCAL Y%:Y%=X%DIV256:=((USR&FFF4)AND&FFFF00)DIV256
  BMI ShadowSelected
 
  BPL ShadowNotSelected
 
  
  \ Read current screen mode, including shadow bit:
+
    LDA #&75:JSR OSBYTE  :\ Read VDU status
  LDA #&87:JSR OSBYTE  :\ Read current screen MODE
+
    TXA:AND #&10:CMP #&10 :\ Test shadow flag in bit 4
  STY tmp
+
    PHP                  :\ Save shadow flag in Carry
  LDA #&84:JSR OSBYTE  :\ Read top of user memory/bottom of screen
+
    LDA #&87:JSR OSBYTE  :\ Read current MODE
  TYA:AND #&80          :\ Keep bit 15 of address
+
    TYA:ASL A:PLP:ROR A   :\ Move shadow flag into bit 7
   ORA tmp              :\ Copy into bit 7 of MODE number
 
  
==Running on a second processor==
+
If this code is used on a BBC with a shadow extension system such as the
If the program is running on a second processor, OSBYTE &84 returns the top
+
Aries or Watford shadow RAM cards it will return 0-7 for shadow screen modes,
of user memory, not the bottom of screen memory, as the user memory and
+
which will correctly re-select the current shadow screen mode, as the shadow
screen memory are in different memory areas.
+
screen mode is selected with a *command and not with MODE &80+n.
  
 +
==Reading shadow screen state==
 +
If you just want to know if a shadow screen mode is currently being used
 +
and you are running in the I/O processor (eg, you are a sideways ROM or a
 +
transient utility) you can use [[OSBYTE &84]] to read the top of user
 +
memory. This will only work on the I/O processor, and will be &8000 or
 +
higher if a shadow screen is currently being used. There are some systems
 +
that overlay RAM over the BASIC ROM so HIMEM could even be at &C000 even on
 +
the I/O processor. So, the address should be checked to be &8000 or higher,
 +
not just exactly &8000. This can be done easily by testing bit 15 of the
 +
address.
  
 +
    \ Test for shadow screen selected if in I/O memory:
 +
    LDA #&84:JSR OSBYTE  :\ Read top of user memory/bottom of screen
 +
    TYA                  :\ Set flags from address
 +
    BMI ShadowSelected
 +
    BPL ShadowNotSelected
 +
 +
OSBYTE &84 returns the top of user memory in the memory space of the caller,
 +
if called from a language it will always return the top of user memory in
 +
the language processor, not the I/O processor. To correctly find the shadow
 +
screen state from a language the following code checks what the bottom of
 +
screen in the I/O processor would be if the current screen mode is reselected:
 +
 +
    shadow%=(FNfx(&85,(FNfx(&87,0)DIV256) OR ((FNfx(&75,0)AND&10)*8)))>&7FFF
  
 
==See Also==
 
==See Also==
 +
* [[MODE]]
 +
* [[OSBYTE &75]]
 
* [[OSBYTE &84]]
 
* [[OSBYTE &84]]
 +
* [[OSBYTE &85]]
 
* [[OSBYTE &87]]
 
* [[OSBYTE &87]]
 
* [[Paging in video memory]]
 
* [[Paging in video memory]]
* http://mdfs.net/Docs/Comp/BBC/Osbyte00
+
* http://mdfs.net/Docs/Comp/BBC/Osbyte80
  
 
[[User:Jgharston|Jgharston]] ([[User talk:Jgharston|talk]]) 20:39, 3 April 2015 (UTC)
 
[[User:Jgharston|Jgharston]] ([[User talk:Jgharston|talk]]) 20:39, 3 April 2015 (UTC)
 +
[[User:Jgharston|Jgharston]] ([[User talk:Jgharston|talk]]) 23:37, 4 February 2017 (UTC)

Revision as of 01:37, 5 February 2017

OSBYTE &87 returns the current screen mode. The VDU status byte returned by OSBYTE &75 has a bit which is set if the current display is a shadow screen mode. However, OSBYTE &87 only returns the base screen mode 0 to 7, it does not add &80 if a shadow screen mode is selected. Also, the VDU status byte shadow bit is only set on systems where a shadow mode can be selected by using MODE &80+n (for example, the Master, BBC B+ and BBC Integrex).

Reading MODE number

The following code will return the current screen mode number in a form that can be then used with the MODE command to re-select the same mode:

   mode%=(FNfx(&87,0)DIV256) OR ((FNfx(&75,0)AND&10)*8)
   ...
   DEFFNfx(A%,X%):LOCAL Y%:Y%=X%DIV256:=((USR&FFF4)AND&FFFF00)DIV256
   LDA #&75:JSR OSBYTE   :\ Read VDU status
   TXA:AND #&10:CMP #&10 :\ Test shadow flag in bit 4
   PHP                   :\ Save shadow flag in Carry
   LDA #&87:JSR OSBYTE   :\ Read current MODE
   TYA:ASL A:PLP:ROR A   :\ Move shadow flag into bit 7

If this code is used on a BBC with a shadow extension system such as the Aries or Watford shadow RAM cards it will return 0-7 for shadow screen modes, which will correctly re-select the current shadow screen mode, as the shadow screen mode is selected with a *command and not with MODE &80+n.

Reading shadow screen state

If you just want to know if a shadow screen mode is currently being used and you are running in the I/O processor (eg, you are a sideways ROM or a transient utility) you can use OSBYTE &84 to read the top of user memory. This will only work on the I/O processor, and will be &8000 or higher if a shadow screen is currently being used. There are some systems that overlay RAM over the BASIC ROM so HIMEM could even be at &C000 even on the I/O processor. So, the address should be checked to be &8000 or higher, not just exactly &8000. This can be done easily by testing bit 15 of the address.

   \ Test for shadow screen selected if in I/O memory:
   LDA #&84:JSR OSBYTE   :\ Read top of user memory/bottom of screen
   TYA                   :\ Set flags from address
   BMI ShadowSelected
   BPL ShadowNotSelected

OSBYTE &84 returns the top of user memory in the memory space of the caller, if called from a language it will always return the top of user memory in the language processor, not the I/O processor. To correctly find the shadow screen state from a language the following code checks what the bottom of screen in the I/O processor would be if the current screen mode is reselected:

   shadow%=(FNfx(&85,(FNfx(&87,0)DIV256) OR ((FNfx(&75,0)AND&10)*8)))>&7FFF

See Also

Jgharston (talk) 20:39, 3 April 2015 (UTC) Jgharston (talk) 23:37, 4 February 2017 (UTC)