That thing with the blue and magenta ladders (OUT)

Y'know, other stuff, Sinclair related.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

That thing with the blue and magenta ladders (OUT)

Post by equinox »

As a follow-up to the successful thread "That thing with the bottom two lines":

In my childhood days when I was messing about with the Speccy and learning BASIC, etc. I was always fascinated by the OUT keyword. I don't think I knew what it meant, at that time: I probably thought it was a sort of more dangerous super-POKE. Today I obviously know what it means: it is outputting a byte to a port. But still, what does that mean to the system?

Since I had no friends, I would sometimes try a lot of OUT x,y combinations to see if I would get anything cool or scary. Sometimes cool and scary. Quite often, an OUT command would hang the machine and slowly fill the screen with a pattern. And I remember one particular pattern that was quite common: it was blue, black and magenta squares (not properly aligned, so they made a kind of chessboard), with white "ladders" on top.

Presumably this was the result of writing a certain sequence of values repeatedly into memory, like an LDIR, and crossing over the screen memory at 16384 upwards. But why so common, and what was the sequence? Does anyone recognise the thing I am describing? I could almost draw it. (I have also seen this happen when programs crash. Maybe only in 128K mode.)

Update: artist's impression:
Image
User avatar
ParadigmShifter
Manic Miner
Posts: 670
Joined: Sat Sep 09, 2023 4:55 am

Re: That thing with the blue and magenta ladders (OUT)

Post by ParadigmShifter »

Some OUTs send commands to the ULA (responsible for drawing the screen and syncing with the TV signal) which can cause it to do weird stuff I think.
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: That thing with the blue and magenta ladders (OUT)

Post by AndyC »

Firstly, there's no way a single OUT could do something like that on its own. The hardware just doesn't work that way.

But you do remember it, so why? Probably what's happened is you've caused the paging hardware to switch something that the system isn't expecting. So suddenly changed what ROM is active and caused the system to crash or maybe changed over to the second screen display and that is just whatever garbage was in RAM page 7 at the time.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

AndyC wrote: Fri Mar 01, 2024 8:31 am Firstly, there's no way a single OUT could do something like that on its own. The hardware just doesn't work that way.

But you do remember it, so why? Probably what's happened is you've caused the paging hardware to switch something that the system isn't expecting. So suddenly changed what ROM is active and caused the system to crash or maybe changed over to the second screen display and that is just whatever garbage was in RAM page 7 at the time.
Truly, Andy, I 100% know it happened. Remember this was 128 BASIC, so it might have collided with some kind of interrupt that the BASIC manager was doing. Your comment is interesting because it does suggest that the numbers (OUT x,y) might not matter, rather only the time and synchronisation. But don't tell me that I didn't see what I saw. It definitely happened. Many times.

I can tell you one more: once, a random OUT command displayed the opening menu "Tape loader, Calculator, etc." -- but with weird colours and border. And I can guarantee this was true, really happened, and only from typing some OUT (random numbers x,y) in BASIC editor. You would think "it must require a USR call to display the menu", but really it didn't. I certainly can't imagine that the opening menu is secretly hidden behind BASIC on the second screen. So who can explain this?
User avatar
PROSM
Manic Miner
Posts: 476
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: That thing with the blue and magenta ladders (OUT)

Post by PROSM »

As Andy says, a random OUT doesn't cause this directly, but rather it is the catalyst for the effects you describe.

The memory paging register on the 128K machine is usually accessed via port $7FFD. However, this port address is only partially decoded - the hardware only checks that A15 and A1 are 0, everything else is ignored (on the +2A/+3, it also checks that A14 is 1).

It's the same with the ULA register - it's at address $FE (the high byte is used to signal which keyboard rows to check), but only checks A0 is 0, so it can actually be accessed at every even address.

This means that, on a 128K machine, since only 2 bits of the 16 bit address are checked, any random number you use for the port address has a 1 in 4 chance of hitting the paging hardware.

