local angrybirdo = false;
local drawgrid = false;
local function box(x1,y1,x2,y2,color)
gui.drawNew()
if (x1 > 0 and x1 < 0xFF and x2 > 0 and x2 < 0xFF and y1 > 0 and y1 < 239 and y2 > 0 and y2 < 239) then
gui.drawRectangle(x1,y1,x2,y2,color);
end;
gui.drawFinish()
end;
local function text(x,y,str)
if (x > 0 and x < 0xFF and y > 0 and y < 240) then
end;
end;
local function toHexStr(n)
local meh = "%X";
return meh:format(n);
end;
while (true) do
if (angrybirdo and mainmemory.read_u8(0x0010) > 0x81) then memory.writebyte(0x0010, 0x6D); end;
local playerpx = mainmemory.read_u8(0x0014);
local playerpy = mainmemory.read_u8(0x001E);
local playerx = mainmemory.read_u8(0x0028);
local playery = mainmemory.read_u8(0x0032);
local playerrx = (playerpx*0xFF)+playerx;
local playerry = (playerpy*0xFF)+playery;
local playerstate = mainmemory.read_u8(0x0050);
local screenoffsetx = mainmemory.read_u8(0x04C0);
local screenoffsety = mainmemory.read_u8(0x00CB);
local playersx = (playerx - screenoffsetx);
if (playersx < 0) then playersx = playersx + 0xFF; end;
local playersy = (playery - screenoffsety);
if (playersy < 0) then playersy = playersy + 0xFF; end;
if (playerstate ~= 0x07) then
box(playersx, playersy, playersx+16, playersy+16, "green");
end;
if (mainmemory.read_u8(0x00D8) == 0) then
local levelstart = 0x6000;
local addleftcrap = math.mod(screenoffsetx,16)*-1;
local leftsplitrx = (mainmemory.read_u8(0x04BE)*0x100) + (screenoffsetx + addleftcrap);
local addtopcrap = math.mod(screenoffsety,15);
local columns = math.floor(leftsplitrx/16);
if (drawgrid) then
for i=0,15 do
for j=0,17 do
box(addleftcrap+(i*16), addtopcrap+(j*16), addleftcrap+(i*16)+16, addtopcrap+(j*16)+16, "green");
end;
end;
end;
local topsplitry = (screenoffsety);
local levelpage =
levelstart +
((math.floor(columns/16))*0xF0) +
(mainmemory.read_u8(0x00CA)*0x100) +
topsplitry;
local levelcol = math.mod(columns,16);
for j=0,15 do
if (levelcol + j > 15) then
levelpage = levelpage + 0xF0;
levelcol = -j;
end;
for i=0,14 do
local tile = mainmemory.read_u8(levelpage+(levelcol+j)+(i*0x10));
if (tile ~= 0x40) then
text(-2+addleftcrap+(j*16),5+(i*16),toHexStr(tile));
end;
end;
end;
end;
text(2,10,"x:"..toHexStr(screenoffsetx));
text(2,25,"y: "..toHexStr(screenoffsety));
text(230,10,mainmemory.read_u8(0x04C1));
text(100,10,"Page: "..playerpx..","..playerpy);
text(playersx,playersy,playerrx.."\n"..playery);
local startpx = 0x0015;
local startpy = 0x001F;
local startx = 0x0029;
local starty = 0x0033;
local drawn = 0x0051;
local type = 0x0090;
for i=0,9 do
local estate = mainmemory.read_u8(drawn+i);
if (estate ~= 0) then
local ex = mainmemory.read_u8(startx+i);
local epx = mainmemory.read_u8(startpx+i);
local ey = mainmemory.read_u8(starty+i);
local epy = mainmemory.read_u8(startpy+i);
local erx = (epx*0xFF)+ex;
local ery = (epy*0xFF)+ey;
local esx = (ex - screenoffsetx);
if (esx < 0) then esx = esx + 0xFF; end;
local esy = (ey - screenoffsety);
if (esy < 0) then esy = esy + 0xFF; end;
if ((erx > playerrx-127) and erx < (playerrx+120)) then
local wtf = "%X";
text(esx,esy,wtf:format(mainmemory.read_u8(type+i)));
if (estate == 1 and i < 5) then
box(esx, esy, esx+16, esy+16, "red");
else
box(esx, esy, esx+16, esy+16, "blue");
end;
end;
end;
end;
emu.frameadvance();
end;