Reading screen mode

From BeebWiki
Jump to: navigation, search

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)