$B5 is an iterator. It rolls through all units that are available for the given room, and compares their spawn blocks with the current block. This way, the order in configs doesn't matter, it may load unit 15, then unit 5, then unit 80, if that's how many units are available for that room, and the current block picks them up in that order.
But what's interesting, it increments only by 8 each frame. Which means, you can delay object spawns by a frame or more, depending on how the total amount of room spawns divides by 8. Throughout the game, it's never more than 30, and varies all the way. Most importantly - this may need manipulation only with enemies that force you to lose frames, otherwise not, since all manipulation is done by delaying your progression. So each enemy that delays you, must be checked on whether it would save time to delay its spawn (which is possible to do by 0-3 frames, depending on the room).
Updated the function. The spawn will occur when the current block matches the unit block from config AND iterator rolls though those 8 units.
Language: lua
function Spawns()
-- feos, 2014
-- uncovers which spawns will occur per frame
local SubCur= memory.readbyte(0x50)/25.6
local PosCur= AND(memory.readbyte(0x51),0xF)
local BlCur = memory.readbyte(0x4E)
local Blptr = memory.readword(0x96)
local Yptr = memory.readword(0x98)
local IDptr = memory.readword(0x9A)
local Count = memory.readbyte(0xB4)
local Iterator = memory.readbyte(0xB5)-8
local IteratorLast = memory.readbyte(0xB5)-1
while (Iterator < 0) do Iterator = Count+Iterator end
if (IteratorLast < 0) then IteratorLast = Count+IteratorLast end
local Interrupt = AND(memory.readbyte(0x4C),0x40)
if (memory.readbyte(0x1FC) == 0x87)
or (memory.readbyte(0x1F3) == 0xD8) then
for i = 0,Count-1 do
local color1 = "white"
local block = memory.readbyte(Blptr+i)
local ypos = memory.readbyte(Yptr +i)
local id = memory.readbyte(IDptr+i)
local x = i*16%256+1
local y = 57+math.floor(i/16)*30
if (block == BlCur) then gui.box(x-1,y-1,x+12,y+23,"#00ff0088") end
if (i+1 >= Iterator) and (i+1 < Iterator+8)
or (i+1 < Iterator+8-Count) then color1 = "#ffccaaff" end
if (Interrupt > 0) then color2 = "red" else color2 = "#44ffffff" end
gui.text(x,y,string.format("%X\n%X\n%X",block,ypos,id),color1)
gui.text(108,41,string.format("Block: %X.%02d.%d\nIterator: %02d-%02d/%d",
BlCur,PosCur,SubCur,Iterator,IteratorLast,Count),color2,"#000000ff")
end
end
end
Whole script:
http://pastebin.com/48RmPqJR