[Is] the software code [...] protected by copyright?
Yes, software code is copyrightable. See 17 USC § 101 and 17 USC § 117 and also, but not limited to: Apple Computer, Inc. v. Formula Int'l, Inc., 725 F.2d 1240, 1246-49 (3rd Cir. 1983); Apple Computer, Inc. v. Franklin Computer Corp., 714 F.2d 1240, 1246-49 (3d Cir. 1983), cert. dismissed, 104S. Ct. 690 (1984); Williams Elecs., Inc. v. Artic Int'l, Inc., 685 F.2d 870, 876-77 (3rd Cir. 1982); Midway Mfg. Co. v. Strohon, 563 F. Supp. 741, 750-52 (N.D. Ill. 1983). (Granted, it is also worth noting that it originally was not copyrightable (Apple Computer, Inc. v. Franklin Computer Corp, 545 F. Supp. 812, 817-22, 824-25 (E.D. Pa. 1982), rev'd, 714 F.2d 1240, 1246-49 (3d Cir. 1983), cert. dismissed, 104S. Ct. 690 (1984); Data Cash Systems v. JS&A Group, Inc., 480 F. Supp. 1063, 1067-68 (N.D. Ill. 1979), aff'd on other grounds, 628 F.2d 1038 (7th Cir. 1980))).
If so why do we need software patents, [considering that they're] often [...] very broad and cover an idea.
As for your second question, copyright only protects the particular program realization, not the idea itself. As a result, if I came up with a novel solution to a problem, e.g., the SIFT (Scale-Invariant Feature Transform) descriptor for object recognition in imagery, and did not patent the idea, yet made the code available, you would be free to manipulate and use that code according to fair use laws and associated legal precedence. In fact, provided you recoded the algorithm, e.g., in another language or by rewriting a sufficient portion of the software, you would be able to package and sell that implementation and I would not have a claim to any royalty/licensing monies.
On the other hand, software patents protect the underlying idea, as you mentioned, which, in my example above, would be the use of specific processes and transforms in order to recognize objects in imagery. Consequently, if I invented and patented SIFT, an individual or company would be required to license the associated patent(s) from me if they wanted to incorporate that technology into a product that they sold without running afoul of pertinent laws.
In any event, although software patents are often overreaching, there are plenty that do serve, like regular and design patents, to protect critical and non-trivial ideas.