8-Bit Software

The BBC and Master Computer Public Domain Library

Back to 8BS Or Back to Disassembly


Page Last Altered:

975F MODE

Submitted by Steve Fewell

Description:

Get the result of the expression at BASIC Text Pointer A, convert the result to Integer (Type mismatch error if String),
and Set BASIC Text Pointer A to BASIC Text Pointer B value.
Call &9BA6 to check that the Statement terminates correctly ('Syntax' error is issued if end of statement marker is
not found).

Use OSBYTE #&82 to obtain the Machine high order address.
If the Machine high order address is not &FFFF then jump to &9797 (skip memory restriction tests).

Compare the Stack Pointer (&04-&05) with HIMEM (&06-&07), if they are not equal (i.e. we have items on
Stack, i.e. as the result of local variables inside a PROC/FN call) then issue 'Bad MODE' error, as BASIC will not allow the
screen mode to be altered if there are items on the Stack (as the stack could then get corrupted).
Note: as the stack contains the return details for a PROC/FN call, MODE cannot be issued from within
a proedure or function, even if no local variables have been declared.

Use OSBYTE #&85 to read the top of User RAM for the specified screen mode (&2A) [X=address LSB & Y=address MSB].
Compare the 'Top of User RAM for the specified Mode' with VARTOP (i.e. the heap, or list of declared variables).
If the 'Top of User RAM for the specified Mode' would fall below the VARTOP value, then the program variables would be
corrupted if the Mode was changed - so we are not allowed to change to that mode, and a 'Bad MODE' error is issued.

Compare the 'Top of User RAM for the specified Mode' with TOP (i.e. the end of the program).
If the 'Top of User RAM for the specified Mode' would fall below the TOP value, then the part of the program would be
corrupted if the Mode was changed - so we are not allowed to change to that mode, and a 'Bad MODE' error is issued.

Set HIMEM (&06-&07) and the Stack Pointer to the 'Top of User RAM for the specified Mode' value.
Zero COUNT (&1E), as after a mode change, the screen is clear, and no characters will have been output on the current
line yet.
Output special character 22 (the operating system's Mode change operator (VDU 22)).
Next, output the contents of location &2A (The IWA LSB, which contains the MODE number), this supplies the mode parameter
to the VDU 22 call, and allows the operating system to execute a MODE change to the MODE specified in &2A.
Lastly, jump to &9005 to start processing the next program statement.


Disassembly for the MODE routine

975F o 032 111 146 20 6F 92 JSR &926F Evaluate Expression at BASIC Text pointer A convert result to integer
9762   032 166 155 20 A6 9B JSR &9BA6 Check end of Statement
9765 K 032 075 190 20 4B BE JSR &BE4B Read High Order address (on return X = MSB, Y = LSB)
9768   232 E8 INX
9769 , 208 044 D0 2C BNE 44 --> &9797
976B   200 C8 INY
976C ) 208 041 D0 29 BNE 41 --> &9797
976E   165 004 A5 04 LDA &04
9770   197 006 C5 06 CMP &06
9772   208 197 D0 C5 BNE -59 --> &9739 Bad MODE error
9774   165 005 A5 05 LDA &05
9776   197 007 C5 07 CMP &07
9778   208 191 D0 BF BNE -65 --> &9739 Bad MODE error
977A * 166 042 A6 2A LDX &2A
977C   169 133 A9 85 LDA#&85
977E   032 244 255 20 F4 FF JSR &FFF4 OSBYTE
9781   228 002 E4 02 CPX &02
9783   152 98 TYA
9784   229 003 E5 03 SBC &03
9786   144 177 90 B1 BCC -79 --> &9739 Bad MODE error
9788   228 018 E4 12 CPX &12
978A   152 98 TYA
978B   229 019 E5 13 SBC &13
978D   144 170 90 AA BCC -86 --> &9739 Bad MODE error
978F   134 006 86 06 STX &06
9791   134 004 86 04 STX &04
9793   132 007 84 07 STY &07
9795   132 005 84 05 STY &05
9797 d 100 030 64 1E STZ &1E
9799   169 022 A9 16 LDA#&16
979B   032 238 255 20 EE FF JSR &FFEE OSWRCH
979E * 165 042 A5 2A LDA &2A
97A0 L 128 076 80 4C BRA 76 --> &97EE Output ASCII Character & process next Statement

 


 Back to 8BS
Or