static int snk_rot12(int which) {
        /*
         This routine converts a 4 bit (16 directional) analog input to the 12 directional input
         that many SNK games require.
         */
        int dial_12[] = {0xb0, 0xa0, 0x90, 0x80, 0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0x00};
        int value = readinputport(which + 1);
        int joypos16 = value >> 4;

        int delta = joypos16 - old_joypos16[which];

        old_joypos16[which] = joypos16;

        if (delta > 8) {
            delta -= 16;
        } else if (delta < -8) {
            delta += 16;
        }

        joypos12[which] += delta;
        while (joypos12[which] < 0) {
            joypos12[which] += 12;
        }
        while (joypos12[which] >= 12) {
            joypos12[which] -= 12;
        }

        return (value & 0x0f) | dial_12[joypos12[which]];
    }