VDU ?

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
BeebMan2018
Posts: 158
Joined: Sun Nov 04, 2018 3:01 am
Contact:

VDU ?

Post by BeebMan2018 » Sat Jun 08, 2019 10:46 pm

Hey guys,

VDU23;8202;0;0;0;

So i understand that 23 is to re-define a character but the next number should be between 0 and 255 ? So how can it be 8202. I looked at the ASCII table in the Electron Manual but cant make much sense of that currently. :/

Can anyone shed some light on the syntax as shown above ? Mode 2 btw.

User avatar
IanS
Posts: 1017
Joined: Mon Aug 31, 2009 6:02 pm
Contact:

Re: VDU ?

Post by IanS » Sat Jun 08, 2019 11:03 pm

If the <numeric> is followed by a semicolon ; then the value is a little-endian word from 0 to 65535 inclusive. It is broken down into two ASCII values; first the word value MOD 256, then its value DIV 256. This word syntax is useful for graphics coordinates or for crunching BASIC programs.
From http://beebwiki.mdfs.net/VDU

BeebMan2018
Posts: 158
Joined: Sun Nov 04, 2018 3:01 am
Contact:

Re: VDU ?

Post by BeebMan2018 » Sat Jun 08, 2019 11:07 pm

So this states mod 82 div 02 ? If so where does that get me ? how do i identify the meaning of this ? What is Mod and Div ?

User avatar
Elminster
Posts: 3916
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: VDU ?

Post by Elminster » Sat Jun 08, 2019 11:42 pm

20,994 ..?

MOD and DIV are math functions. Slightly rusty but if the answer is 82 and 02 then the question would be 20994. But I could be wrong. I.e. 20994 / 256 is 82 remained 2, but maths is not much used in last 20 years.

Edit: should have read top post, answered imaginary question.
Last edited by Elminster on Sat Jun 08, 2019 11:59 pm, edited 2 times in total.

User avatar
IanS
Posts: 1017
Joined: Mon Aug 31, 2009 6:02 pm
Contact:

Re: VDU ?

Post by IanS » Sat Jun 08, 2019 11:45 pm

It doesn't say 82 mod 02. The 8202 is a two byte value, or a word. The MOD(ulo) and DIV are the remainder of a division and integer division. Which in this case are just a way of getting the two bytes one by one. 8202 (base 10) is &200a (base 16). MOD 256 will get you the low byte (&0a) , DIV 256 will give you the high byte (&20).

See MOD and DIV on this page - http://www.bbcbasic.co.uk/bbcwin/tutori ... ter05.html

BeebMan2018
Posts: 158
Joined: Sun Nov 04, 2018 3:01 am
Contact:

Re: VDU ?

Post by BeebMan2018 » Sat Jun 08, 2019 11:46 pm

IanS wrote:
Sat Jun 08, 2019 11:45 pm
It doesn't say 82 mod 02. The 8202 is a two byte value, or a word. The MOD(ulo) and DIV are the remainder of a division and integer division. Which in this case are just a way of getting the two bytes one by one. 8202 (base 10) is &200a (base 16). MOD 256 will get you the low byte (&0a) , DIV 256 will give you the high byte (&20).

See MOD and DIV on this page - http://www.bbcbasic.co.uk/bbcwin/tutori ... ter05.html
WHAT !!!!!!!!!!!!! :D

User avatar
Elminster
Posts: 3916
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: VDU ?

Post by Elminster » Sat Jun 08, 2019 11:52 pm

I should have read further up the question :)

User avatar
IanS
Posts: 1017
Joined: Mon Aug 31, 2009 6:02 pm
Contact:

Re: VDU ?

Post by IanS » Sat Jun 08, 2019 11:57 pm

BeebMan2018 wrote:
Sat Jun 08, 2019 11:46 pm
IanS wrote:
Sat Jun 08, 2019 11:45 pm
It doesn't say 82 mod 02. The 8202 is a two byte value, or a word. The MOD(ulo) and DIV are the remainder of a division and integer division. Which in this case are just a way of getting the two bytes one by one. 8202 (base 10) is &200a (base 16). MOD 256 will get you the low byte (&0a) , DIV 256 will give you the high byte (&20).

