6. Let $M$ be a point on the plane with coordinates $(p \times 1994, 7 p \times 1994)$, where $p$ is a prime number. Find the number of right triangles that satisfy the following conditions:
(1) The three vertices of the triangle are integer points, and $M$ is the right-angle vertex;
(2) The incenter of the triangle is the origin.
Connect the origin $O$ and point $M$, take the midpoint $I(p \times 997$, $7 p \times 997)$ of line segment $O M$, and perform a central symmetry about point $I$, i.e., transform point $(x, y)$ into point $(p \times 1994-x, 7 p \times 1994-y)$. Thus, a right-angled triangle that satisfies the conditions is transformed into a congruent right-angled triangle with integer coordinates. The incenter of the triangle moves to point $M$, and the right-angle vertex moves to the origin. Therefore, the number of right-angled triangles with integer coordinates that satisfy the conditions can be considered by only looking at the case where the right-angle vertex is at the origin and the incenter is at point $M$.

Consider a right-angled triangle $\triangle O A B$ with integer coordinates that satisfies the above conditions, as shown in Figure 1. Let
$$
\angle x O M=\beta, \angle x O A=\alpha, \alpha+\frac{\pi}{4}=\beta
$$

From the problem conditions, we know
$$
\begin{array}{c}
\tan \beta=7 \\
\tan \alpha=\tan \left(\beta-\frac{\pi}{4}\right)=\frac{\tan \beta-1}{1+\tan \beta}=\frac{3}{4}
\end{array}
$$

Thus, the coordinates of any point on the leg $O A$ can be written as $(4 t, 3 t)$, and since $A$ is an integer point, then $t \in \mathbf{N}, O A=5 t$. From $\angle y O B=\alpha$, we know the coordinates of point $B$ are $\left(-3 t^{*}, 4 t^{*}\right), t^{*} \in \mathbf{N}, O B=5 t^{*}$. The inradius of the right-angled triangle is
$$
r=\frac{\sqrt{2}}{2} O M=5 p \times 1994
$$

Let
$$
O A=2 r+p^{*}, O B=2 r+q^{*}
$$

Since $O A, O B, r$ are all multiples of 5, the positive integers $p^{*}, q^{*}$ are also multiples of 5.
Using the property that the lengths of the tangents from a point outside a circle to the circle are equal, we have
$$
A B=\left(r+p^{*}\right)+\left(r+q^{*}\right)=2 r+p^{*}+q^{*}
$$

Since $\triangle O A B$ is a right-angled triangle, we have
$$
\begin{aligned}
0= & A B^{2}-O A^{2}-O B^{2}= \\
& \left(2 r+p^{*}+q^{*}\right)^{2}-\left(2 r+p^{*}\right)^{2}-\left(2 r+q^{*}\right)^{2}= \\
& 2 p^{*} q^{*}-4 r^{2}
\end{aligned}
$$

Thus, we have
$$
p^{*} q^{*}=2 r^{2}
$$

Since $\frac{p^{*}}{5}, \frac{q^{*}}{5}$ are positive integers, we get
$$
\frac{p^{*}}{5} \cdot \frac{q^{*}}{5}=2^{3} \times 997^{2} \times p^{2}
$$

When $p \neq 2$ and $p \neq 997$, we have
$$
\left\{\begin{array}{l}
\frac{p^{*}}{5}=2^{i} \times 997^{j} \times p^{k} \\
\frac{q^{*}}{5}=2^{3-i} \times 997^{2-j} \times p^{2-k}
\end{array}\right.
$$

Here $i=0,1,2,3 ; j=0,1,2 ; k=0,1,2$. Thus, $\left(\frac{p^{*}}{5}, \frac{q^{*}}{5}\right)$ has $4 \times 3 \times 3=36$ different (ordered) solutions.

When $p=2$, we have
$$
\left\{\begin{array}{l}
\frac{p^{*}}{5}=2^{i} \times 997^{j} \\
\frac{q^{*}}{5}=2^{5-i} \times 997^{2-j}
\end{array}\right.
$$

Here $i=0,1,2,3,4,5 ; j=0,1,2$. Equation set (8) has $6 \times 3=18$ different (ordered) solutions.
When $p=997$, we have
$$
\left\{\begin{array}{l}
\frac{p^{*}}{5}=2^{i} \times 997^{j} \\
\frac{q^{*}}{5}=2^{3-i} \times 997^{4-j}
\end{array}\right.
$$

Here $i=0,1,2,3 ; j=0,1,2,3,4$. Equation set (9) has $4 \times 5=20$ different (ordered) solutions.
Thus, the number of right-angled triangles is
$$
S=\left\{\begin{array}{l}
36, p \neq 2 \text{ and } p \neq 997 \\
18, p=2 \\
20, p=997
\end{array}\right.
$$