Sideways RAM bank selection code

bbc/electron apps, languages, utils, educational progs, demos + more
Post Reply
User avatar
simonm
Posts: 316
Joined: Mon May 09, 2016 3:40 pm
Contact:

Sideways RAM bank selection code

Post by simonm » Tue Nov 15, 2016 7:41 pm

Question for you Beeb Gurus.
Quite possibly a bug in my code, but are there any gotchas when selecting a SWR bank?
My code correctly detects the presence of 4 SWR banks (slots 4,5,6,7) on a Master 128 by cycling through 16 values, selecting bank by poking the bank number to &FE30, then checking if address &8000 is writable or not.

However the same bank selection code, when used later on in my program, doesn't seem to correctly select a SWR bank.

Code: Select all

; A contains ROM bank to be selected
.swr_select_bank
{
    sta &fe30
    sta &f4
    rts
}
(I'm stashing the bank in &F4 just in case the OS gets involved somewhere).


I've tried wrapping the call to swr_select_bank with SEI/CLI for belts and braces but that made no difference.
I'm running pure machine code rather than BASIC.
I also havent disabled any system interrupts as I didn't think that would be needed.

I'm trying to load data into the SWR banks using OSFILE, so not sure if thats a problem too - it occurred to me that perhaps the DFS is getting paged in and messing things up.

Is there some other voodoo to this? I've forgotten a lot since the old days!
TIA!

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

Re: Sideways RAM bank selection code

Post by sweh » Tue Nov 15, 2016 8:04 pm

FWIW, write to F4 before FE30 just to catch the race condition.

On a Master that's all that is necessary to select a SWR bank.

But you can't necessarily use OSFILE because that will cause the DFS ROM to page in. You either need to read a byte at a time and switch the RAM bank in for each byte read, or else load the data into a low memory location (eg &2000) and then block move the data after it has been loaded. That's what the "Q" option to *SRLOAD does.
Rgds
Stephen

User avatar
geraldholdsworth
Posts: 761
Joined: Tue Nov 04, 2014 9:42 pm
Location: Inverness, Scotland
Contact:

Re: Sideways RAM bank selection code

Post by geraldholdsworth » Tue Nov 15, 2016 8:11 pm

This seems to work - bit long winded, I know, but compiles for most machines, and includes menus, etc.

http://www.geraldholdsworth.co.uk/ExROM.php
Gerald Holdsworth
Repton Resource Page
www.reptonresourcepage.co.uk

User avatar
simonm
Posts: 316
Joined: Mon May 09, 2016 3:40 pm
Contact:

Re: Sideways RAM bank selection code

Post by simonm » Tue Nov 15, 2016 10:07 pm

Thanks all, I rewrote my loading code to use mem copy and all was well. Seems that OSFILE was indeed the problem, which makes sense, but I'd have expected a much more corrupted data upload to SWR if that was getting paged in during the write. It 'appears' OSFILE would successfully load data to the SWR memory, but for some reason it always used the same SWR bank no matter what was selected prior to calling OSFILE.

I've not got much in the way of spare RAM to load into system RAM all in one go, so I opted to use OSGBPB to load/copy 1 page at a time for a 16Kb chunk of data instead and boy that's slow!
FWIW, write to F4 before FE30 just to catch the race condition.
Good catch! Done.

Code: Select all

 3610DEFFNpagerom(i,c)
 3620IFc>0[OPTi:STA&F4:STA&FE30:]ELSE[OPTi:PHA:LDA#&C:STA&F4:STA&FE05:PLA:STA&F4:STA&FE05:]
 3630=i
Thanks for the reference code Gerald, whats the FE05 bit do?

User avatar
geraldholdsworth
Posts: 761
Joined: Tue Nov 04, 2014 9:42 pm
Location: Inverness, Scotland
Contact:

Re: Sideways RAM bank selection code

Post by geraldholdsworth » Tue Nov 15, 2016 10:20 pm

simonm wrote:Thanks for the reference code Gerald, whats the FE05 bit do?
That's the sideways bank selection address for the Acorn Electron. The code is multi-platform.
Gerald Holdsworth
Repton Resource Page
www.reptonresourcepage.co.uk

User avatar
jgharston
Posts: 4240
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Sideways RAM bank selection code

Post by jgharston » Tue Nov 15, 2016 10:24 pm

simonm wrote:My code correctly detects the presence of 4 SWR banks (slots 4,5,6,7) on a Master 128 by cycling through 16 values, selecting bank by poking the bank number to &FE30, then checking if address &8000 is writable or not.
If you're going to do that you must use the binary version number at &8008, not any other location. Imagine what happens if you write to &8000 and before you can manage to restore it a reset happens. Bnag!
simonm wrote:.swr_select_bank
sta &fe30
sta &f4
rts
As others have pointed out, you've got those two the wrong way around. Imagine what happens if an interupt happens between STA &FE30 and STA &F4. The interupt routine pages in whatever it needs, then restores the ROM from what &F4 was.
simonm wrote:I'm trying to load data into the SWR banks using OSFILE, so not sure if thats a problem too - it occurred to me that perhaps the DFS is getting paged in and messing things up.
Without specialist hardware or a specialist filing system that will not work as the filing system is sat on top of the same addresses as the sideways RAM. Without specialist hardware you can only write to a bank of sideways RAM when it is paged in in the same way that you can only read from it when it is paged in. If it is paged in then by definition the filing system is paged out. You load data into sideways RAM by loading is into a buffer then copying it from that buffer to sideways RAM, and vis versa for saving.

Code: Select all

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

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

Re: Sideways RAM bank selection code

Post by sweh » Wed Nov 16, 2016 12:34 am

Although not strictly relevant, here, Solidisk DDFS had a fun feature. The FDC handling code would be copied down to page D and the data load done from there. This meant the ROM could be paged out. They also looked at the 3rd byte of the load address and paged that bank in. So you could do

Code: Select all

*LOAD MYROM 48000
And it would be loaded into bank 4.

Totally non-portable, but useful!
Rgds
Stephen

User avatar
simonm
Posts: 316
Joined: Mon May 09, 2016 3:40 pm
Contact:

Re: Sideways RAM bank selection code

Post by simonm » Wed Nov 16, 2016 2:15 pm

geraldholdsworth wrote:That's the sideways bank selection address for the Acorn Electron. The code is multi-platform.
Ah gotcha.
If you're going to do that you must use the binary version number at &8008, not any other location. Imagine what happens if you write to &8000 and before you can manage to restore it a reset happens. Bnag!
Good tip!

Post Reply

Return to “8-bit acorn software: other”