Could be a host of things from poor valve tolerances, wrong jets in carburetor, wrong range sparkplug, type of fuel used or a loose stator assembly. Has the top end been maintained? Is compression good? Correct oil type and level? Using the muffler or not? Header dented? Is it serviced regularly?
Retarded timing will run the exhaust hotter than normal and backfire easily, will also ruin valves, piston, rings and cylinder bore.
Take generator cover off and check stator housing and pick-up coil are not loose or show signs of movement in any way.
Check condition of carby jets and replace with stock # or one size larger. Check inlet manifold for air leaks or cracks as too lean a motor will burn valves/piston crown. If this is not the cure, your problem should be left to a mechanic with 4 stroke experience.
http://www.yamahaownershandbook.com.au/index.php
Your bikes manual can be downloaded free at this site.
Cheers.