Osbyte &81 - read machine type

discussion of beeb/electron applications, languages, utils and educational s/w
Post Reply
User avatar
jms2
Posts: 1978
Joined: Mon Jan 08, 2007 6:38 am
Location: Derby, UK
Contact:

Osbyte &81 - read machine type

Post by jms2 » Wed Feb 28, 2018 8:50 pm

I've been looking at the "read machine type" function of Osbyte &81 (ie Osbyte &81,0,&FF) and I've noticed that BeebWiki is by far the best source of information. Specifically:

- The BBC Advanced User Guide doesn't mention this function at all (as far as I can see). Surprising to find it's missed this.
- The New Advanced User Guide does mention it, but contains a lot of errors. It correctly states that the entry conditions are X=0, Y=&FF but the descriptions next to these lines look to have been cut 'n' pasted from OSBYTE &00 just up the page, as they don't make sense. Also it shows the result being returned in A, whereas in reality it is returned in X.
- The Electron AUG is not too bad, but it doesn't contain a very comprehensive list of machine types.

However, none of the references say anything about what happens to the Y register. I guess this just means that it is undefined, but what prompted me to look at this issue is the fact that the loader for (one version of) Tube Elite accepts two possible results, either "X=0, Y=0" or "X=&FF, Y=&FF". The latter represents a BBC B with OS 1.20, and I presume the former is a BBC B with OS 0.10. I thought that setting Y to zero might be an OS 0.10 anomaly, but then experimenting with different emulation setups I found that the B+, Master and Electron all set Y to zero - making OS 1.20 apparently the odd one out.

I don't suppose this is very significant really, but I thought it might be worth pointing out in case it is useful to someone.

User avatar
richardtoohey
Posts: 3563
Joined: Thu Dec 29, 2011 5:13 am
Location: Tauranga, New Zealand
Contact:

Re: Osbyte &81 - read machine type

Post by richardtoohey » Thu Mar 01, 2018 5:23 am

jms2 wrote:The BBC Advanced User Guide doesn't mention this function at all (as far as I can see)
Wild guess: maybe they didn't think it was very important because only BBC Bs when it was printed? No Masters, Electrons, etc. so didn't seem worth mentioning? :?:

Page 5 says "All the information about the operating system is exclusively based on OS 1.20" - not exactly the same thing, but the sort of thing I mean regarding their focus.

User avatar
tricky
Posts: 2541
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Osbyte &81 - read machine type

Post by tricky » Thu Mar 01, 2018 7:50 am

I remember going through a similar exercise when I was going to swap my initialisation code, but as I only want to find the ADC control register I just stayed with osbyte 0.

User avatar
daveejhitchins
Posts: 4187
Joined: Wed Jun 13, 2012 5:23 pm
Location: Newton Aycliffe, County Durham
Contact:

Re: Osbyte &81 - read machine type

Post by daveejhitchins » Thu Mar 01, 2018 8:03 am

During the early development of the original MGC, when I hoped to support the Master, JGH provided me with the following, to identify which machine I was in:

Code: Select all

A%=0:X%=1:machine=((USR&FFF4)AND&FF00)DIV256

The results include:
0 Electron
1 BBC A/B
2 BBC B+
3 Master
4 Master ET
5 Master Compact
6 RISC OS
7 Springboard
8 Unix
No mention of Y !!

Dave H :D
Parts: UM6502CE, GAL22V10D, GAL16V8D, AS6C62256A, TC514400AZ, WD1772, R6522, TMS27C512, AT28C256
Products: ARA II, ABR, ATI, AP6, MGC, AP5 . . .
For a price list, contact me at: Retro Hardware AT dave ej hitchins DOT plus DOT com

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

Re: Osbyte &81 - read machine type

Post by jms2 » Thu Mar 01, 2018 8:46 am

That's Osbyte 0 Dave, which is similar but subtly different. I get the impression that this is the preferred call to use, so I might just do that in my case.

