Your company would own the code you produced to date and then license it out to the jointly owned company. You could then build in an agreement where the jointly owned company has the right to purchase the code for a nominal sum at some future date if certain benchmarks are met.
This should give you the flexibility and protection you seem to want. You could agree to move forward with your friend as a business partner, but if he turns out to be a flop, you still have ownership over your code. At the same time, your partner should feel confident that if he performs his part, he won't be shortchanged.
As for the appropriate percentages, I am also currently grappling with this issue. I haven't settled on a figure yet, although I recall reading somewhere that the best deals are where both parties feel shortchanged.