As you progress along the square wave, each time you get to a new half cycle there is of course a new applied voltage Vapp, alternating between 10 and 0 volts. When that occurs, the capacitor is sitting at a voltage I'll call Vold. At that point the voltage moves toward the new Vapp with a time constant 1e-4 that you know already. If the start of that half cycle is denoted by u = tstart, then the voltage in the half cycle is
V = Vapp + (Vold - Vapp)*exp(-(u-tstart)*10000)
So as you can see, for u = tstart the voltage is Vold, and as u--> inf the voltage --> Vapp. So all you need do is start with Vold = 0, go through each half cycle, find the voltage as a function of u, and then use Vold = V(end of that half cycle) for the start of the upcoming half cycle.