One of the tricks I discovered while trying to understand code like that is outb to an adress on the ISA bus takes a determintic amount of real time. This allows outb to somewhere same to replace a delay loop.
The way that code is described it does feel like someone lost the plot after a point. (Keep adding delays until the code works style). The basic operations it is using seem sane.