Although similar techniques were surely used in the past, the thing started growing when viznut studied some demoscene codes from * 4mat * and was captivated by their ingenious (don’t miss the incredible IBNIZ enviroment viznut made). My intention is that you get the general logic of this, and go deeper with the links if you’re interested but let me get just a bit technical now: when you say DSP is running at 8000 Hz, it means there’s already a counter that increases +8000 per second and for each state there is a sample, a number that gives a certain amplitude value (256 possible amplitudes in the case of 8 bit depth, the common bytebeat setup) and that’s pretty everything on how a computer processes sound. If you pass the actual value of that count through a modulo two (t % 2), you’ll get a square-wave. You can divide or multiply t to get different frequencies, add simple counters to make an arpeggio, modulate it, generate an envelope, sum more ‘voices’ if you want and… well, that’s it.