What a stray read is
A program keeps its working data at fixed places in memory. A stray read is a bug where the code looks in the wrong place: a pointer it forgot to set, a variable some earlier routine reused for something else, a list read one entry past its end. The bytes it finds there belong to something else entirely, and they depend on whatever the computer happened to do just before.
On the Apple II nothing stops this. The game simply carries on with a wrong number: the wrong unit, the wrong "country", a terrain type taken from program code. Usually the damage is small, which is why such bugs survive. But it means the game's behaviour at those points is, in effect, arbitrary.
For the rebuild this is a real problem. It doesn't run the original's machine code, so it doesn't have the same leftover bytes in memory, and it can't reproduce what the original would have found.
The decision
At every stray read, the rebuild does what the code was meant to do. It looks up the right unit, uses the real country map, and skips units that aren't there.
That raised a question for testing: the rebuild is checked against the original after every keypress, so wouldn't the two drift apart at the first stray read? They don't, because the tests handle these spots specially. When the rebuild reaches a stray read during a test, the test runs the original on to the moment it makes the same read and hands the rebuild the very byte the original found. So in the tests the two stay in step, and everything else is still checked against the original. The same tests also work out, each time, whether the intended answer would have been different, which is where the numbers below come from.
Outside the tests, as in the playable game, there is no original running alongside, and the rebuild takes the intended path. That path is tested too, with eight whole games played by the rebuild alone.
These fixes are the core bug fixes option on the Play page, on to start with (see Bugs in the original). Switched off, the rebuild reads its own copy of the computer's memory at each of these spots: the map routines, the BASIC runtime, the module's own code and the screens, all where the original keeps them. That brings the stray reads back, but the bytes are a stand-in: zero page and the leftovers of earlier modules differ from the original's.
The numbers
Eight random games ran from the opening menu to GAME OVER on turn 31: a human or computer Highlord, in both the scenario and the campaign. They matched the original on every screen and every saved file. Across all eight:
| Stray read | Module | Times | Original ≠ intended |
|---|---|---|---|
| Interception, after the first patrol sails in | J | 127 | All 127. In 13 of them a fleet's interception check was skipped |
| The news odds: Highlord armies in the west | Q | 89 turns | 3 turns; once it changed the news |
| NO ATTACK on an empty square | D | 5 | 4: some other unit's orders changed |
| Recalling a unit onto an empty square | K | 3 | None |
| The map window's corner | C | 48–60 a game | No effect: the value is never used |
| Squares off the map | A, I | 6–46 a game | None seen |
| DRAW.F's pages before they're filled | B, C, I, J | 0 | Never happened |
The fleet reads came up in two of the eight games; the news odds are checked on turns 2–15 only.
Interception, after the first patrol sails in
What the original does. After each movement phase, the naval module goes through the moving side's units one by one. For each fleet it looks for enemy fleets nearby: an adjacent enemy fleet joins a battle where it is, and an enemy fleet on patrol 2–4 squares away sails up to join it. This works, and players of the original will have seen patrols sail in to attack.
The trouble starts the first time a patrol sails in. Finding a free square for it calls a country lookup, and that lookup uses two of the naval module's variables as its own scratch space: the one that holds where the side's unit list starts, and the loop's counter. So for the rest of that phase each "unit" is read from the 6502's zero page (the first 256 bytes of memory, where the BASIC runtime keeps its scratch values) instead of from the unit list, and the loop carries on from wherever the lookup left its counter.
What the rebuild does now. It takes each unit from the side's list, as intended. The jump in the loop counter is a plain bug rather than a stray read, so it is kept.
Known impact. The biggest change of all, though it only matters after a patrol has engaged. In the two games where that happened, the original read the wrong unit every time afterwards, 127 out of 127. What matters is whether the unit is a fleet, because only a fleet goes on to intercept:
| Seed | Neither a fleet | Interception skipped | Junk unit a fleet |
|---|---|---|---|
| 5 | 84 | 9 | 0 |
| 11 | 30 | 4 | 0 |
"Interception skipped": the unit in the list was one of the moving side's fleets, but the one the original read wasn't a fleet, so that fleet got no interception check.
So in the original, once one patrol has sailed in during a movement phase, the moving side's remaining fleets get no interception check for the rest of that phase. In the rebuild they are all checked as the code meant: 13 more checks in those two games.
Possible unknown impact. More sea battles in phases where several fleets meet enemy fleets after a first patrol has engaged. More battles at sea mean more transports caught or lost, and that feeds into the land war.
The news odds
What the original does. At the start of each turn from 2 to 15, the game checks whether Highlord armies are in the west, in certain countries. The country lookup it calls never sets up the addresses of the country map, so it reads zero page as if it were the map, and gets an arbitrary "country" for each unit.
What the rebuild does now. It reads the real country map.
PC version The 1990 DOS version makes the same check and reads the real country map, because its lookup uses map addresses set when the game starts. Its news odds are otherwise the same as the Apple II's.
Known impact. The answer, "Highlord armies in the west", makes several Whitestone news events more likely (a chain of events from 24 to 29, and events 25, 35 and 36). Over 89 turns the original got the answer wrong 3 times. Once that changed the turn's news: the original announced Highlord event 23 and Whitestone event 34, where the intended answer gives no Highlord event and Whitestone event 33. In the rebuild these events follow the rule as written: they are likelier when Highlord armies really are in the west.
Possible unknown impact. Since the original's answer depends on zero page, its news odds might differ more in situations the eight games didn't reach. Most of the time it happened to agree with the map.
NO ATTACK on an empty square
What the original does. A human player's NO ATTACK order cancels the attack orders of the units in the last square the game listed. (That is usually the attacker's own square, but after a move it can be the square the unit just stepped into. That quirk is a rules bug, fixed when Rules bug fixes is on: see Bugs.) When that square was empty, the game's loop still runs once. The unit number then comes from leftover memory, and whichever unit it names has its orders wiped.
What the rebuild does now. An empty square has no units, so nothing changes.
Known impact. In 4 of 5 cases the original changed some unrelated unit, cancelling its attack order. The same two bytes also hold a loaded unit's ship and saved map icon, so if the junk unit was cargo, that is overwritten too. The rebuild does neither.
Possible unknown impact. In the original, a corrupted cargo unit could unload wrongly or vanish. That wasn't seen in the eight games.
Recalling a unit onto an empty square
What the original does. When a unit is brought back from subversion onto an empty square, the stacking check again runs its loop once with a unit number from leftover memory, and counts that phantom unit towards the square's limit.
What the rebuild does now. It counts only the units really in the square.
Known impact. None seen: all 3 cases gave the same result.
Possible unknown impact. In the original a placement could be refused as overstacked when the phantom happened to be a large unit or a flier. The rebuild allows it.
The map window's corner
What the original does. When the computer starts moving its units, it reads the corner of the map window on screen and works out the window's centre.
What the rebuild does now. The same as the original. The value is never used: before each unit moves, the same variables are set again from that unit's own position.
Known impact. None, and none possible, since nothing reads the value.
Squares off the map
What the original does. The map routines work out where a square is stored with simple arithmetic: $EDF8 + y × 70 + x, in 16 bits. For a square off the edge of the map, or for a unit carried on a ship (whose position is junk while it's aboard), the address lands outside the map. It can wrap round into the game's program code, so the square's terrain, its "occupied" flag and its height come from whatever bytes are there. This happens when placing reinforcements near the edge, in searches for nearby units, and for the terrain under a unit that is at sea.
What the rebuild does now. Such squares read as 0: empty, and tile 0, which is sea. That's right for a unit on a ship, and gives no rough-terrain bonus in battle.
Known impact. None seen: reading 0 gave the original's result every time (6–46 times a game when placing reinforcements, twice in the battle display).
Possible unknown impact. In rare cases the original could see an off-map square as occupied or rough, giving a unit a zone-of-control effect, a different placement, or a terrain bonus in battle.
DRAW.F's pages before they're filled
What the original does. The game's machine-code map library leaves its answers ("these units are in this square", "these enemies are within range") in two pages of memory, $0800–$09FF, for the BASIC modules to read. A read of those pages before the library has filled them in would see an earlier module's leftovers.
What the rebuild does now. Such a read gives 0.
Known impact. None: in all eight games, every read came after the library had filled the page. Possible unknown impact. None expected.