I wasn't so much concerned with how to detect machine type, as I'd got that figured out, but more that Osbyte &81 seemed to have an undocumented feature, ie setting the Y register to zero except on OS1.20. However if nobody uses it any more it probably doesn't matter.

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

Re: Osbyte &81 - read machine type

Post by Rich Talbot-Watkins » Thu Mar 01, 2018 11:43 am

It'd never occurred to me that the INKEY-256 thing was originally undocumented. It is very obscure - piggybacking off a totally unrelated API for no apparent reason. Not even sure why they couldn't just use OSBYTE 0 to return this information - having two separate calls with slightly different return codes just seems like bad planning.

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

Re: Osbyte &81 - read machine type

Post by Rich Talbot-Watkins » Thu Mar 01, 2018 12:14 pm

Having a quick look at the OS 1.20 disassembly, it doesn't look as if any special handling is given to OSBYTE &81,&00,&FF - it seems to actually drop through to the keyboard scan code and presumably always guarantees a consistent return value. In later OSes I guess they had to hardcode specific behaviour in order to return different values. Still would've been less obscure just to support more varied return codes for OSBYTE 0, but there you go.

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 12:43 pm

Yeah this rings a distant bell. There is very little information out there about this and I am yet to find a reason wh(Y) doesn't need to be set whereas in other calls it does. Whiffs of an anomaly to me, too.
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

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

Re: Osbyte &81 - read machine type

Post by jms2 » Thu Mar 01, 2018 1:33 pm

petercumberland wrote:Yeah this rings a distant bell. There is very little information out there about this and I am yet to find a reason wh(Y) doesn't need to be set whereas in other calls it does. Whiffs of an anomaly to me, too.
I think you might have misunderstood my original post. As far as I know, it is necessary to set Y=&FF when making the call. It's just that the contents of Y are unaffected on OS1.20 whereas every other 8 bit OS puts Y=&00 as the output.

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 1:39 pm

Hmm. What makes you think that Y does have to be set - I am interested..
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 1:40 pm

petercumberland wrote:Hmm. What makes you think that Y does have to be set - I am interested..
Nevermind I see where you are coming from now.
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 1:47 pm

jms2 wrote:
petercumberland wrote:Yeah this rings a distant bell. There is very little information out there about this and I am yet to find a reason wh(Y) doesn't need to be set whereas in other calls it does. Whiffs of an anomaly to me, too.
I think you might have misunderstood my original post. As far as I know, it is necessary to set Y=&FF when making the call. It's just that the contents of Y are unaffected on OS1.20 whereas every other 8 bit OS puts Y=&00 as the output.
What I mean't was OSBYTE calls with A in the range &80 to &FF in general need to set both X and Y whereas other OSBYTE calls only take one argument - in X

Clear as mud? #-o
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 1:55 pm

jms2 wrote:
petercumberland wrote:Yeah this rings a distant bell. There is very little information out there about this and I am yet to find a reason wh(Y) doesn't need to be set whereas in other calls it does. Whiffs of an anomaly to me, too.
I think you might have misunderstood my original post. As far as I know, it is necessary to set Y=&FF when making the call. It's just that the contents of Y are unaffected on OS1.20 whereas every other 8 bit OS puts Y=&00 as the output.
I think Richard gives a clearer answer on this:

http://www.bbcbasic.co.uk/bbcbasic/manual/opsys0.html

And specifically where he mentions:
OSBYTE and OSWORD are accessed in the same way as on a BBC Micro by USR to addresses &FFF4 (OSBYTE) and CALL to address &FFF1 (OSWORD).

Because a call to either of these addresses only provides a single function, it is not strictly necessary to pass the OSBYTE or OSWORD function number in A%, but it is best to do so to ensure compatibility with any future enhancements to BBCBASIC(86).
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 2:07 pm

