Given a degree-two endomorphism of an elliptic curve, how to construct the following map to $\Bbb P^1$? This is the first part of Hartshorne exercise IV.4.5.

Let $(X,P_0)$ be an elliptic curve having an endomorphims  $f:X\to X$ be of degree two.
If we represent $X$ as a 2-1 cover of $\Bbb P^1$ by a morphism $\pi:X\to\Bbb P^1$ ramified at $P_0$, then as in (4.4), show that there is another morphism $\pi':X\to \Bbb P^1$ and a morphism $g:\Bbb P^1\to\Bbb P^1$, also of degree 2, such that $\pi\circ f=g\circ\pi'$.

Here's lemma IV.4.4 referenced above, where $X$ is used to denote an elliptic curve:

Lemma: If $f_1:X\to\Bbb P^1$ and $f_2:X\to\Bbb P^1$ are any two morphisms of degree 2 from $X$ to $\Bbb P^1$, then there are automorphisms $\sigma\in \operatorname{Aut} X$ and $\tau\in\operatorname{Aut} \Bbb P^1$ so that $f_2\circ\sigma=\tau\circ f_1$.
Proof: Let $P_1$ be a ramification point of $f_1$ and let $P_2$ be a ramification point of $f_2$. Then since the group of automorphisms of $X$ is transitive, there is $\sigma\in\operatorname{Aut} X$ such that $\sigma(P_1)=P_2$. On the other hand, $f_1$ is determined by the linear system $|2P_1|$ and $f_2$ is determined by $|2P_2|$. Since $\sigma$ takes one to the other, $f_1$ and $f_2\circ\sigma$ correspond to the same linear system, so they differ only by an automorphism $\tau$ of $\Bbb P^1$.

I'm a little stuck in figuring out how to construct $\pi'$ and $g$. It seems like I can't copy the proof of 4.4 directly, because $f$ is degree-two instead of an automorphism. But we can do something similar: $\pi$ is given by $|2P_0|$, so $\pi\circ f$ is given by the map to $\Bbb P^1$ determined by $[(\pi\circ f)^*x:(\pi\circ f)^*y]$ where $(\pi\circ f)^*x$ and $(\pi\circ f)^*y$ are the images of $x,y\in\mathcal{O}_{\Bbb P^1}(1)$ under the composite pullback $\Gamma(\Bbb P^1,\mathcal{O}_{\Bbb P^1}(1))\to\Gamma(X,\mathcal{O}_X(2P_0))\to\Gamma(X,f^*\mathcal{O}_X(2P_0))$. But I'm having trouble seeing how to factor this as $X\stackrel{\pi'}{\to}\Bbb P^1\stackrel{g}{\to}\Bbb P^1$ where $\pi'$ and $g$ both have degree two. I'm looking for help understanding what to do here.
I did find this question which mentions the first two parts in passing, but it seems like they've got some things the wrong way around.
Further attempts: By Riemann-Hurwitz and the assumption that our base field is not characteristic two, $f$ is unramified and therefore $f^{-1}(P_0)$ is two distinct points, say $Q_1,Q_2$. Then $f^*\mathcal{O}_X(2P_0)\cong\mathcal{O}_X(2Q_1+2Q_2)$, which has a four-dimensional space of global sections. I think I should be able to pick two linearly independent global sections with no common base point in here which are the squares of global sections from $\mathcal{O}_X(Q_1+Q_2)$, and then use these to define the maps. But I'm not sure and would appreciate some confirmation.
 A: After a while of thinking, I figured this out:
$f$ is unramified, so $f^{-1}(P_0)$ is two points. Because $f$ is also a group homomorphism, we must have that one of those points is $P_0$, and the other point is $P_1$, a 2-torsion point. Letting $P_2$ and $P_3$ be the other 2-torsion points, we must have that $f(P_2)=f(P_3)$, since $P_2+P_1=P_3$, so we can arrange $\pi$ to map $P_0$ to $\infty$ and $f(P_2)$ to $0$. Therefore the composite $\pi\circ f$ is given by a rational function with double poles at $P_0$ and $P_1$ and double zeroes at $P_2$ and $P_3$. If we make $g$ the map $x\mapsto x^2$, this means we need to find a rational function on $X$ with simple poles at $P_0$ and $P_1$ and simple zeroes at $P_2$ and $P_3$. If we embed $X\subset\Bbb P^2$ with equation $y^2z=x(x-z)(x-\lambda z)$ so that $P_1$ is $[0:0:1]$, then the rational function $y/x$ works, which you can see by checking the intersections $V(x)\cap X$ and $V(y)\cap X$.
Since any rational function is determined up to a constant by it's zeroes and poles counted with multiplicity, this shows that some multiple of $y/x$ is the required rational function.
