local stage_pointers = 0x3CCF68
local current_stage, current_segment, camera_x, camera_y
local current_stage_address, current_segment_address
local current_enemy_number, current_enemy_address
local current_enemy_x, current_enemy_y = {}, {}
memory.usememorydomain("IWRAM")
while true do
camera_x = memory.read_s32_le(0x1500)
camera_y = memory.read_s32_le(0x1504)
current_stage = memory.readbyte(0x152C)
current_segment = memory.readbyte(0x1530)
current_stage_address = memory.read_u24_le(stage_pointers + current_stage * 4, "ROM")
current_segment_address = memory.read_u24_le(current_stage_address + current_segment * 4, "ROM")
-- Generate table of spawn locations
current_enemy_number = 0
while true do
-- The first set of coordinates is always (0, 0) and does not correspond to an enemy, so skip it
current_enemy_address = current_segment_address + current_enemy_number * 18 + 18
if memory.read_u16_le(current_enemy_address, "ROM") == 0xFFFF then break end
current_enemy_x[current_enemy_number] = memory.read_u16_le(current_enemy_address, "ROM")
current_enemy_y[current_enemy_number] = memory.read_u16_le(current_enemy_address + 2, "ROM")
current_enemy_number = current_enemy_number + 1
end
for i = 0, current_enemy_number - 1 do
if current_enemy_number == 0 then break end
gui.drawBox(current_enemy_x[i] - 300 - camera_x, current_enemy_y[i] - camera_y, current_enemy_x[i] - 248 - camera_x, current_enemy_y[i] + 160 - camera_y, 0x800000FF, 0x8000007F)
gui.drawBox(current_enemy_x[i] + 32 - camera_x, current_enemy_y[i] - camera_y, current_enemy_x[i] + 40 - camera_x, current_enemy_y[i] + 160 - camera_y, 0x8000FF00, 0x80007F00)
gui.drawRectangle(current_enemy_x[i] - camera_x, current_enemy_y[i] - camera_y, 4, 4)
end
emu.frameadvance()
end
-- 30 x 20