dofile("textrender.lua");
mouse_vx = 0;
mouse_vy = 0;
mouse_deadzone = 8192
mouse_ysensitivity = 70;
mouse_xsensitivity = 70;
last_x = 0;
last_y = 0;
last_d = 0;
last_f = 0;
dx = 0;
dy = 0;
dd = 0;
wolfmap = {};
for i=0,4095,1 do
wolfmap[i] = 0;
end
htable = {};
for i=1,150,1 do
htable[i] = 0;
end
hstring = "";
while true do
a, b = jpcrr.wait_event();
if a == "lock" then
jpcrr.hud.top_gap(3, 16);
jpcrr.hud.right_gap(3, 512);
jpcrr.hud.bottom_gap(3, 112);
x = jpcrr.read_dword(0x004882E);
y = jpcrr.read_dword(0x0048832);
d = jpcrr.read_word(0x00048848);
timer = jpcrr.read_word(0x471DE);
f = jpcrr.frame_number();
spd = math.sqrt(dx * dx + dy * dy)
render_text(3, 0, 0, string.format("(%7d,%7d) %3d [%+5d,%+5d](%f) %+3d", x, y, d, dx, dy, spd, dd),
false, 0, 255, 0);
render_text(3, 0, 432, string.format("Time: %5d",timer),
false, 0, 255, 0);
if f ~= last_f then
dx = x - last_x;
dy = y - last_y;
dd = d - last_d;
last_x = x;
last_y = y;
last_d = d;
last_f = f;
end
for i=0,4095,1 do
tile = wolfmap[i];
if tile>0x7F then
doornum = tile - 0x80;
dooropen = jpcrr.read_byte(0x425F7+doornum*2);
if dooropen<0xFF then
jpcrr.hud.box(3,640+math.floor(i/64)*8,(i%64)*8,math.floor(((0xFF-dooropen)/0xFF)*8),8,0,0,0,0,0,0,255,255,255);
end
elseif tile>0 then
jpcrr.hud.box(3,640+math.floor(i/64)*8,(i%64)*8,8,8,0,0,0,0,0,255,255,255,255);
end
end
jpcrr.hud.circle(3,math.floor(x/8192)+640,math.floor(y/8192),4,0,0,0,0,0,255,69,0,255);
jpcrr.hud.circle(3,math.floor(x/8192)+640+math.cos(math.rad(d))*4,math.floor(y/8192)-math.sin(math.rad(d))*4,2,0,0,0,0,0,255,69,0,255);
--4882F: enemy x
for i=1,150,1 do
enemyt = jpcrr.read_word(0x48822+60*i);
if enemyt==0 then break end -- no ID, end of the list (...right?)
enemyh = jpcrr.read_word_signed(0x4884A+60*i);
if enemyh>0 then -- it's alive, otherwise move on
enemyx = jpcrr.read_word(0x4882F+60*i);
enemyy = jpcrr.read_word(0x48833+60*i);
enemyd = jpcrr.read_byte(0x4882C+60*i);
if enemyt==3 then -- guard
jpcrr.hud.circle(3,math.floor(enemyx/32)+640,math.floor(enemyy/32),4,0,0,0,0,0,205,133,63,255);
jpcrr.hud.circle(3,math.floor(enemyx/32)+640+math.cos(math.rad(enemyd*45))*4,math.floor(enemyy/32)-math.sin(math.rad(enemyd*45))*4,2,0,0,0,0,0,205,133,63,255);
elseif enemyt==5 then -- SS
jpcrr.hud.circle(3,math.floor(enemyx/32)+640,math.floor(enemyy/32),4,0,0,0,0,0,0,0,255,255);
jpcrr.hud.circle(3,math.floor(enemyx/32)+640+math.cos(math.rad(enemyd*45))*4,math.floor(enemyy/32)-math.sin(math.rad(enemyd*45))*4,2,0,0,0,0,0,0,0,255,255);
elseif enemyt==6 then -- dog
jpcrr.hud.circle(3,math.floor(enemyx/32)+640,math.floor(enemyy/32),4,0,0,0,0,0,255,105,180,255);
jpcrr.hud.circle(3,math.floor(enemyx/32)+640+math.cos(math.rad(enemyd*45))*4,math.floor(enemyy/32)-math.sin(math.rad(enemyd*45))*4,2,0,0,0,0,0,255,105,180,255);
else -- not yet ID'd
jpcrr.hud.circle(3,math.floor(enemyx/32)+640,math.floor(enemyy/32),4,0,0,0,0,0,255,255,255,255);
end
end
if enemyh~=htable[i] then -- damage has been done
hstring = string.format("Last damage dealt: %3d",(htable[i]-enemyh))
end
render_text(3, 0,416, hstring,false, 0, 255, 0);
htable[i]=enemyh;
end
jpcrr.release_vga();
elseif a == "message" then
c,d,e = string.match(b, "(.*) (.*) (.*)");
if b == "refresh" then
for i = 0,4095,1 do
wolfmap[i] = jpcrr.read_byte(0x44888+i);
end
end
if e and c == "BUTTON" then
if d == "304" and e == "1" then
jpcrr.pc_start();
end
if d == "304" and e == "0" then
jpcrr.pc_stop();
end
if d == "305" then
jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "KEYEDGE", "157");
end
if d == "307" then
jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "KEYEDGE", "57");
end
if d == "308" then
jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "KEYEDGE", "184");
end
end
if e and c == "move" then
if string.match(d, "-?[0-9]+") and string.match(e, "-?[0-9]+") then
print("Moved X "..tonumber(d).." and Y "..tonumber(e));
jpcrr.hold_mouse_motion(tonumber(d), tonumber(e));
end
end
--print(b);
end
end
-- 0x4882E U position (dword)
-- 0x48832 V position (dword)
-- 0x48848 Direction (word)