I"m joking around on what Rich wrote..
It's just a code snippet...
detdone was a register that contained error flags.
rndgen was a register that contained a random number.
chgmode was a register that held the control mode. 8 modes.
Unfortunately, nothing to do with the OP trying to make square
waves...