So why does it happen? Well, the paging register controls:
  • Which 16K bank is paged in at $C000
  • Which ROM is paged in at $0000
  • Which screen (normal or shadow) is being sent to the video output
Considering that the Z80's stack normally starts at the top of the memory, the chances are that when you did your random OUT, you ended up swapping out the bank with the stack on it. Of course, this would lead to unexpected results as soon as the Z80 tried reading something back from the stack (with e,g, POP or RET), and would likely cause it to run off into some random code.

I had a go myself, and by luck managed to get a similar pattern to the ladders you describe with OUT 25, 34.

Obviously the 25 can be substituted with any other suitable address, and since the paging hardware ignores the top 2 bits of the byte you give it, 34 could also be substituted with 98, 162 or 226.

EDIT: Have just had a go at doing the OUT with the stack out of the way (cleared to 32767) and it still happens. Not sure why that is - presumably it has more to do with the paging hardware being disabled by bit 5 being set, and making the 128K ROM go a bit nutty when it tries to change pages, not knowing it can't. If you try it with bit 5 reset (i.e. OUT 25, 2), so the paging hardware stays active, all you get is a reset to 48K BASIC.
Last edited by PROSM on Tue Mar 05, 2024 7:03 am, edited 1 time in total.
All software to-date
Working on something, as always.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

