This routine is desribed in Mapping the C64, page 102, and used at least by CCGMS terminal software - see here: - https://raw.githubusercontent.com/spathiwa/ccgmsterm/master/original/5a.gs