I am developing a Game Boy emulator and I need to get a formula for generating pulse waves, like this:
(picture from this Wikipedia page)
I know that it is possible to generate a square wave with this formula: $$f(x) = A (-1)^{\lfloor 2 (x - x0) / T \rfloor}$$
What formula could I use to get a pulse wave?