jms2 wrote:
petercumberland wrote:Yeah this rings a distant bell. There is very little information out there about this and I am yet to find a reason wh(Y) doesn't need to be set whereas in other calls it does. Whiffs of an anomaly to me, too.
I think you might have misunderstood my original post. As far as I know, it is necessary to set Y=&FF when making the call. It's just that the contents of Y are unaffected on OS1.20 whereas every other 8 bit OS puts Y=&00 as the output.
I wonder if it is based on the same restriction that the co-processor has?

In other words:

&00-&7F - Only X (not Y) is sent and returned.
&82 - Always returns 00 in both X and Y (ie the parasite high order address).
&83 - Always returns 00 in X and 08 in Y (ie OSHWM in parasite).
&84 - Always returns &8000 or &B800 (ie the position of HIMEM in the parasite)

I agree I doubt it matters at all in the great scheme of things but you raise an interesting point.
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

User avatar
jgharston
Posts: 3090
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Osbyte &81 - read machine type

Post by jgharston » Thu Mar 01, 2018 2:32 pm

You should ignore Y because different hosts set Y differently, eg BBC returns &FFFF, most other hosts return &00xx.

You should use OSBYTE 0 to determine what the host is, and only use OSBYTE &81/INKEY-256 after calling OSBYTE 0 if OSBYTE 0 provides insufficient granularity.

Also, if at all possible, you shouldn't even call OSBYTE 0 anyway, just damn well just call the damn call you want to call, and examine the resturned results.

WRONG: IF I_am_a_BBC THEN There is no RTC
CORRECT: IF OSWORD 14 says there is no RTC THEN There is no RTC

WRONG: IF i_am_not_a_Master THEN There are no configuration settings
CORRECT: IF OSBYTE 161 says there are no configuration settings THEN There are no configuration settings

Edit: plus OSBYTE calls <&80 are defined to only use the X register, only OSBYTE calls >&7F are defined to allow passing data in the Y register and optionally returning a status in the Carry flag.
Last edited by jgharston on Thu Mar 01, 2018 2:34 pm, edited 1 time in total.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

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

Re: Osbyte &81 - read machine type

Post by jms2 » Thu Mar 01, 2018 2:33 pm

petercumberland wrote:Hmm. What makes you think that Y does have to be set - I am interested..
Partly because that's what both BeebWiki and the Advanced User Guides define the command parameters as. But also because many Osbyte calls conform to a standard format whereby they set the new value of the memory location in question to =(<old value> AND Y) EOR X
i.e. any required new value is in X, and Y=0 for write, Y=&FF for read.

So setting Y=&FF would be normal for reading. On exit, Y often seems to be undefined for many calls.

I think Rich's explanation sounds very likely - this was a totally undocumented and unintentional property of the OS which was exploited by early Acornsoft game authors to figure out which machine their code was running on. Later on it was formalised, and documented (badly) in the New Advanced User Guide, hence the partial duplication of Osbyte 0.

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 2:39 pm

..totally undocumented and unintentional property of the OS which was exploited by early Acornsoft game authors to figure out which machine their code was running on
I think you hit the nail on the head with that. I totally agree.
Last edited by petercumberland on Thu Mar 01, 2018 2:40 pm, edited 1 time in total.
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

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

Re: Osbyte &81 - read machine type

Post by jms2 » Thu Mar 01, 2018 2:39 pm

jgharston wrote:You should ignore Y because different hosts set Y differently, eg BBC returns &FFFF, most other hosts return &00xx.

You should use OSBYTE 0 to determine what the host is, and only use OSBYTE &81/INKEY-256 after calling OSBYTE 0 if OSBYTE 0 provides insufficient granularity.
Fair enough, thanks Jonathan. I was expecting that this was something you'd already know about.

In this case, I'm trying to understand some existing code rather than write new, and I was intrigued by the way the code (in Elite) specifically goes checking for Y=&FF. Looks like it's hackery rather than adherence to some over-arching rule that we don't know about!

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 2:52 pm

