When fighting the boss on the first level, press and hold down A for the duration of the fight. Kill the boss and end the level but don't let go of the A button. In the night scene where you can get some magic books do not do anything at all. At the start of the second map your character will automatically do a magic attack. When it's finished you will have blue dots (representing how much magic you have) will go all the way along the bottom of the screen, giving you plenty of magic.
It isn't unlimited, but it should be enough to last the whole game.