See MOD and DIV on this page - http://www.bbcbasic.co.uk/bbcwin/tutori ... ter05.html
WHAT !!!!!!!!!!!!! :D
Did you try it?
divmod.PNG
divmod.PNG (8.58 KiB) Viewed 964 times

User avatar
Elminster
Posts: 3916
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: VDU ?

Post by Elminster » Sun Jun 09, 2019 12:04 am

Or somewhere like

https://goodcalculators.com/modulo-calculator/

20994 mod 256 is 82 02 :)
8202 mod 256 is 32 10


User avatar
lurkio
Posts: 2180
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: VDU ?

Post by lurkio » Sun Jun 09, 2019 12:46 am

On pages 355 and 356 of the Beeb user guide, there are brief explanations of the semicolon usage in VDU statements and of what VDU23,0,R,X,0,0,0,0,0,0 does:

From there, and from the info everyone else has posted in this thread, you can work out that

Code: Select all

VDU23;8202;0;0;0;
is equivalent to

Code: Select all

VDU23,0,10,32,0,0,0,0,0,0
which means "put the value 32 in register 10 of the 6845 CRTC (Cathode Ray Tube Controller) chip".

Elminster's link then explains what the effect of setting register 10 to the value 32 is:
:idea:

User avatar
MartinB
Posts: 5241
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: VDU ?

Post by MartinB » Sun Jun 09, 2019 6:05 am

This is probably a good example of why it can often be really helpful to be familiar with the hex number notation for all things eight-bit computing related - IanS alluded to this further up the thread.

If you apply a little hex in this case, the significance of 8202 can actually be a lot less confusing in that 8202 decimal is hex &200A which is a 16-bit value having (and we can see this visually) a low byte of &0A (decimal 10) and a high byte of &20 (decimal 32). Then, with the additional knowledge that the VDU statement will stream such 16-bit numbers as low byte followed by high byte, we can easily see, without the need for any MOD'ing or DIV'ing, that the two VDU sequential values are 10 and 32.




.
Last edited by MartinB on Sun Jun 09, 2019 6:07 am, edited 2 times in total.

User avatar
jms2
Posts: 2276
Joined: Mon Jan 08, 2007 6:38 am
Location: Derby, UK
Contact:

Re: VDU ?

Post by jms2 » Sun Jun 09, 2019 6:47 am

I assume the reason why people started using the "8202" form of the command was because it is slightly easier to remember and to type compared to the intelligible version of the command. I'm as guilty as anyone else for using it, so I guess it has some value. All the same it seems like an odd thing to do - it would be possible to abbreviate other VDU sequences in the same way, but nobody seems to do that.

I think the BBC micro user guide is responsible for introducing this method. And of course, once you've read about it and memorised it as a young user, it gets stuck in your mind permanently.

The Electron user guide, as I recall, tried to dissuade users from this form of the command and introduced some other sequence for turning off the cursor involving zeroes and ones. But guess what, I can't remember it! The advice "don't use this older method of turning off the cursor" had the exact opposite effect on me.

User avatar
0xC0DE
Posts: 343
Joined: Tue Mar 19, 2019 7:52 pm
Location: The Netherlands
Contact:

Re: VDU ?

Post by 0xC0DE » Sun Jun 09, 2019 7:15 am

Code: Select all

VDU 23,1,0,0,0,0,0,0,0,0
And

Code: Select all

VDU 23,1,1,0,0,0,0,0,0,0
To turn the cursor on again
0xC0DE
:idea: Follow me on Twitter :idea: Visit my YouTube channel featuring my demos for Acorn Electron and BBC Micro

User avatar
danielj
Posts: 7505
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: VDU ?

Post by danielj » Sun Jun 09, 2019 7:48 am

0xC0DE wrote:
Sun Jun 09, 2019 7:15 am

Code: Select all

VDU 23,1,0,0,0,0,0,0,0,0
And

Code: Select all

