USR0

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
R-Tape
Site Admin
Posts: 6446
Joined: Thu Nov 09, 2017 11:46 am

USR0

Post by R-Tape »

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?
User avatar
Einar Saukas
Bugaboo
Posts: 3167
Joined: Wed Nov 15, 2017 2:48 pm

Re: USR0

Post by Einar Saukas »

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.
Last edited by Einar Saukas on Sun Apr 11, 2021 8:03 pm, edited 1 time in total.
AndyC
Dynamite Dan
Posts: 1420
Joined: Mon Nov 13, 2017 5:12 am

Re: USR0

Post by AndyC »

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.
User avatar
TomD
Manic Miner
Posts: 382
Joined: Tue Nov 13, 2018 9:47 am
Location: Leeds UK
Contact:

Re: USR0

Post by TomD »

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?
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.

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
User avatar
TomD
Manic Miner
Posts: 382
Joined: Tue Nov 13, 2018 9:47 am
Location: Leeds UK
Contact:

Re: USR0

Post by TomD »

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
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
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: USR0

Post by Ast A. Moore »

R-Tape wrote: Sun Apr 11, 2021 7:47 pm how do we put a Spectrum into USR0 mode (without having to load the above utility)?
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.
User avatar
1024MAK
Bugaboo
Posts: 3130
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: USR0

Post by 1024MAK »

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
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
DVDfever
Microbot
Posts: 131
Joined: Fri Mar 24, 2023 10:14 am

Re: USR0

Post by DVDfever »

Does anyone know how I enable this mode in Es.pectrum emulator, please, as apparently I need to do that to make a new Gigascreen demo run, but in both that AND Zesarux, I get a black screen on the demo.
User avatar
+3code
Manic Miner
Posts: 442
Joined: Sat Mar 19, 2022 7:40 am

Re: USR0

Post by +3code »

AndyC wrote: Sun Apr 11, 2021 8:02 pm 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).
Ah, I thought the SPECTRUM command was standard in all the 128k models.
AndyC
Dynamite Dan
Posts: 1420
Joined: Mon Nov 13, 2017 5:12 am

Re: USR0

Post by AndyC »

+3code wrote: Sat Apr 27, 2024 8:14 pm Ah, I thought the SPECTRUM command was standard in all the 128k models.
It's in all 128 models, but the behaviour is slightly different. The original 128 and +2 lock the paging mechanism, the +2A and +3 do the equivalent of USR0 instead
DVDfever
Microbot
Posts: 131
Joined: Fri Mar 24, 2023 10:14 am

Re: USR0

Post by DVDfever »

+3code wrote: Sat Apr 27, 2024 8:14 pm Ah, I thought the SPECTRUM command was standard in all the 128k models.
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
Post Reply