SHEILA &FE40 - What Does This Do?

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
melchett
Posts: 408
Joined: Tue Jan 28, 2003 9:52 am
Contact:

SHEILA &FE40 - What Does This Do?

Post by melchett »

I have been looking at a game loader from the mid-80s and I cannot figure out what part of it does with SHEILA 6522 System VIA Register B ($FE40). I searched the forum but couldn't find anything similar, happy to be pointed at an existing thread.

Code: Select all

        ...
	; What does this do? Value in binary is 0111 1110
        LDA     #$7E
        STA     $FE40
        
        ; Set the hardware scroll address to $5800
        LDA     #$0C
        STA     $FE40
        LDA     #$05
        STA     $FE40
        ...
I have been using in New Advanced User Guide / Advanced User Guide as the starting point however I'm stumped with what $7E / 0111 1110 would do - and looking at Toby Lobster's far more useful and excellent MOS decompilation reference notes on this, it looks as though either the bottom 4 bits or the top 4 bits should set. Can you do a read and write at the same time? Or does this do something else?

I know this 6522 VIA controls "the keyboard, sound, speech, joystick fire buttons etc" but I appreciate any insights in what this achieves.

Many thanks, Andy
User avatar
lurkio
Posts: 3666
Joined: Wed Apr 10, 2013 12:30 am
Location: Doomawangara
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by lurkio »

I don’t really understand it, but does this document help at all?:

http://mdfs.net/Docs/Comp/BBC/Hardware/SHEILAddrs

:?:
melchett
Posts: 408
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by melchett »

lurkio wrote:
Mon Jun 14, 2021 4:30 pm
I don’t really understand it, but does this document help at all?:

http://mdfs.net/Docs/Comp/BBC/Hardware/SHEILAddrs
Thank you Lurkio - I had seen that, it just shows the register location though. Not "what the consequence is of writing $7E" to that location. The other values I can work out from Toby Lobster's write up, but this value doesn't make sense from everything I can read about. It may be a bug in the original program that didn't matter, or it may be something special that I cannot fathom - starts wondering into words like "addressable latch" but that seems more pertinent for the User VIA than the System VIA which I'd expect to have more well defined behaviour given there's only so many predefined devices you can talk to through it.

Andy.
philb
Posts: 725
Joined: Sat Aug 05, 2017 7:05 pm
Location: Cambridge, GB
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by philb »

See section 23 of the Advanced User Guide.

http://stardot.org.uk/mirrors/www.bbcdo ... 0Guide.pdf
User avatar
daveejhitchins
Posts: 6599
Joined: Wed Jun 13, 2012 6:23 pm
Location: Newton Aycliffe, County Durham
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by daveejhitchins »

Here's the 6522 data sheet:
Rockwell R6522.pdf
(8.06 MiB) Downloaded 12 times

Dave H.
melchett
Posts: 408
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by melchett »

philb wrote:
Mon Jun 14, 2021 4:56 pm
See section 23 of the Advanced User Guide.

http://stardot.org.uk/mirrors/www.bbcdo ... 0Guide.pdf
Thank you Phil. As above, I have the AUG / NAUG but it talks about using the Data Direction Register B (in this instance) to control which way data should flow but that's controlled at &FE43. And looking at Toby's disassembly of the MOS, it seems it should for &FE40 only have the top or bottom 4 bits set to set or read the certain values for the hardware. Chapter 23 doesn't tell what this &FE40 does with a value of &7E.
melchett
Posts: 408
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by melchett »

daveejhitchins wrote:
Mon Jun 14, 2021 5:02 pm
Here's the 6522 data sheet:

Rockwell R6522.pdf
Thank you Dave - I think this is specific to how the System VIA is wired though as it talks to e.g. sounds, speech joystick buttons etc and the value in that code doesn't make sense with anything I can see documented around specifically the &FE40 which I believe hits the MOS first before calling any hardware mapped I/O addresses e.g. &FE41/FE43 etc.
philb
Posts: 725
Joined: Sat Aug 05, 2017 7:05 pm
Location: Cambridge, GB
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by philb »

melchett wrote:
Mon Jun 14, 2021 5:36 pm
Thank you Phil. As above, I have the AUG / NAUG but it talks about using the Data Direction Register B (in this instance) to control which way data should flow but that's controlled at &FE43. And looking at Toby's disassembly of the MOS, it seems it should for &FE40 only have the top or bottom 4 bits set to set or read the certain values for the hardware. Chapter 23 doesn't tell what this &FE40 does with a value of &7E.
&FE40 is system VIA output register B. AUG chapter 23 explains how port B is connected up to the addressable latch in particular.
philb
Posts: 725
Joined: Sat Aug 05, 2017 7:05 pm
Location: Cambridge, GB
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by philb »

Assuming that DDRB has been left at the default value of &0F, the top four bits are inputs and it doesn't matter what you write to them. So writing &7E is equivalent to writing the addressable latch with D=1 and A=6, which turns off caps lock.
User avatar
sweh
Posts: 2469
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by sweh »

philb wrote:
Mon Jun 14, 2021 5:49 pm
So writing &7E is equivalent to writing the addressable latch with D=1 and A=6, which turns off caps lock.
Of course on the next interrupt cycle the OS turns it back on again, so you need to do this within a section of code with interrupts disabled.
Rgds
Stephen
melchett
Posts: 408
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by melchett »

That's useful information Phil and Stephen!
Assuming that DDRB has been left at the default value of &0F,
It has, nothing in the code to that point has changed DDRB.
the top four bits are inputs and it doesn't matter what you write to them
I will move on and consider it an oversight by the original programmer or an artefact leftover from something else he tried to do. Thank you for the confirmation.
so you need to do this within a section of code with interrupts disabled.
The part I quoted in the original post is sandwiched between a SEI / CLI to disable the maskable interrupts. So I think it's doing the right thing.

Appreciate all the fast responses from everyone on this thread. Every day is an education :)

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

Re: SHEILA &FE40 - What Does This Do?

Post by sweh »

It's an easy test as well :-)

Code: Select all

P%=&900
[SEI:LDA#&7E:STA&FE40:JMP P%
CALL &900
and the capslock LED should go out.
Rgds
Stephen
melchett
Posts: 408
Joined: Tue Jan 28, 2003 9:52 am
Contact:

Re: SHEILA &FE40 - What Does This Do?

Post by melchett »

sweh wrote:
Tue Jun 15, 2021 12:55 pm
It's an easy test as well :-)

Code: Select all

P%=&900
[SEI:LDA#&7E:STA&FE40:JMP P%
CALL &900
and the capslock LED should go out.
I wasn't sure if it was doing anything else special under the covers too - thankfully not :) Thank you for the code snippet.
Post Reply

Return to “programming”