BASIC Mode Selection (on Titanium)
Steve Fryatt (216) 2105 posts |
I’m wondering if I’m missing something. A BASIC program recently came my way which opened with the line
and which, when run on a Titanium that natively operates in “X1920 Y1080 C16M LTRGB F60” on the desktop, reported “Screen mode not available”. I’ve returned this evening to look at it in more detail, and couldn’t see the problem. So I did some more digging, and found that
also failed with “Screen mode not available”, but if I explicitly demand B and R swapping with
then it’s happy, and the program runs. I can sort-of understand the mode string1, but when writing Have I missed something? This is on BASIC 1.81, RISC OS 5.28. 1 Although a mode string without the 2 Which is another argument altogether. |
Rick Murray (539) 13851 posts |
https://www.riscosopen.org/forum/forums/1/topics/16050 When you’re using OS routines and don’t need to care whether it’s RGB or BGR, this is all an unnecessary complication |
Steve Fryatt (216) 2105 posts |
Thanks; I’d obviously missed that. It seems… sub-optimal to add a nice new, user-friendly It’s not a major problem for me, because it just adds another reason to recommend the use of |
Rick Murray (539) 13851 posts |
Yeah, it’s a bit duh. However, source is available. It ought to be a few extra lines to try RGB if the normal (BGR) fails, before giving up. Submit a patch, then it’ll “magically work”. ;-) |
Rick Murray (539) 13851 posts |
Though, to be honest, this should be fixed in the OS. If the user doesn’t explicitly specify a mode type using the mode flags, then OS_ScreenMode ought to set the mode if a definition exists, regardless of the byte ordering. I would imagine a lot of stuff that uses regular OS calls to draw to the screen wouldn’t care which way around the screen was set up. |
Rick Murray (539) 13851 posts |
Edit: I’m talking crap as usual. ;-)
|
Steve Fryatt (216) 2105 posts |
I’m not sure that I follow? The point of In the context I’m interested in for what I’m writing, we’re not looking for a specific screen mode. All we want is a mode, which we can then determine the dimensions of. After that, it’s geometric shapes all the way – and there’s no difference between
or
except that the latter should work in any available mode – albeit with different proportions. (I’ve just written that off the top of my head, so I’m quite prepared to accept that the maths is wrong.) Oh, and if you do colour selection using
then the actual colours available don’t matter either, AFAIK. |
Rick Murray (539) 13851 posts |
Yeah… uh… sorry… “insufficient tea” error. Now that my brain is working, I see that it’s setting MODE to itself, not trying to read MODE. <facepalm>
Works fine in what passes for MODE 13, MODE 15, and MODE 28 on the Pi2. It’s slightly squished in MODE15, but then the entire mode is. 13 and 28 work fine. Not seen VDU actually used like that before. That’s pretty nifty. A lot simpler than messing around with calling the ReadVduVars SWI. |
Steve Fryatt (216) 2105 posts |
I only found it in the Reference Manual yesterday; prior to that, I was using Apparently it’s been there since the Iyonix was launched… |
Rick Murray (539) 13851 posts |
As BASIC keywords are the native way of writing programs in BASIC, it is logically more correct to have VDU as a function able to read these variables.
Rubbish, it’s nothing to do with the MOS. It was added circa Iyonix (April 2001). |
Steve Drain (222) 1620 posts |
As well as |
Steve Pampling (1551) 8172 posts |
SYS “OS_ReadModeVariable” versus cryptic VDU use – Hmmm. One tells you what it’s for and the other does not. So, for all the humans it’s SYS “OS_ReadModeVariable” then. |
Steve Fryatt (216) 2105 posts |
Although the
so I know which I’ll be going with. |
Steve Pampling (1551) 8172 posts |
There are numerous Perl one-liners that do a lot while being massively cryptic too |
David Pitt (3386) 1248 posts |
VDU as a function. Nearly 20 rears old, BASIC 1.26, 16th Mar 2001. Documentation :- >HELP VDU VDU <number>[;|][,<number>[;|]]: list of values to be sent to vdu. , only - 8 bits. ; 16 bits. | 8 bytes of zeroes. As a function VDU x gives the value of the specified vdu variable. > HowTo :- REM >ReadModeVar FOR X%=0 TO 11 SYS "OS_ReadModeVariable",-1,X% TO ,,value1% value2% = VDU X% PRINT X%,value1%,value2% NEXT END A little archeology, see s/Factor VDUFN STR R14,[SP,#-4]! BL FACTOR BL INTEGZ LDR R14,[SP],#4 MOV R1,#-1 MOV R2,#0 STMFD SP!,{R0-R2} MOV R0,SP ADD R1,SP,#8 SWI READVDUVARIABLES LDR IACC,[R1] ADD SP,SP,#12 B SINSTK VDU as a function looks to be a veneer calling |
Steve Drain (222) 1620 posts |
As many BASIC keywords are veneers to SWI calls.
Overloading keywords is hardly unheard of, eg I think I have this right, the OS_ReadModeVariable code is duplicated for OS_ReadVduVariables, so you takes your pick. However, the former can be used for any mode, the latter only the current mode, and the latter can be used to read several values at once. With the speed of the machines we are using now, hiding SYS calls behind |
Steve Fryatt (216) 2105 posts |
If you’re not comfortable with the
line, then by all means break it up. An alternative, which is getting closer to the SWI-based version, is
followed by
That seems like a lot of padding to me, but if you prefer it, that’s fine. However, using OS_ReadModeVariable is comprehensively cryptic:
I remain unconvinced that this is clearer than using (All code off the top of my head and untested.) |
James Byrne (3371) 29 posts |
Yes, as I mentioned recently on another thread, if you have a pre-RISC OS 5 machine you just download System Resources from the Miscellaneous downloads page and follow the instructions in the ReadMe to merge it, then add a one-line Obey file to Choices:Boot.PreDesk containing the following line: The latest BASIC will work on anything back to RISC OS 3.1.
|
Steve Drain (222) 1620 posts |
With just BASIC I have used this to get dimensions of the current mode: DEFPROCthis_mode_size(RETURN width%,RETURN height%) !&8200=4:!&8204=5:!&8208=11:!&820C=12:!&8210=-1 SYS"OS_ReadVduVariables",&8200,&8200 width% =!&8208+1<<!&8200 height%=!&820C+1<<!&8204 ENDPROC Edit: Corrected to add list terminator. |
Steve Drain (222) 1620 posts |
Never say ‘always’, although in over 30 years it has not changed. ;-) For safety you would use a DIMmed buffer or some other construction. |