PROSM wrote: Tue Mar 05, 2024 6:57 am I had a go myself, and by luck managed to get a similar pattern to the ladders you describe with OUT 25,34.
ANDY APOLOGISE
ANDY APOLOGISE
ANDY APOLOGISE
I would love a screenshot actually. The blue-and-magenta ladder really is quite a common crash, I think it should be a sort of representative icon of the Speccy scene (like how somebody, once, suggested that the "glider" in Conway's life automaton should be a HACKER symbol). We can't use the rainbow because that's the God and/or gay sign. I really really want a screenshot of it.
Even when I had a +D interface (which had its little internal 8K RAM) I doubt I could have taken a shot because by the crash time, everything was so broken that you couldn't do a screen grab. If you really wanted to fk things up, hold down the +D snapshot button while also hitting the reset button on your +2. OH! CRUEL!

I first encountered the "second screen" when I made the Blizzard Pass text adventure crash (a strange game that was bundled with the +2 and had to be loaded with a special OUT command, ah, now we see the swine -- "USR0" wasn't invented yet). I noted that the screen was undrawable, but you could hear 48K keyclicks, and do stuff like BORDER 1; and the screen immediately became visible once you pressed the reset button. It took 20 years to half-understand why.

"Hi, I'm Alan Cox, you may remember me from such software as Blizzard Pass, and the network substructure of Linux"
Last edited by equinox on Tue Mar 05, 2024 7:08 am, edited 2 times in total.
User avatar
PROSM
Manic Miner
Posts: 476
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: That thing with the blue and magenta ladders (OUT)

Post by PROSM »

equinox wrote: Tue Mar 05, 2024 7:03 am I would love a screenshot actually.
Sure, here it is:

Image

Not quite how you depicted it, but close.
All software to-date
Working on something, as always.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

PROSM wrote: Tue Mar 05, 2024 7:07 am Sure, here it is:

Image

Not quite how you depicted it, but close.
WOW I love you, that's it. That's what I was staring at in my childhood. (Well, there were variations. This isn't the "ladders" I mentioned, but very close (probably same attrs but different bitmap). For some reason the colours are identical, I never saw a red and yellow one.)
Please describe the screen in byte terms. 1-3-7... but I don't see any 5 cyan. What repeating pattern are we seeing, in the Spectrum brain?
Last edited by equinox on Tue Mar 05, 2024 7:22 am, edited 2 times in total.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

PROSM wrote: Tue Mar 05, 2024 6:57 am and would likely cause it to run off into some random code.
Do you reckon The Apprentice will pay me a $1337 vulnerability bonus for finding this, like Google does? sigh

(Last night on Speccy Discord I asked whether the 'user number' on CP/M would actually stop you touching other people's files -- you know what I mean, you can put a number in the +3 disk syntax -- and I was put in my place like "no, you could still smash the disk or pour water over it". Jerk. Nobody ever put their +3 in a protected data centre.)
User avatar
PROSM
Manic Miner
Posts: 476
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: That thing with the blue and magenta ladders (OUT)

Post by PROSM »

equinox wrote: Tue Mar 05, 2024 7:08 amWhat repeating pattern are we seeing, in the Spectrum brain?
Here's the first 256 bytes or so, as viewed in a hex editor:

Code: Select all

Hex View  00 01 02 03 04 05 06 07  08 09 0A 0B 0C 0D 0E 0F
 
00000000  5B 38 00 00 5B 48 00 38  00 0D 5B 38 00 00 5B 48  [8..[H.8..[8..[H
00000010  00 38 00 0D 5B 38 00 00  5B 48 00 38 00 0D 5B 38  .8..[8..[H.8..[8
00000020  00 00 5B 48 00 38 00 0D  5B 38 00 00 5B 48 00 38  ..[H.8..[8..[H.8
00000030  00 0D 5B 38 00 00 5B 48  00 38 00 0D 5B 38 00 00  ..[8..[H.8..[8..
00000040  5B 48 00 38 00 0D 5B 38  00 00 5B 48 00 38 00 0D  [H.8..[8..[H.8..
00000050  5B 38 00 00 5B 48 00 38  00 0D 5B 38 00 00 5B 48  [8..[H.8..[8..[H
00000060  00 38 00 0D 5B 38 00 00  5B 48 00 38 00 0D 5B 38  .8..[8..[H.8..[8
00000070  00 00 5B 48 00 38 00 0D  5B 38 00 00 5B 48 00 38  ..[H.8..[8..[H.8
00000080  00 0D 5B 38 00 00 5B 48  00 38 00 0D 5B 38 00 00  ..[8..[H.8..[8..
00000090  5B 48 00 38 00 0D 5B 38  00 00 5B 48 00 38 00 0D  [H.8..[8..[H.8..
000000A0  5B 38 00 00 5B 48 00 38  00 0D 5B 38 00 00 5B 48  [8..[H.8..[8..[H
000000B0  00 38 00 0D 5B 38 00 00  5B 48 00 38 00 0D 5B 38  .8..[8..[H.8..[8
000000C0  00 00 5B 48 00 38 00 0D  5B 38 00 00 5B 48 00 38  ..[H.8..[8..[H.8
000000D0  00 0D 5B 38 00 00 5B 48  00 38 00 0D 5B 38 00 00  ..[8..[H.8..[8..
000000E0  5B 48 00 38 00 0D 5B 38  00 00 5B 48 00 38 00 0D  [H.8..[8..[H.8..
000000F0  5B 38 00 00 5B 48 00 38  00 0D 5B 38 00 00 5B 48  [8..[H.8..[8..[H
It continues in this manner all the way down into the attribute area - to be honest I'm not sure of the significance of the values right now - it could be a stack run amok, just pushing the same values over and over, or something else.
equinox wrote: Tue Mar 05, 2024 7:16 am Do you reckon The Apprentice will pay me a $1337 vulnerability bonus for finding this, like Google does? sigh
I reckon a discovery like this is worth 1337 Iranian Rial - at current exchange rates that's about 2.5 pence :mrgreen:

EDIT: Put quote at top to clarify which message I was replying to
Last edited by PROSM on Tue Mar 05, 2024 7:24 am, edited 1 time in total.
All software to-date
Working on something, as always.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

PROSM wrote: Tue Mar 05, 2024 7:22 am to be honest I'm not sure of the significance of the values right now
ok anyone want a Nobel Prize?
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: That thing with the blue and magenta ladders (OUT)

Post by AndyC »

equinox wrote: Tue Mar 05, 2024 7:03 am ANDY APOLOGISE
I stand by what I said. The OUT doesn't really do all the things you're seeing, it's just a consequence of what follows.

The OUT swaps the paging arrangement to some unexpected configuration. At that point one of maybe four things could suddenly be true:

1) One of the other 128K ROMs is paged in, since the BASIC OUT command code is in the 48K ROM it'll suddenly start executing random instructions from another ROM. Which may cause random values to be written to the screen.

2) The stack will get paged out, when the OUT command finishes, BASIC will attempt to return but read nonsense values from RAM. Random code gets executed, fills the screen.

3) The 128K second screen is made active but paged out. You'd see garbage on the screen (possibly) but BASIC would still run (you just couldn't see what you were typing). It's possible this would correct itself, since 128 BASIC fiddles with the paging often enough that it probably resets the display.

4) On a +2A/+3, you could switch to an "all RAM" configuration. Your BASIC program may no longer be in visible memory, the stack may or may not be present but the ROM that is executing definitely won't be. Again this leads to arbitrary execution of code and could fill the screen with garbage.

But it's not the OUT that does it, if you did the same thing from a controlled environment (machine code, executing from the central RAM with the stack safely positioned and interrupts disabled) then it wouldn't give you the same result.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

AndyC wrote: Firstly, there's no way a single OUT could do something like that on its own. The hardware just doesn't work that way.
AndyC wrote: Tue Mar 05, 2024 7:47 am I stand by what I said. The OUT doesn't really do all the things you're seeing, it's just a consequence of what follows.
“It's nonsense,” scoffed Myrtle, “he's a silly old bird.
But if it makes him feel better, let him have the last word.”

The point is that it can *run*/execute something, and not merely do a beep or border. Maybe it is a consequence but you did say this was totally impossible. 'sall. #3 (BASIC works but we can't see our typing) was a real interesting mystery to me as a kid -- it was many years before I knew about "banks" and "paging" and lalalala (when it becomes totally obvious that we have just mapped a load of 0x00 to the display) -- this "blind BASIC" state could be encountered only by nasty crashes

P.S. Pro-tip for nerds going to Revision demoparty this Easter: tell them about why you have to write "USR 0" on your Spectrum to access full memory. chicks love that.
User avatar
TakuikaNinja
Drutt
Posts: 30
Joined: Mon Dec 25, 2023 11:02 am
Location: New Zealand
Contact:

Re: That thing with the blue and magenta ladders (OUT)

Post by TakuikaNinja »

Code: Select all

10 FOR a=1 TO 3: PRINT "ANDY APOLOGISE": NEXT a
20 PAUSE 100: OUT 25,34
I think I did it right... wait, why did the pattern change after a while?
Edit: pressing keys during the pause seems to affect the pattern somewhat as well...

Image
Last edited by TakuikaNinja on Tue Mar 05, 2024 10:18 am, edited 1 time in total.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

TakuikaNinja wrote: Tue Mar 05, 2024 8:21 am

Code: Select all

10 FOR a=1 TO 3: PRINT "ANDY APOLOGISE": NEXT a
20 PAUSE 100: OUT 25,34
I think I did it right... wait, why did the pattern change after a while?

Image
lmao "Actually, RND is not truly random, because it follows a fixed sequence of 65536 numbers. However, these are so thoroughly jumbled up that there are at least no obvious patterns and we say that RND is pseudo-random." https://worldofspectrum.org/ZXBasicManu ... hap11.html

also used for important cryptography such as bitcoin, and that shitty racist I-Ching prediction program in the +2 manual

I am laughing so hard at the PAUSE 100. That is good manners.
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: That thing with the blue and magenta ladders (OUT)

Post by AndyC »

equinox wrote: Tue Mar 05, 2024 8:04 am The point is that it can *run*/execute something, and not merely do a beep or border. Maybe it is a consequence but you did say this was totally impossible. 'sall.
I said the hardware can't trigger something like that from a single OUT, but changing a paging register probably causes the machine to crash and display what you remember. Which sounds right to me.

It may seem like a distinction without a difference, but one of the things that puts people off delving deeper into machine code is thinking that things like this are "magic" and they'd have to learn them all, rather than entirely determistic results aee very small changes.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

AndyC wrote: Tue Mar 05, 2024 8:37 am I said the hardware can't trigger something like that from a single OUT, but changing a paging register probably causes the machine to crash and display what you remember. Which sounds right to me.

It may seem like a distinction without a difference, but one of the things that puts people off delving deeper into machine code is thinking that things like this are "magic" and they'd have to learn them all, rather than entirely determistic results aee very small changes.
Funnily enough I was speaking last night to THAT TELETEXT GUY and he didn't like SQL because it seemed like weird new nerd stuff.
I said: this is a useful efficient way to find data by recursive subsets.
He said "nooooo I hate it it's rubbish"
I said: look, in SQL, you can write "select x... join y... join z... " and gradually find what you want.
He said "nooooo I hate it it's rubbish"
I said: but what if you had access to the underpants of andy C.

OOPS. Yes the point was "people don't learn things because they assume it is magic". Well that's certainly how i got into my modern 2024 job based on mostly writing Spectrum BASIC. I work for the French nuclear missile industry.
User avatar
TakuikaNinja
Drutt
Posts: 30
Joined: Mon Dec 25, 2023 11:02 am
Location: New Zealand
Contact:

Re: That thing with the blue and magenta ladders (OUT)

Post by TakuikaNinja »

equinox wrote: Tue Mar 05, 2024 9:50 am Funnily enough I was speaking last night to THAT TELETEXT GUY and he didn't like SQL because it seemed like weird new nerd stuff.
Reminds me of Windows 7 (and older, god forbid) users who think they have the audacity to complain about modern software compatibility.
Separately, there is an opposite condition where people don't care about retro systems because it seems like old nerd stuff to them.

Uh, where were we again? Silly OUT commands crashing the Speccy with odd screen patterns? I mean, this is just as bad as CLOSE #4, I think.
User avatar
Guesser
Manic Miner
Posts: 641
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: That thing with the blue and magenta ladders (OUT)

Post by Guesser »

I'd Had Some Port, but I don't think that's an entirely accurate record of the conversation.

I've no desire to read it again to find out though :lol:
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

Guesser wrote: Tue Mar 05, 2024 10:50 am I'd Had Some Port, but I don't think that's an entirely accurate record of the conversation.
Sadly there is no IHSP instruction on a Z80.
....... YET
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

TakuikaNinja wrote: Tue Mar 05, 2024 10:37 am Reminds me of Windows 7 (and older, god forbid) users who think they have the audacity to complain about modern software compatibility.
Separately, there is an opposite condition where people don't care about retro systems because it seems like old nerd stuff to them.

Uh, where were we again? Silly OUT commands crashing the Speccy with odd screen patterns? I mean, this is just as bad as CLOSE #4, I think.
Try again, I think you were making an important point before you went beyond 5 or 6 words.

CLOSE #4 terror is fascinating but we can't talk about that. It's just Speccies being bad.
User avatar
Guesser
Manic Miner
Posts: 641
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: That thing with the blue and magenta ladders (OUT)

Post by Guesser »

equinox wrote: Tue Mar 05, 2024 11:13 am Sadly there is no IHSP instruction on a Z80.
....... YET
It's one of the undocumented prefixed ones...
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: That thing with the blue and magenta ladders (OUT)

Post by equinox »

Guesser wrote: Tue Mar 05, 2024 10:50 am I'd Had Some Port, but I don't think that's an entirely accurate record of the conversation.
I asked an AI and it said "this is definitely 90% accurate".
And I think the Ai was 80% accurate.
What was the chance that you would fail to get through Skylab Landing Bay?
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: That thing with the blue and magenta ladders (OUT)

Post by AndyC »

equinox wrote: Tue Mar 05, 2024 11:19 am What was the chance that you would fail to get through Skylab Landing Bay?
105%, approximately.
User avatar
Guesser
Manic Miner
Posts: 641
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: That thing with the blue and magenta ladders (OUT)

Post by Guesser »

0% chance I would play long enough to get to it in the first place
Post Reply