USR0
USR0
I'm a bit puzzled by all this USR0 business. My understanding is that USR0 is a 128K system in 48K mode, but with the paging enabled. Einar's always banging on about this utility that forces it before loading another program.
Why is USR0 a thing (then and now), is it all 128K Spectrums? how do we put a Spectrum into USR0 mode (without having to load the above utility), and why do the loaders say RANDOMIZE USR .? What memory location does the "." refer to?
Why is USR0 a thing (then and now), is it all 128K Spectrums? how do we put a Spectrum into USR0 mode (without having to load the above utility), and why do the loaders say RANDOMIZE USR .? What memory location does the "." refer to?
- Einar Saukas
- Bugaboo
- Posts: 3169
- Joined: Wed Nov 15, 2017 2:48 pm
Re: USR0
Yes, the USR0 mode means switching to 48K mode (thus using the 48K ROM) but keeping paging enabled.
IIRC whenever you run an assembly program from 128K BASIC, it automatically switches to the 48K ROM in an attempt to improve compatibility with older 48K programs. Therefore if you run RANDOMIZE USR 0, it will execute the 48K ROM initialization thus make it behave exactly like a 48K machine afterwards. The only difference is that paging will be still available.
IIRC whenever you run an assembly program from 128K BASIC, it automatically switches to the 48K ROM in an attempt to improve compatibility with older 48K programs. Therefore if you run RANDOMIZE USR 0, it will execute the 48K ROM initialization thus make it behave exactly like a 48K machine afterwards. The only difference is that paging will be still available.
Last edited by Einar Saukas on Sun Apr 11, 2021 8:03 pm, edited 1 time in total.
Re: USR0
1) Some games don't work properly if the 48 ROM isn't paged in (or too much stack space has been used etc). This is why USR0 mode is sometimes required. A well written 128K program shouldn't really ever need it.
2) You can get into USR0 mode by type PRINT USR 0 in 128 basic. On a +2A/+3 you can also just type SPECTRUM (this is a subtle change from the original 128 models).
3) Why does it work? Because USR xxxx calls whatever machine code happens to be at address xxxx, when that value is 0 the processor jumps to the start of the ROM, just as it would at reboot. Because the 48K ROM is paged in when decoding the USR instruction, this causes a jump to the start of the 48K ROM and is effectively restarting the machine in 48 mode. However the 48K ROM doesn't know anything about the paging hardware and therefore doesn't attempt to lock it first so all the 128K memory paging hardware is still available.
2) You can get into USR0 mode by type PRINT USR 0 in 128 basic. On a +2A/+3 you can also just type SPECTRUM (this is a subtle change from the original 128 models).
3) Why does it work? Because USR xxxx calls whatever machine code happens to be at address xxxx, when that value is 0 the processor jumps to the start of the ROM, just as it would at reboot. Because the 48K ROM is paged in when decoding the USR instruction, this causes a jump to the start of the 48K ROM and is effectively restarting the machine in 48 mode. However the 48K ROM doesn't know anything about the paging hardware and therefore doesn't attempt to lock it first so all the 128K memory paging hardware is still available.
Re: USR0
Numerous ways to do it but the code basically sets some of the system variables, switches to 48k ROM with bank switching on and returns to basic without a reset which is useful in loaders.R-Tape wrote: ↑Sun Apr 11, 2021 7:47 pm I'm a bit puzzled by all this USR0 business. My understanding is that USR0 is a 128K system in 48K mode, but with the paging enabled. Einar's always banging on about this utility that forces it before loading another program.
Why is USR0 a thing (then and now), is it all 128K Spectrums? how do we put a Spectrum into USR0 mode (without having to load the above utility), and why do the loaders say RANDOMIZE USR .? What memory location does the "." refer to?
Regarding the memory location, these loaders are probably using a common trick where the number in the listing bears no relation to the number actually used in the USR statement. This is because basic stores numbers as the actual text version and then a 5 byte code version which is used by the interpreter and allows for floating point numbers etc... the 5byte version will have the actual address and is hidden from view.
TomD
Retro enthusiast and author of Flynn's Adventure in Bombland, The Order of Mazes & Maze Death Rally-X. Check them out at http://tomdalby.com
Re: USR0
In the utility you mention it says RUN USR 8, but it isn't actually calling memory pos 8, looking at the code it is actually calling address 0x5cdd which just so happens to be the machine code to switch to USR 0. It will then run this, return to basic and execute the LOAD "".
TomD
TomD
Retro enthusiast and author of Flynn's Adventure in Bombland, The Order of Mazes & Maze Death Rally-X. Check them out at http://tomdalby.com
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: USR0
I simply add RES 4,(IY+1) to a MC loader (incorporated into BASIC). That’s the bit of the FLAGS system variable that determines the mode: 48K or 128K. It is set by the 128K ROM, but is “unused” (i.e. reset) by the 48K ROM. If you manually reset it, the machine will operate as though it’s in 48K mode, but paging will remain enabled.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
- 1024MAK
- Bugaboo
- Posts: 3136
- Joined: Wed Nov 15, 2017 2:52 pm
- Location: Sunny Somerset in the U.K. in Europe
Re: USR0
See also the bit that I wrote here
And as others have indicated, the address 0 in the 16k/48k ROM is the first memory location that a Z80 processor will execute after a reset (power on or via the push button on the plus model) and hence the ‘original’ 48k ROM will take control of the system, set the border to white, clear all the RAM it knows about (48k worth) and drop you into 16k/48k BASIC.
Mark
And as others have indicated, the address 0 in the 16k/48k ROM is the first memory location that a Z80 processor will execute after a reset (power on or via the push button on the plus model) and hence the ‘original’ 48k ROM will take control of the system, set the border to white, clear all the RAM it knows about (48k worth) and drop you into 16k/48k BASIC.
Mark
Standby alert
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb
Looking forward to summer later in the year.
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb
Looking forward to summer later in the year.
Re: USR0
Ah, I thought the SPECTRUM command was standard in all the 128k models.
Re: USR0
I've now down this, thanks, but oddly, whatever I try, I'm getting only black screens with this demo, whether I try Zesaurx or Es.pectrum. Anyone know the answer, please?
https://jbizzel.itch.io/giga-screenzx