Lobsters - 03 Dec 2026
Page 5 of 10
Read its sixteen entries in bitmap order, blue, green, red and a spare byte. That makes 5, 53, 178, 0 a red and 210, 62, 45, 0 a blue. The flag and edition name are already on the screen before the kernel gives the video card any of these colours. So is a 22 by 9 pixel sprite in the top left. Windows reads three little 6 by 9 squares back out of the video memory there and blacks the corner out again. By the time you can see anything, the sprite those squares came from is gone. A thread brings up MainPalette in twenty steps at intervals of 80 milliseconds (the comment says 100). Once it has done that, the squares can be sent down the track.
You might expect the fade to end on the colours somebody picked for the logo. It falls one step short, and you can work out just how bright XP got from the order of two operations in the thread.
case PLT_START:
FadePalette ((UCHAR)(PaletteNum));
FadePaletteColor (0, COLOR_FADE_TEXT); // #1 - color of fading text
if ((++PaletteNum)>=FADE_GRADES) {
PltRotBarStatus = PLT_CYCLE;
FadingIn = TRUE;
PaletteNum = 1;
}
break;
=FadePalette= multiplies each colour by PaletteNum and divides by FADE_GRADES, which is 20. When PaletteNum reaches 20 the thread has already finished applying colours and switches to moving the squares. So the biggest multiplier the screen actually got was 19/20. The brightest white was 242, or 60 out of 63 by the time it went into the VGA's six-bit colour registers. People watched that logo come up at 95% brightness for about a decade. I doubt anybody noticed. The demo reads the real boot.bmp and puts it through the same fade.
boot.bmp and the other bitmaps from and the other bitmaps from
base/ntos/init, decoded by your browser, with the kernel's palette pushed through the original fade: twenty ticks of 80 ms, and the last one stops at 19/20, so the white reads 60 of 63. Turn on X-ray and press Replay to see what is in video memory while the screen is still black, including the sprite in the top-left corner that the squares are copied from. Server shows the ".net" version, and Home Edition's squares come out green, which is what the palette in this tree says. "Let the fade finish" shows the logo at the brightness it was drawn for.
, decoded by your browser, with the kernel's palette pushed through the original fade: twenty ticks of 80 ms, and the last one stops at 19/20, so the white reads 60 of 63. Turn on X-ray and press Replay to see what is in video memory while the screen is still black, including the sprite in the top-left corner that the squares are copied from. Server shows the ".net" version, and Home Edition's squares come out green, which is what the palette in this tree says. "Let the fade finish" shows the logo at the brightness it was drawn for.
Windows Server 2003, still called Windows .NET Server when this code was written, didn't get a separate boot screen. The code in base/ntos/init/init.c draws the XP bitmap. On products other than the workstation it then alters the lettering.
InbvBitBlt(Bitmap, 0, 0);
//if (SharedUserData->NtProductType == NtProductServer) {
if (SharedUserData->NtProductType != NtProductWinNt) {
// make some fixes for server bitmap: remove "XP"
UCHAR sav_copyright[64];
InbvScreenToBufferBlt(sav_copyright, 413, 237, 7, 7, 8);
InbvSolidColorFill(418,230,454,256,0);
InbvBufferToScreenBlt(sav_copyright, 413, 237, 7, 7, 8);
It copies the small registered-trademark sign after "Windows" into a buffer (called sav_copyright, although it's an R in a circle), paints a black rectangle over the letters XP, puts the sign back, and then the kernel stamps a small ".net" bitmap on top. The Server button in the blog demo does the same, in the same order and at the same coordinates.
The squares don't measure the work, but the kernel does remember some of it. XP's cache manager records the memory pages used during boot, then reads them ahead of time on later boots, grouping reads that would otherwise send the disk head back and forth. The boot prefetcher, base/ntos/cache/prefboot.c, by Cenk Ergan in March 2000, has a particularly nice trick. It measures how long the video driver takes to initialise and saves that time in the registry. Next boot, while the video driver is busy, it reads pages that later parts of startup will need. Its budget is the previous delay, rounded down to whole seconds, multiplied by a configurable number of pages per second.
//
// Determine how many pages max we can prefetch in parallel to video
// initialization.
//
VideoInitMaxPages = (VideoInitTime / 1000) * VideoInitPagesPerSecond;
//
// We can only prefetch pages used after winlogon in parallel to video
// initialization. Determine exactly how many pages we will prefetch
// starting from the last boot phase.
The default is 1,500 pages per second, and it only uses this opportunity for pages needed after Winlogon starts. If there is no valid previous timing, this part of the budget is zero. The window system really calls the prefetcher immediately before and after InitVideo, so this is wired into normal startup. The logo's animation and the disk's activity are doing separate jobs. Behind the looping squares, Windows is using one piece of waiting to hide another. Mark Russinovich and David Solomon's 2001 account of XP's kernel explains the wider prefetch design.
How the Start menu picks its six programs
XP's Start menu has your browser and your mail client pinned at the top of the left column, and six programs you "use frequently" under them. I'd always assumed that list counted launches. It's a score, and the score decays when you stop using a program.
The engine is called UserAssist and lives in shell/browseui/emclient. Its design note (shell/docs/uassist.txt, February 1998, from the Internet Explorer 5 days) counts time in sessions, which are roughly days. A new session starts when you open the Turn Off Computer dialog long enough after the last one, or after twelve hours with no keyboard or mouse input. "Long enough" is meant to be twelve hours and comes out at about ten and three quarters, because UserAssist's clock ticks in 53.7-second units that it treats as minutes. As uacount.h puts it, "currently we just assume a UATIME is exactly 1 minute, which it's not... easy enough to do, but we'll wait until i have time to do the math." Every time Explorer reads a program's score it first decays it by the number of sessions since it was last used, through a table in uacount.cpp marked "from mso-9 spec". MSO-9 is Office 9, better known as Office 2000, whose personalised menus hid the items you hadn't clicked lately. A few sessions without a program cost it a point, the losses grow from there, and thirty-one sessions after you last used it the score is gone. Its first row gives the thresholds in sessions, 3, 6, 9, 12, 17, 23, 29 and 31.
// from mso-9 spec
// last used 'timTab' sessions ago => dec by >-of abs, pct
// n.b. this table is non-cumulative
static const int timTab[] = { 3, 6, 9, 12, 17, 23, 29, 31, -1, };
static const int absTab[] = { 1, 1, 1, 2, 3, 4, 5, 0, 0, };
static const int pctTab[] = { 0, 0, 0, 25, 25, 50, 75, 100, 100, };
The second row gives the points to lose, 1, 1, 1, 2, 3, 4, 5 and 0. The third gives percentages, 0, 0, 0, 25, 25, 50, 75 and 100. For each threshold a program has gone past or reached, its score loses that column's points or its percentage of what's left, whichever is bigger. So a program you haven't opened for twelve sessions has lost a point three times, and then two points or a quarter of what was left, whichever is more.
Launching a program doesn't just add one either. The code decays the old score, adds one, and then bumps the result up to six if it's lower. That's how a single launch comes to be worth six.
// 981029 new incr algorithm per ie5 PM
// UAC_MINCOUNT: initial inc starts at 6
// _fNoDecay: but, UAssist2 doesn't do this
if (_cCnt < UAC_MINCOUNT && !_fNoDecay)
_cCnt = UAC_MINCOUNT;
The header that defines that six files it under "tunable values for IncCount (talk to your neighborhood PM)", which I love.
There's a fairly practical reason to care about the six. People examining a seized machine used the UserAssist entries in the registry to tell what had run on it. XP-era guides said the raw count started at five instead of zero, so you ought to subtract five. RegRipper, widely used for this work, subtracts five whenever the stored value is greater than five. It works beautifully for a first launch. Suppose you launched a program fifty times, then went 31 UserAssist sessions without using it before opening it again. The same calculation gives you one launch. As for the value names, the "encryption" is ROT13, with a comment about someday needing an international-aware scheme. Someday never came.
There's another odd thing about a list of programs you use frequently. You can have one before you've used the computer. When Explorer first builds the Start panel, CreateInitialMFU in shell/explorer/desktop2/proglist.cpp fills the six positions with scores already assigned, 19 for the first one down to 14 for the last.
// ASsert that the slots are evenly shared between MSFT and the OEM
COMPILETIME_ASSERT(ARRAYSIZE(rgpidlMFU) % 2 == 0);
// The OEM can provide up to four apps, and we will put as many
// as fit into into bottom half.
{
MFUEnumerator mfuOEM;
for (iSlot = ARRAYSIZE(rgpidlMFU)/2; iSlot < ARRAYSIZE(rgpidlMFU); iSlot++)
{
rgpidlMFU[iSlot] = mfuOEM.Next(&mex, TEXT("OEM%d"), 4, FALSE);
}
}
A PC manufacturer could supply the bottom three entries. Microsoft filled what was left from its list, which in the original release included MSN Explorer, Windows Media Player, Movie Maker, the XP tour and the transfer wizard. SP1's longer list included Windows Messenger. Internet Explorer itself is on the list but gets passed over when it would duplicate the default browser pinned just above it. Given the argument in 2001 over who got to put what on the Windows desktop, I'd guess the lawyers took an interest in that condition. The demo starts with the same scores and lets you see what becomes of them a day at a time.
uacount.cpp and and
proglist.cpp: the decay table, the clamp to six, the first-logon seeding as XP first shipped, and the ROT13 in the registry. Run Notepad three times, press "Two weeks of use", run it once more and look at the registry pane; a forensics tool subtracting five would say you launched it once. "Two weeks away", with the computer switched off, costs a single session, because UserAssist counts sessions and a switched-off computer has none.
: the decay table, the clamp to six, the first-logon seeding as XP first shipped, and the ROT13 in the registry. Run Notepad three times, press "Two weeks of use", run it once more and look at the registry pane; a forensics tool subtracting five would say you launched it once. "Two weeks away", with the computer switched off, costs a single session, because UserAssist counts sessions and a switched-off computer has none.
FreeCell's game numbers
FreeCell was Jim Horne's. His history line puts the first code in June 1991 and the Win32 port in October. If the title says "FreeCell Game #11982", 11982 is the number that went into the C runtime's random generator. In ShuffleDeck in shell/osshell/ep/freecell/display.c the cards start out numbered zero to 51. Take rand() modulo the number left, give that card to the next column and fill its place with the last card still in the deck. Do this fifty-two times. Even rand() is here in base/crts/crtw32/misc/rand.c, a multiply and an add. The comment on srand() credits the BASIC random number generator. Anybody using that same generator and deal number could reproduce the game.
My favourite comment in the leak is just above that shuffle. A game developer coming along later might quite reasonably think of improving it. The warning was to expect "the wrath of people who have invested a huge amount of time solving these games". The shuffle algorithm was already public, so players could refer to a game by its number.
//
// Caution:
// This shuffle algorithm has been published to people all around. The intention
// was to let people track the games by game numbers. So far all the games between
// 1 and 32767 except one have been proved to have a winning solution. Do not change
// the shuffling algorithm else you will incur the wrath of people who have invested
// a huge amount of time solving these games.
//
// The game number can now be upto a million as the srand takes an integer but the
// the random value generated by rand() is only from 0 to 32767.
//
srand(gamenumber);
for (i = 0; i < 52; i++)
{
j = rand() % wLeft;
wLeft --;
card[(i%8)+1][i/8] = deck[j];
deck[j] = deck[wLeft];
}
Between 1994 and 1995 more than a hundred volunteers in Dave Ring's Internet FreeCell Project worked through the original 32,000 deals. The one nobody could win was 11982. Michael Keller keeps the history in his FreeCell FAQ. Now imagine changing either the shuffle or Microsoft's rand(). All those solved games would keep their numbers and acquire different cards. A detail of how one little game happened to work had become an API.
There's a second comment in XP because FreeCell can now take a game number up to a million. The seed will take an integer that large. A value you get back from rand() is still between zero and 32,767, which makes a difference when the New Game command tries to choose a number for you. The dialog rather neglects to mention this.
UINT GenerateRandomGameNum()
{
UINT wGameNum;
srand((unsigned int)time(NULL));
rand();
rand();
wGameNum = rand();
while (wGameNum < 1 || wGameNum > MAXGAMENUMBER)
wGameNum = rand();
return wGameNum;
}
F2 deals from 1 to 32,767. The test against a MAXGAMENUMBER of one million never enters into it, so to see the remaining 967,233 deals you have to type a number into Select Game. Beneath the ordinary range are two more, -1 and -2. Someone laid those out by hand. According to Keller the joke goes back to Windows 95, and the dialog calls negative numbers special cases for unwinnable shuffles. In -1 the columns are each a single suit and the aces are buried under the odd cards. In -2 each ace is underneath its King, Queen, Jack, Ten, Nine and Eight at the bottom of a column.
Solitaire repeats too, only it doesn't show you the numbers. In shell/osshell/games/sol/sol.c it seeds each deal with the Unix time modulo 32,768. That's 32,768 deals recurring every 9 hours, 6 minutes and 8 seconds. Two XP computers with the right time would deal the same cards if you started in the same second. The comment there is about a report that the games never changed, which the people working on it hadn't been able to reproduce.
// It was reported that games never changed.
// We could not repro it so see if it happens
// and output a message to the debugger.
//
Param= (INT) time(NULL);
srand( igmCur = ((WORD) Param) & 0x7fff);
Retry to Lose,
or Ignore to Cancel.
ShuffleDeck and the C runtime's and the C runtime's
rand(). Games 1, 617 and 11982 match the deals people have been publishing since the nineties; -1 and -2 are the hand-built ones. Press New Game a few times, then "Press once a second" and let it run for a few seconds: the count of different games stops at 32,767 and never moves again, although the dialog promises a million. With the demo focused, Ctrl+Shift+F10 opens the User-Friendly User Interface. (In real XP, New Game in the middle of a deal first asks whether you want to resign and counts a loss; I didn't bother with that.)
. Games 1, 617 and 11982 match the deals people have been publishing since the nineties; -1 and -2 are the hand-built ones. Press New Game a few times, then "Press once a second" and let it run for a few seconds: the count of different games stops at 32,767 and never moves again, although the dialog promises a million. With the demo focused, Ctrl+Shift+F10 opens the User-Friendly User Interface. (In real XP, New Game in the middle of a deal first asks whether you want to resign and counts a loss; I didn't bother with that.)
Back in FreeCell, Ctrl+Shift+F10 opens a "User-Friendly User Interface". The note says the strings needn't be translated. "Choose Abort to Win, Retry to Lose, or Ignore to Cancel." The interesting part about Abort is that you still have to make a move. The next time the normal tidy-up asks Useless() whether a card can go home, it gets yes for everything. Off go the cards in the wrong order but with their usual graceful glide. Without the cheat, aces and twos can go straight home. For a higher card both opposite-colour cards one rank below it must already be there, so nobody on the table will need that card to play on.
Internet Explorer could justify Arabic
A few months ago I wrote about how much trouble the web still has with Arabic typography, and the heart of that article was a missing feature. Arabic can be justified by elongating the strokes inside words, the kashida. Browsers stretch the spaces between words, so you get rivers. I said there that Internet Explorer 5.5 implemented text-justify: kashida in 2000, and that the value was later dropped from the CSS drafts because nobody else implemented it. What I didn't say is how IE decided where to stretch, and that code is in this tree.
IE does it in two steps. Trident, IE's layout engine, asks Uniscribe (the part of Windows that shapes complex scripts) what kind of justification point each glyph is, and Uniscribe answers with one of the Arabic classes listed in usp10.h. Then inetcore/mshtml/src/site/text/linesrv.cxx ranks those using another table and picks the best available place in each word to stretch, with ties going to the later letter. Uniscribe's letter table isn't in the tree, but Microsoft published the rules for IE 5.5 at the time, and Edo Smitshuijzen of the Khatt Foundation reproduces them.
- First comes the place after a tatweel already in the text,
- then after an initial or medial seen or sad ( ),
- then before a final heh, teh marbuta or dal ( ).
- Fourth comes the place before a final alef, tah, lam, kaf or gaf ( ).
- Fifth is before a medial ba-like letter that joins a final ra, ya or alef maqsura, so the join itself isn't stretched.
- Sixth is before a final ra, waw, ain, qaf or fa ( ),
- and seventh before any other connected letter.
- IE adds one rank at the bottom that the published list doesn't have, before a medial ba-like letter ( ).
Next page | Previous page | More Lobsters | Headlines
Original: https://lr0.org/blog/p/winxp/