jgharston wrote:You should ignore Y because different hosts set Y differently, eg BBC returns &FFFF, most other hosts return &00xx.
My "What makes you think that Y does have to be set" could also be interpreted as your "You can ignore Y" which is where I was coming from given that for OSBYTE y only returns for a>=&80. What I think we were both interested in was the fact this was more or less undocumented.
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 4:37 pm

Intrigued, I dug out some projects I did in the 1990's. I stumbled across some pseudocode logic that I had as comments in some code I was doing to get os ver. It went like this:

osbyte call &00(0)
entry:
X=0 {brk} return in X
X<>0 {rts} return X

after 1992, however my code had changed a bit:

osbyte call &81(129)
entry:
X=0 : Y=&FF
return X
So the Y came later and I suspect it was for detecting later oses.
EDIT: Just finished reading the original BBC Micro User Guide and discovered the above comment is incorrect

But you can see that the earlier osbyte &00(0) does not concern itself with Y in any meaningful way. Y was only signicant when you call osbyte &81(129).
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 5:12 pm

Rich Talbot-Watkins wrote:Having a quick look at the OS 1.20 disassembly, it doesn't look as if any special handling is given to OSBYTE &81,&00,&FF - it seems to actually drop through to the keyboard scan code and presumably always guarantees a consistent return value. In later OSes I guess they had to hardcode specific behaviour in order to return different values. Still would've been less obscure just to support more varied return codes for OSBYTE 0, but there you go.
Ah-yup. I missed this comment (sorry Rich) but I wish I hadn't - as I ended up going round circles. Thanks for giving me my sanity back.. :?
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Thu Mar 01, 2018 5:31 pm

Rich Talbot-Watkins wrote:Having a quick look at the OS 1.20 disassembly..
Rich - out of interest - when did Acorn relinquish rights to the magnificent OS 1.20 ? I have been state-side for the past 10 years and when I recall trying to get a legal copy (circa 1998/99) I was told no. Clearly things have moved on from that position and I was just wondering roughly when that was?

Cheers

Pete
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

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

Re: Osbyte &81 - read machine type

Post by Rich Talbot-Watkins » Thu Mar 01, 2018 5:40 pm

No one really knows. No one seems to know for sure who the current copyright holder is after Acorn rights were split between Pace, Broadcom, Castle, RISCOS Ltd and whoever else.

I remember back around '96-'97 someone (from Acorn I guess) popping up on the old BBC Micro Emul8 mailing list granting unofficial permission to distribute OS 1.20 with the first emulators which were being released at the time. I don't think any license was ever made explicit, and I think the whole thing is in a sort of legal limbo to this day, but no one is sure who owns the rights so many blind eyes are turned.

I found a relevant thread here:
http://mdfs.net/Archive/BBCMicro/1994/08/30/113855.htm

...but no conclusion.

Edit: looks like I remember wrong. Just browsing through the mailing list archives, I don't see any indication that any kind of agreement was ever made. And then Acorn imploded. Oh well.

crj
Posts: 834
Joined: Thu May 02, 2013 4:58 pm
Contact:

Re: Osbyte &81 - read machine type

Post by crj » Thu Mar 01, 2018 7:06 pm

From the context, I'd always assumed you used OSBYTE 0 if you wanted to know what OS features to expect and OSBYTE &81 if you wanted to know what keyboard layout to expect.

User avatar
petercumberland
Posts: 26
Joined: Wed Feb 21, 2018 5:06 pm
Location: UK
Contact:

Re: Osbyte &81 - read machine type

Post by petercumberland » Fri Mar 02, 2018 9:23 am

Rich - many thanks for that - very interesting reading.

Cheers

Pete
______________________________________________________________
I am just trying to get to the end of the day without somebody saying at the end of the day

Post Reply