The famous poke -1,x
depends on each computer's slot configuration. The general formula is poke -1,((peek(-1)xor&hff)and&hf0)*1.0625
. This is copying the high nibble of the secondary slot selection register into the low nibble. And why is this necessary? Sit down and relax.
Slots in MSX1
The original 1983 specification of the MSX system allowed for four memory slots, each divided in 4x16K pages. You can switch any page of any slot into the page with the same number (same addresses range) of the Z80, thus making the slot contents visible.
A MSX boots (let's ignore cartridge games and the disk system for now) in MSX-BASIC with the following slots configuration: BIOS ROM in page 0, BASIC interpreter in page 1, RAM in pages 2 and 3. Assuming a 64K RAM computer, a game that wants to use more RAM than the upper 32K must switch the RAM slot in page 0 and/or PAGE 1. The usual procedure for this (which works in almost all the machines) is: check the slot switched in page 3, then switch the same slot in page 0/1. And, hey, it worked.
Slots in MSX2
Life was good for those cassette games but then the MSX2 standard appeared in 1985. Amongst other improvements, it introduced the concept of expanded slots. This means that one or more of the four primary slots can be expanded, meaning that the slot actually consists of four subslots. So in that case you no longer have e.g. slot 3, but slots 3-0, 3-1, 3-2, and 3-3.
How does that work? To switch a expanded slot, let's say 3-2 in page 1, you first switch primary slot 3 in page 3. Then you write a value in the secondary slot selection register for this slot, which is located at its address FFFFh. This register contains four two-bit fields, each indicating the secondary slot number that is visible at each page when the slot is switched to that page. Whoa. So in our case the value would be xxxx10xx
(xx = the previous value).
The problem
So now let's say we are loading a game from a cassette tape in our shiny MSX2 computer. The game does the "let's check the page 3 slot and switch it in page 1" trick to get more RAM visible. But that does not work. Why?
MSX2 computers have usually slot 3 expanded, and RAM is in one of these subslots. Let's say it's in 3-2 in our case. So the game sees that slot 3 is on page 3, so it switches it on page 1... but what secondary slot is visible? Answer: we don't know, it could be anything! Chances are that it is not subslot 2 as we expect, so no RAM is actually visible and... booom.
The solution
The "magical poke" solves this by making sure that the values of the secondary slot selection register of the RAM slot for pages 0 and 1 are the same as for pages 2 and 3 (which are usually the same). You can poke directly from BASIC because the RAM slot is already visible in page 3 (-1 = &HFFFF in BASIC), then the non-expended-slots-aware game can happily switch just the primary slot, and tada! RAM is here happily waiting for us.