VDU 23,1,1,0,0,0,0,0,0,0
To turn the cursor on again
Which is the proper way to do it from OS 1.0 onwards :) - the 8202 was a hangover from the pre-1.0 versions of MOS and people stuck with it as it was guaranteed to work for everyone...
edit: you can make it a bit shorter using semicolons to wordify your single bytes :)

Code: Select all

VDU23,1,0;0;0;0;
Last edited by danielj on Sun Jun 09, 2019 7:50 am, edited 1 time in total.

User avatar
Richard Russell
Posts: 917
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: VDU ?

Post by Richard Russell » Sun Jun 09, 2019 9:06 am

jms2 wrote:
Sun Jun 09, 2019 6:47 am
The Electron user guide, as I recall, tried to dissuade users from this form of the command and introduced some other sequence for turning off the cursor involving zeroes and ones. But guess what, I can't remember it! The advice "don't use this older method of turning off the cursor" had the exact opposite effect on me.
Later versions of BBC BASIC (I'm not exactly sure when this was introduced) support an even easier method using dedicated statements:

Code: Select all

      OFF : REM Disable text cursor/caret
      ON  : REM Enable text cursor/caret
This certainly works in all 'modern' versions including BBC BASIC for Windows, BBC BASIC for SDL 2.0 and Matrix Brandy BASIC.
Last edited by Richard Russell on Sun Jun 09, 2019 9:07 am, edited 1 time in total.

User avatar
Lardo Boffin
Posts: 1656
Joined: Thu Aug 06, 2015 6:47 am
Contact:

Re: VDU ?

Post by Lardo Boffin » Sun Jun 09, 2019 9:59 am

I assume the main driver (pun alert) behind this was to save a couple of bytes on longer VDU statements?
Atom, issue 5
BBC model B 32k issue 4, 16k sideways RAM, Watford 12 ROM board, Acorn 6502 coproc
BBC model B 32k issue 7, turboMMC, Opus Challenger 3 512k, Pi 3 coproc
USA Model B
BBC Master, Datacentre + HDD, pi co-proc, econet, NULA

User avatar
Richard Russell
Posts: 917
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: VDU ?

Post by Richard Russell » Mon Jun 10, 2019 8:15 am

Lardo Boffin wrote:
Sun Jun 09, 2019 9:59 am
I assume the main driver (pun alert) behind this was to save a couple of bytes on longer VDU statements?
Not really. VDU 23,0... writes values directly to the 6845 CRTC registers; disabling the text cursor/caret is just one of many effects it can have. Since it is specific to that particular chip it may not do what you expect, or indeed anything at all, on different hardware (unless emulated). VDU 23,1... is a 'higher level' command that is not hardware-specific, and should work on different platforms even if they don't use a 6845 or anything similar.

User avatar
jms2
Posts: 2276
Joined: Mon Jan 08, 2007 6:38 am
Location: Derby, UK
Contact:

Re: VDU ?

Post by jms2 » Mon Jun 10, 2019 11:20 am

I think what Lardo was getting at was that "8202" is one byte shorter than "10,32" and that this was possibly why that form, rather than the latter, was put into the User Guide.

The 10,32 form is easier to understand if you have access to the Advanced User Guide to understand what the individual parameters mean. But the authors of the User Guide weren't writing for that audience, so the slightly shorter and slightly easier to remember 8202 form probably seemed like a better choice for them.

TopBanana
Posts: 1064
Joined: Wed Jun 09, 2010 2:16 pm
Contact:

Re: VDU ?

Post by TopBanana » Wed Jun 12, 2019 9:45 pm

I’m presuming that the 0 (as in VDU 23,0) is implied because of the semi colon after 23?

User avatar
sweh
Posts: 2089
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: VDU ?

Post by sweh » Wed Jun 12, 2019 10:11 pm

TopBanana wrote:
Wed Jun 12, 2019 9:45 pm
I’m presuming that the 0 (as in VDU 23,0) is implied because of the semi colon after 23?
Yup!
Rgds
Stephen

User avatar
Rich Talbot-Watkins
Posts: 1547
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: VDU ?

Post by Rich Talbot-Watkins » Thu Jun 13, 2019 12:13 pm

(The other posts which were going off-topic, speculating about BBC BASIC, have been split off into this thread.)

Post Reply